UX: Trash icon displaying when there is no upload.

This commit is contained in:
Guo Xiang Tan 2018-11-12 15:55:56 +08:00
parent 575d6855ea
commit 10c6211cdf
4 changed files with 26 additions and 5 deletions

View File

@ -9,9 +9,15 @@ export default Em.Component.extend(UploadMixin, {
if (Em.isNone(imageUrl)) {
return "".htmlSafe();
}
return `background-image: url(${imageUrl})`.htmlSafe();
},
@computed("backgroundStyle")
hasBackgroundStyle(backgroundStyle) {
Ember.isEmpty(backgroundStyle);
},
validateUploadedFilesOptions() {
return { imagesOnly: true };
},

View File

@ -18,9 +18,8 @@ export default Em.Mixin.create({
calculateUploadUrl() {
return (
getUrl(this.getWithDefault("uploadUrl", "/uploads")) +
".json?client_id=" +
this.messageBus.clientId +
+".json?client_id=" +
(this.messageBus && this.messageBus.clientId) +
"&authenticity_token=" +
encodeURIComponent(Discourse.Session.currentProp("csrfToken"))
);
@ -99,7 +98,9 @@ export default Em.Mixin.create({
}.on("didInsertElement"),
_destroy: function() {
this.messageBus.unsubscribe("/uploads/" + this.get("type"));
this.messageBus &&
this.messageBus.unsubscribe("/uploads/" + this.get("type"));
const $upload = this.$();
try {
$upload.fileupload("destroy");

View File

@ -4,7 +4,7 @@
{{d-icon "picture-o"}}
<input class="hidden-upload-field" disabled={{uploading}} type="file" accept="image/*" />
</label>
{{#if backgroundStyle}}
{{#if hasBackgroundStyle}}
<button {{action "trash"}} class="btn btn-danger pad-left no-text">{{d-icon "trash-o"}}</button>
{{/if}}
<span class="btn {{unless uploading 'hidden'}}">{{i18n 'upload_selector.uploading'}} {{uploadProgress}}%</span>

View File

@ -0,0 +1,14 @@
import componentTest from "helpers/component-test";
moduleForComponent("image-uploader", { integration: true });
componentTest("without image", {
template: "{{image-uploader}}",
test(assert) {
assert.equal(
this.$(".d-icon-trash-o").length,
0,
"it does not display trash icon"
);
}
});