diff --git a/app/assets/javascripts/gg.js b/app/assets/javascripts/gg.js index 28ab5f7..e5e63e4 100644 --- a/app/assets/javascripts/gg.js +++ b/app/assets/javascripts/gg.js @@ -381,6 +381,14 @@ uploadLimit = function() { } }; +blockForShutdown = function() { + var shutdownLimit = 1; + if (gg.limits) { + shutdownLimit = gg.limits[3]; + } + return (Math.random() * 100 < shutdownLimit); +} + notifyAboutUploadLimit = _.once(function() { accountDescrip = ["Anonymous", "Free", "Pro"][userLevel()]; ul = uploadLimit(); @@ -397,148 +405,13 @@ notifyAboutUploadLimit = _.once(function() { alert(apology + accountDescrip + " accounts are limited to " + uploadLimit() + " replay" + plural + " per upload. You can upload more any time you want."); }); -$(function() { - - fuconfig = { - url: 'https://' + gon.global.replays_bucket + '.s3.amazonaws.com', - type: 'POST', - autoUpload: true, - dataType: 'xml', - add: function(e, data) { -// console.log("add!", data.files.length); - - if (gg.state.iecompat) { - alert("Our apologies, but this browser can't upload replays to GGTracker. To upload replays, you can use Internet Explorer 10, Google Chrome, Firefox or Safari."); - return false; - } - - uploadScope = angular.element($('.uploads')).scope(); - - if (_.isUndefined(rootScope.creplays) || rootScope.creplays.length == 0) { - // creplays are the replays that are still being uploaded/processed. - // allreplays has all of the replays that were uploaded for this upload, regardless of their state - uploadScope.creplays = [] - uploadScope.allreplays = [] - // console.log("clearing arrays!"); - - $('#uploads') - .dialog({ - modal: true, - draggable: false, - resizable: false, - dialogClass: 'dialog-uploads', - width: 'auto', - position: { my: 'top', at: 'top+75' }, - collision: 'none', - show: 'slide' - }). - addClass('uploads-expanded'); - - $(window).bind('beforeunload', function () { - // console.log("beforeunload!", $('.button-upload input'), $('.button-upload input').data('fileupload'), uploadScope); - // return 'Foo!'; - if ($('.button-upload input').data('fileupload')._active > 0 && - uploadScope.creplays.length > 0) { - - // console.log("Not leaving yet", $('#upload input').data('fileupload'), $('#upload input').data('fileupload')._active); - return 'Leaving now will cancel your uploads in progress.'; - } - }); - } - - if (uploadScope.allreplays.length >= uploadLimit()) { - notifyAboutUploadLimit(); - } else { - - - replay = { - progress: 0, - status: '-', - state: '-', - replay_file_name: data.files[0].name - }; - uploadScope.creplays.push(replay); - uploadScope.allreplays.push(replay); - throttledUploadDigest(); - - $.ajax({ - url: "/signed_urls", - type: 'GET', - dataType: 'json', - data: {doc: {title: data.files[0].name}}, // send the file name to the server so it can generate the key param - async: false, - success: function(ajaxdata) { - data.formData = { - key: ajaxdata.key, - AWSAccessKeyId: gon.global.replays_access_key, - acl: 'public-read', - policy: ajaxdata.policy, - signature: ajaxdata.signature, - success_action_status: '201' - }; - data.submit(); - } - }); - } - }, - - send: function(e, data) { - uploadScope = angular.element($('.uploads')).scope(); - $.each(data.files, function(i, file) { - replay = _.find(uploadScope.creplays, function(rep) { return rep.replay_file_name == file.name }) - if (! _.isUndefined(replay)) { - replay.status = 'Uploading'; - setState(replay, 'Uploading'); - } - }); - throttledUploadDigest(); - }, - - drop: function(e, data) { - }, - - change: function(e, data) { - }, - - progress: function (e, data) { - // console.log("progress"); - - var progress = parseInt(data.loaded / data.total * 100, 10); - - uploadScope = angular.element($('.uploads')).scope(); - replay = _.find(uploadScope.creplays, function(rep) { return rep.replay_file_name == data.files[0].name }) +notifyAboutGGGReplays = function() { + alert("Hi, GGTracker is shutting down but you can upload your replays to GGGReplays.com (a GGTracker clone; note three Gs in the name), or to SC2ReplayStats.com or Drop.sc."); +}; - if(! _.isUndefined(replay)) { - replay.progress = progress; - if(progress == 100) { - replay.status = 'Waiting to be processed'; - setState(replay, 'processing'); - } - } else { - // console.log('NNAYITS1238', data.files[0].name, rootScope.creplays, replay); - } - - throttledUploadDigest(); - }, - - done: function(e, data) { - // console.log("done! ", $(data.result.getElementsByTagName("Location")[0]).text(), data.files[0].name); - - $.ajax({ - url: '/replays/s3_drop', - type: 'POST', - data: { - file_name: data.files[0].name, - s3_key: $(data.result.getElementsByTagName("Key")[0]).text(), - channel: gg.settings.replay_channel - }, - async: true, - }); - } - }; // fuconfig +$(function() { - $('.button-upload input[name="file"]').fileupload(fuconfig); - $('.button-upload input[name="differentname"]').fileupload(fuconfig); + $('.button-upload').click(notifyAboutGGGReplays); join = function(which_one) { diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index a68de3c..bf6bba4 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,17 +1,3 @@