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

View file

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