add onAllComplete event to fileupload.js; hide mention helper during upload

This commit is contained in:
Michael Nutt 2011-02-27 12:44:56 -05:00
parent b6dc32959c
commit 208a47162c
3 changed files with 337 additions and 313 deletions

View file

@ -30,14 +30,14 @@
onSubmit: function(id, fileName){ onSubmit: function(id, fileName){
$('#file-upload').addClass("loading"); $('#file-upload').addClass("loading");
$('#publisher').find("input[type='submit']").attr('disabled','disabled'); $('#publisher').find("input[type='submit']").attr('disabled','disabled');
$("#publisher .options_and_submit").fadeIn(50); $("div.mention_helper").fadeTo(100, 0, function() {
$("#publisher .options_and_submit, #fileInfo").fadeIn(50);
});
$("#publisher_spinner").fadeIn(100); $("#publisher_spinner").fadeIn(100);
}, },
onComplete: function(id, fileName, responseJSON) { onComplete: function(id, fileName, responseJSON) {
$('#fileInfo').text(fileName + ' completed').fadeOut(2000); $('#fileInfo').text(fileName + ' completed');
$("#publisher_spinner").fadeOut(100);
$('#file-upload').removeClass("loading");
var id = responseJSON.data.photo.id; var id = responseJSON.data.photo.id;
var url = responseJSON.data.photo.thumb_small; var url = responseJSON.data.photo.thumb_small;
@ -70,6 +70,15 @@
} }
}); });
}); });
},
onAllComplete: function(completed_files){
$('#fileInfo').delay(1800).fadeOut(200, function() {
$("div.mention_helper").fadeTo(100, 100);
});
$("#publisher_spinner").fadeOut(100);
$('#file-upload').removeClass("loading");
} }
}); });

View file

@ -37,7 +37,7 @@
= hidden_field_tag 'aspect_ids[]', aspect_id.to_s = hidden_field_tag 'aspect_ids[]', aspect_id.to_s
.options_and_submit .options_and_submit
%div %div.mention_helper
%i= t('.mention_helper_text') %i= t('.mention_helper_text')
.right .right

View file

@ -266,6 +266,7 @@ qq.FileUploaderBasic = function(o){
onSubmit: function(id, fileName){}, onSubmit: function(id, fileName){},
onProgress: function(id, fileName, loaded, total){}, onProgress: function(id, fileName, loaded, total){},
onComplete: function(id, fileName, responseJSON){}, onComplete: function(id, fileName, responseJSON){},
onAllComplete: function(completed_files){},
onCancel: function(id, fileName){}, onCancel: function(id, fileName){},
// messages // messages
messages: { messages: {
@ -332,6 +333,9 @@ qq.FileUploaderBasic.prototype = {
self._onComplete(id, fileName, result); self._onComplete(id, fileName, result);
self._options.onComplete(id, fileName, result); self._options.onComplete(id, fileName, result);
}, },
onAllComplete: function(completed_files){
self._options.onAllComplete(completed_files);
},
onCancel: function(id, fileName){ onCancel: function(id, fileName){
self._onCancel(id, fileName); self._onCancel(id, fileName);
self._options.onCancel(id, fileName); self._options.onCancel(id, fileName);
@ -859,6 +863,7 @@ qq.UploadHandlerAbstract = function(o){
maxConnections: 999, maxConnections: 999,
onProgress: function(id, fileName, loaded, total){}, onProgress: function(id, fileName, loaded, total){},
onComplete: function(id, fileName, response){}, onComplete: function(id, fileName, response){},
onAllComplete: function(completed_files){},
onCancel: function(id, fileName){} onCancel: function(id, fileName){}
}; };
qq.extend(this._options, o); qq.extend(this._options, o);
@ -866,6 +871,7 @@ qq.UploadHandlerAbstract = function(o){
this._queue = []; this._queue = [];
// params for files in queue // params for files in queue
this._params = []; this._params = [];
this._completed_files = [];
}; };
qq.UploadHandlerAbstract.prototype = { qq.UploadHandlerAbstract.prototype = {
log: function(str){ log: function(str){
@ -943,6 +949,13 @@ qq.UploadHandlerAbstract.prototype = {
var nextId = this._queue[max-1]; var nextId = this._queue[max-1];
this._upload(nextId, this._params[nextId]); this._upload(nextId, this._params[nextId]);
} }
if (this._queue.length == 0){
this._onAllComplete();
}
},
_onAllComplete: function(){
this._options.onAllComplete(this._completed_files);
} }
}; };
@ -1223,9 +1236,11 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
response = {}; response = {};
} }
this._completed_files.push({file: this._files[id], response: response});
this._options.onComplete(id, name, response); this._options.onComplete(id, name, response);
} else { } else {
this._completed_files.push({file: this._files[id], response: {}});
this._options.onComplete(id, name, {}); this._options.onComplete(id, name, {});
} }