FEATURE: upload placeholder

This commit is contained in:
Régis Hanol 2015-09-09 23:14:06 +02:00
parent b34b3293a3
commit 38cb72b329
3 changed files with 17 additions and 2 deletions

View file

@ -215,6 +215,10 @@ Discourse.Utilities = {
} }
}, },
getUploadPlaceholder: function(filename) {
return "[" + I18n.t("uploading_filename", { filename: filename }) + "]() ";
},
isAnImage: function(path) { isAnImage: function(path) {
return (/\.(png|jpe?g|gif|bmp|tiff?|svg|webp)$/i).test(path); return (/\.(png|jpe?g|gif|bmp|tiff?|svg|webp)$/i).test(path);
}, },

View file

@ -322,8 +322,9 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
this.messageBus.subscribe("/uploads/composer", upload => { this.messageBus.subscribe("/uploads/composer", upload => {
if (!cancelledByTheUser) { if (!cancelledByTheUser) {
if (upload && upload.url) { if (upload && upload.url) {
const markdown = Discourse.Utilities.getUploadMarkdown(upload); const old = Discourse.Utilities.getUploadPlaceholder(upload.original_filename),
this.addMarkdown(markdown + " "); markdown = Discourse.Utilities.getUploadMarkdown(upload);
this.replaceMarkdown(old, markdown);
} else { } else {
Discourse.Utilities.displayErrorForUpload(upload); Discourse.Utilities.displayErrorForUpload(upload);
} }
@ -350,6 +351,10 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
this.get("controller").send("closeModal"); this.get("controller").send("closeModal");
// deal with cancellation // deal with cancellation
cancelledByTheUser = false; cancelledByTheUser = false;
// add upload placeholder
const markdown = Discourse.Utilities.getUploadPlaceholder(data.files[0].name);
this.addMarkdown(markdown);
//
if (data["xhr"]) { if (data["xhr"]) {
const jqHXR = data.xhr(); const jqHXR = data.xhr();
if (jqHXR) { if (jqHXR) {
@ -502,6 +507,11 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
}); });
}, },
replaceMarkdown(old, text) {
const reply = this.get("model.reply");
this.set("model.reply", reply.replace(old, text));
},
// Uses javascript to get the image sizes from the preview, if present // Uses javascript to get the image sizes from the preview, if present
imageSizes() { imageSizes() {
const result = {}; const result = {};

View file

@ -245,6 +245,7 @@ en:
upload: "Upload" upload: "Upload"
uploading: "Uploading..." uploading: "Uploading..."
uploading_filename: "Uploading {{filename}}..."
uploaded: "Uploaded!" uploaded: "Uploaded!"
enable: "Enable" enable: "Enable"