FIX: Canceling upload on mobile did not work

This commit is contained in:
Gerhard Schlager 2017-12-30 22:40:15 +01:00
parent 070fe12e25
commit a0b2b3c8a7
2 changed files with 20 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import userSearch from 'discourse/lib/user-search'; import userSearch from 'discourse/lib/user-search';
import { default as computed, on } from 'ember-addons/ember-computed-decorators'; import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators';
import { linkSeenMentions, fetchUnseenMentions } from 'discourse/lib/link-mentions'; import { linkSeenMentions, fetchUnseenMentions } from 'discourse/lib/link-mentions';
import { linkSeenCategoryHashtags, fetchUnseenCategoryHashtags } from 'discourse/lib/link-category-hashtags'; import { linkSeenCategoryHashtags, fetchUnseenCategoryHashtags } from 'discourse/lib/link-category-hashtags';
import { linkSeenTagHashtags, fetchUnseenTagHashtags } from 'discourse/lib/link-tag-hashtag'; import { linkSeenTagHashtags, fetchUnseenTagHashtags } from 'discourse/lib/link-tag-hashtag';
@ -36,6 +36,18 @@ export default Ember.Component.extend({
return `[${I18n.t('uploading')}]() `; return `[${I18n.t('uploading')}]() `;
}, },
@observes('composer.uploadCancelled')
_cancelUpload() {
if (!this.get('composer.uploadCancelled')) { return; }
this.set('composer.uploadCancelled', false);
if (this._xhr) {
this._xhr._userCancelled = true;
this._xhr.abort();
}
this._resetUpload(true);
},
@computed @computed
markdownOptions() { markdownOptions() {
return { return {
@ -401,7 +413,9 @@ export default Ember.Component.extend({
}, },
_resetUpload(removePlaceholder) { _resetUpload(removePlaceholder) {
this._validUploads--; if (this._validUploads > 0) {
this._validUploads--;
}
if (this._validUploads === 0) { if (this._validUploads === 0) {
this.setProperties({ uploadProgress: 0, isUploading: false, isCancellable: false }); this.setProperties({ uploadProgress: 0, isUploading: false, isCancellable: false });
} }
@ -624,14 +638,6 @@ export default Ember.Component.extend({
this.sendAction('importQuote', toolbarEvent); this.sendAction('importQuote', toolbarEvent);
}, },
cancelUpload() {
if (this._xhr) {
this._xhr._userCancelled = true;
this._xhr.abort();
}
this._resetUpload(true);
},
onExpandPopupMenuOptions(toolbarEvent) { onExpandPopupMenuOptions(toolbarEvent) {
const selected = toolbarEvent.selected; const selected = toolbarEvent.selected;
toolbarEvent.selectText(selected.start, selected.end - selected.start); toolbarEvent.selectText(selected.start, selected.end - selected.start);

View File

@ -224,6 +224,10 @@ export default Ember.Controller.extend({
}, },
actions: { actions: {
cancelUpload() {
this.set('model.uploadCancelled', true);
},
onPopupMenuAction(action) { onPopupMenuAction(action) {
this.send(action); this.send(action);
}, },