2023-03-15 17:42:12 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
|
|
|
import { sort } from "@ember/object/computed";
|
2020-03-31 02:16:10 +08:00
|
|
|
import EmberObject, { action, computed } from "@ember/object";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2020-03-31 02:16:10 +08:00
|
|
|
|
|
|
|
const ALL_FILTER = "all";
|
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
export default class AdminEmojisController extends Controller {
|
|
|
|
@service dialog;
|
2019-05-28 18:15:12 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
filter = null;
|
|
|
|
sorting = null;
|
|
|
|
|
|
|
|
@sort("filteredEmojis.[]", "sorting") sortedEmojis;
|
2019-05-28 18:15:12 +08:00
|
|
|
init() {
|
2023-03-15 17:42:12 +08:00
|
|
|
super.init(...arguments);
|
2019-05-28 18:15:12 +08:00
|
|
|
|
2020-03-31 02:16:10 +08:00
|
|
|
this.setProperties({
|
|
|
|
filter: ALL_FILTER,
|
|
|
|
sorting: ["group", "name"],
|
|
|
|
});
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2020-03-31 02:16:10 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@computed("model")
|
|
|
|
get emojiGroups() {
|
|
|
|
return this.model.mapBy("group").uniq();
|
|
|
|
}
|
2020-03-31 02:16:10 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@computed("emojiGroups.[]")
|
|
|
|
get sortingGroups() {
|
|
|
|
return [ALL_FILTER].concat(this.emojiGroups);
|
|
|
|
}
|
2020-03-31 02:16:10 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@computed("model.[]", "filter")
|
|
|
|
get filteredEmojis() {
|
|
|
|
if (!this.filter || this.filter === ALL_FILTER) {
|
|
|
|
return this.model;
|
|
|
|
} else {
|
|
|
|
return this.model.filterBy("group", this.filter);
|
|
|
|
}
|
|
|
|
}
|
2020-03-31 02:16:10 +08:00
|
|
|
|
2022-01-17 09:48:49 +08: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");
|
|
|
|
});
|
|
|
|
}
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2022-01-17 09:48:49 +08:00
|
|
|
|
2020-03-31 02:16:10 +08:00
|
|
|
@action
|
|
|
|
filterGroups(value) {
|
|
|
|
this.set("filter", value);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2020-03-31 02:16:10 +08:00
|
|
|
|
|
|
|
@action
|
|
|
|
emojiUploaded(emoji, group) {
|
|
|
|
emoji.url += "?t=" + new Date().getTime();
|
|
|
|
emoji.group = group;
|
|
|
|
this.model.pushObject(EmberObject.create(emoji));
|
2022-01-17 09:48:49 +08:00
|
|
|
this._highlightEmojiList();
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2020-03-31 02:16:10 +08:00
|
|
|
|
|
|
|
@action
|
|
|
|
destroyEmoji(emoji) {
|
2022-08-30 01:59:57 +08: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);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
}
|