2020-03-30 14:16:10 -04:00
|
|
|
import EmberObject, { action, computed } from "@ember/object";
|
2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2019-10-30 16:28:29 -04:00
|
|
|
import { sort } from "@ember/object/computed";
|
2022-08-29 13:59:57 -04:00
|
|
|
import { inject as service } from "@ember/service";
|
2020-03-30 14:16:10 -04:00
|
|
|
|
|
|
|
const ALL_FILTER = "all";
|
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend({
|
2022-08-29 13:59:57 -04:00
|
|
|
dialog: service(),
|
2020-03-30 14:16:10 -04:00
|
|
|
filter: null,
|
|
|
|
sorting: null,
|
2019-05-28 06:15:12 -04:00
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
2020-03-30 14:16:10 -04:00
|
|
|
this.setProperties({
|
|
|
|
filter: ALL_FILTER,
|
|
|
|
sorting: ["group", "name"],
|
|
|
|
});
|
2019-05-28 06:15:12 -04:00
|
|
|
},
|
2014-12-22 19:12:26 -05:00
|
|
|
|
2020-03-30 14:16:10 -04:00
|
|
|
sortedEmojis: sort("filteredEmojis.[]", "sorting"),
|
|
|
|
|
|
|
|
emojiGroups: computed("model", {
|
|
|
|
get() {
|
|
|
|
return this.model.mapBy("group").uniq();
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
|
|
|
sortingGroups: computed("emojiGroups.[]", {
|
|
|
|
get() {
|
|
|
|
return [ALL_FILTER].concat(this.emojiGroups);
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
|
|
|
filteredEmojis: computed("model.[]", "filter", {
|
|
|
|
get() {
|
|
|
|
if (!this.filter || this.filter === ALL_FILTER) {
|
|
|
|
return this.model;
|
|
|
|
} else {
|
|
|
|
return this.model.filterBy("group", this.filter);
|
|
|
|
}
|
2014-12-22 19:12:26 -05:00
|
|
|
},
|
2020-03-30 14:16:10 -04:00
|
|
|
}),
|
|
|
|
|
2022-01-16 20:48:49 -05:00
|
|
|
_highlightEmojiList() {
|
|
|
|
const customEmojiListEl = document.querySelector("#custom_emoji");
|
|
|
|
if (
|
|
|
|
customEmojiListEl &&
|
|
|
|
!customEmojiListEl.classList.contains("highlighted")
|
|
|
|
) {
|
|
|
|
customEmojiListEl.classList.add("highlighted");
|
|
|
|
customEmojiListEl.addEventListener("animationend", () => {
|
|
|
|
customEmojiListEl.classList.remove("highlighted");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-03-30 14:16:10 -04:00
|
|
|
@action
|
|
|
|
filterGroups(value) {
|
|
|
|
this.set("filter", value);
|
|
|
|
},
|
|
|
|
|
|
|
|
@action
|
|
|
|
emojiUploaded(emoji, group) {
|
|
|
|
emoji.url += "?t=" + new Date().getTime();
|
|
|
|
emoji.group = group;
|
|
|
|
this.model.pushObject(EmberObject.create(emoji));
|
2022-01-16 20:48:49 -05:00
|
|
|
this._highlightEmojiList();
|
2020-03-30 14:16:10 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
@action
|
|
|
|
destroyEmoji(emoji) {
|
2022-08-29 13:59:57 -04:00
|
|
|
this.dialog.yesNoConfirm({
|
|
|
|
message: I18n.t("admin.emoji.delete_confirm", {
|
|
|
|
name: emoji.get("name"),
|
|
|
|
}),
|
|
|
|
didConfirm: () => {
|
|
|
|
return ajax("/admin/customize/emojis/" + emoji.get("name"), {
|
|
|
|
type: "DELETE",
|
|
|
|
}).then(() => {
|
|
|
|
this.model.removeObject(emoji);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2014-12-22 19:12:26 -05:00
|
|
|
},
|
|
|
|
});
|