mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
UX: Trash icon displaying when there is no upload.
This commit is contained in:
parent
575d6855ea
commit
10c6211cdf
@ -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 };
|
||||
},
|
||||
|
@ -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");
|
||||
|
@ -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>
|
||||
|
14
test/javascripts/components/image-uploader-test.js.es6
Normal file
14
test/javascripts/components/image-uploader-test.js.es6
Normal 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"
|
||||
);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user