FIX: multiple file uploads wasn't working due to composer upgrade

This commit is contained in:
Régis Hanol 2015-11-23 11:30:26 +01:00
parent bec1606328
commit 4fe1a13bae
2 changed files with 24 additions and 13 deletions

View File

@ -117,9 +117,14 @@ export default Ember.Component.extend({
}); });
}, },
_resetUpload() { _resetUpload(removePlaceholder) {
this.setProperties({ uploadProgress: 0, isUploading: false }); this._validUploads--;
if (this._validUploads === 0) {
this.setProperties({ uploadProgress: 0, isUploading: false, isCancellable: false });
}
if (removePlaceholder) {
this.set('composer.reply', this.get('composer.reply').replace(this.get('uploadPlaceholder'), "")); this.set('composer.reply', this.get('composer.reply').replace(this.get('uploadPlaceholder'), ""));
}
}, },
_bindUploadTarget() { _bindUploadTarget() {
@ -147,16 +152,19 @@ export default Ember.Component.extend({
}); });
$element.on("fileuploadsend", (e, data) => { $element.on("fileuploadsend", (e, data) => {
// add upload placeholder this._validUploads++;
this.appEvents.trigger('composer:insert-text', uploadPlaceholder); // add upload placeholders (as much placeholders as valid files dropped)
const placeholder = _.times(this._validUploads, () => uploadPlaceholder).join("\n");
this.appEvents.trigger('composer:insert-text', placeholder);
if (data.xhr) { if (data.xhr && data.originalFiles.length === 1) {
this.set("isCancellable", true);
this._xhr = data.xhr(); this._xhr = data.xhr();
} }
}); });
$element.on("fileuploadfail", (e, data) => { $element.on("fileuploadfail", (e, data) => {
this._resetUpload(); this._resetUpload(true);
const userCancelled = this._xhr && this._xhr._userCancelled; const userCancelled = this._xhr && this._xhr._userCancelled;
this._xhr = null; this._xhr = null;
@ -172,13 +180,14 @@ export default Ember.Component.extend({
if (!this._xhr || !this._xhr._userCancelled) { if (!this._xhr || !this._xhr._userCancelled) {
const markdown = Discourse.Utilities.getUploadMarkdown(upload); const markdown = Discourse.Utilities.getUploadMarkdown(upload);
this.set('composer.reply', this.get('composer.reply').replace(uploadPlaceholder, markdown)); this.set('composer.reply', this.get('composer.reply').replace(uploadPlaceholder, markdown));
this._resetUpload(false);
} else {
this._resetUpload(true);
} }
} else { } else {
this._resetUpload(true);
Discourse.Utilities.displayErrorForUpload(upload); Discourse.Utilities.displayErrorForUpload(upload);
} }
// reset upload state
this._resetUpload();
}); });
if (Discourse.Mobile.mobileView) { if (Discourse.Mobile.mobileView) {
@ -276,6 +285,7 @@ export default Ember.Component.extend({
@on('willDestroyElement') @on('willDestroyElement')
_unbindUploadTarget() { _unbindUploadTarget() {
this._validUploads = 0;
this.$(".mobile-file-upload").off("click.uploader"); this.$(".mobile-file-upload").off("click.uploader");
this.messageBus.unsubscribe("/uploads/composer"); this.messageBus.unsubscribe("/uploads/composer");
const $uploadTarget = this.$(); const $uploadTarget = this.$();
@ -302,9 +312,8 @@ export default Ember.Component.extend({
if (this._xhr) { if (this._xhr) {
this._xhr._userCancelled = true; this._xhr._userCancelled = true;
this._xhr.abort(); this._xhr.abort();
this._resetUpload();
} }
this._resetUpload(); this._resetUpload(true);
}, },
showOptions() { showOptions() {

View File

@ -21,7 +21,9 @@
<div id="file-uploading"> <div id="file-uploading">
{{loading-spinner size="small"}} {{i18n 'upload_selector.uploading'}} {{loading-spinner size="small"}} {{i18n 'upload_selector.uploading'}}
{{uploadProgress}}% {{uploadProgress}}%
{{#if isCancellable}}
<a href id="cancel-file-upload" {{action "cancelUpload"}}>{{fa-icon "times"}}</a> <a href id="cancel-file-upload" {{action "cancelUpload"}}>{{fa-icon "times"}}</a>
{{/if}}
</div> </div>
{{/if}} {{/if}}
<div id='draft-status' class="{{if isUploading 'hidden'}}"> <div id='draft-status' class="{{if isUploading 'hidden'}}">