mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: immediately remove upload placeholder when cancelling the upload
FIX: prevent post submit when something is uploading
This commit is contained in:
parent
6a4b9a3d38
commit
e65ddc6c25
2 changed files with 20 additions and 10 deletions
|
@ -225,9 +225,7 @@ export default Ember.Controller.extend({
|
|||
return false;
|
||||
},
|
||||
|
||||
disableSubmit: function() {
|
||||
return this.get('model.loading');
|
||||
}.property('model.loading'),
|
||||
disableSubmit: Ember.computed.or("model.loading", "view.isUploading"),
|
||||
|
||||
save(force) {
|
||||
const composer = this.get('model');
|
||||
|
|
|
@ -340,15 +340,18 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
|
|||
var cancelledByTheUser;
|
||||
|
||||
this.messageBus.subscribe("/uploads/composer", upload => {
|
||||
// reset upload state
|
||||
reset();
|
||||
// replace upload placeholder
|
||||
if (upload && upload.url) {
|
||||
const old = Discourse.Utilities.getUploadPlaceholder(),
|
||||
markdown = cancelledByTheUser ? "" : Discourse.Utilities.getUploadMarkdown(upload);
|
||||
this.replaceMarkdown(old, markdown);
|
||||
if (!cancelledByTheUser) {
|
||||
const uploadPlaceholder = Discourse.Utilities.getUploadPlaceholder(),
|
||||
markdown = Discourse.Utilities.getUploadMarkdown(upload);
|
||||
this.replaceMarkdown(uploadPlaceholder, markdown);
|
||||
}
|
||||
} else {
|
||||
Discourse.Utilities.displayErrorForUpload(upload);
|
||||
}
|
||||
// reset upload state
|
||||
reset();
|
||||
});
|
||||
|
||||
$uploadTarget.fileupload({
|
||||
|
@ -370,8 +373,8 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
|
|||
// deal with cancellation
|
||||
cancelledByTheUser = false;
|
||||
// add upload placeholder
|
||||
const markdown = Discourse.Utilities.getUploadPlaceholder();
|
||||
this.addMarkdown(markdown);
|
||||
const uploadPlaceholder = Discourse.Utilities.getUploadPlaceholder();
|
||||
this.addMarkdown(uploadPlaceholder);
|
||||
|
||||
if (data["xhr"]) {
|
||||
const jqHXR = data.xhr();
|
||||
|
@ -381,7 +384,10 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
|
|||
const $cancel = $("#cancel-file-upload");
|
||||
$cancel.on("click", () => {
|
||||
if (jqHXR) {
|
||||
// signal the upload was cancelled by the user
|
||||
cancelledByTheUser = true;
|
||||
// immediately remove upload placeholder
|
||||
this.replaceMarkdown(uploadPlaceholder, "");
|
||||
// might trigger a "fileuploadfail" event with status = 0
|
||||
jqHXR.abort();
|
||||
// make sure we always reset the uploading status
|
||||
|
@ -401,8 +407,14 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
|
|||
});
|
||||
|
||||
$uploadTarget.on("fileuploadfail", (e, data) => {
|
||||
// reset upload state
|
||||
reset();
|
||||
|
||||
if (!cancelledByTheUser) {
|
||||
// remove upload placeholder when there's a failure
|
||||
const uploadPlaceholder = Discourse.Utilities.getUploadPlaceholder();
|
||||
this.replaceMarkdown(uploadPlaceholder, "");
|
||||
// display the error
|
||||
Discourse.Utilities.displayErrorForUpload(data);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue