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-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
2019-10-31 04:28:29 +08:00
|
|
|
import { sort } from "@ember/object/computed";
|
2020-03-31 02:16:10 +08:00
|
|
|
|
|
|
|
const ALL_FILTER = "all";
|
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2020-03-31 02:16:10 +08:00
|
|
|
filter: null,
|
|
|
|
sorting: null,
|
2019-05-28 18:15:12 +08:00
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
2020-03-31 02:16:10 +08:00
|
|
|
this.setProperties({
|
|
|
|
filter: ALL_FILTER,
|
|
|
|
sorting: ["group", "name"],
|
|
|
|
});
|
2019-05-28 18:15:12 +08:00
|
|
|
},
|
2014-12-23 08:12:26 +08:00
|
|
|
|
2020-03-31 02:16:10 +08: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-23 08:12:26 +08:00
|
|
|
},
|
2020-03-31 02:16:10 +08: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));
|
|
|
|
},
|
|
|
|
|
|
|
|
@action
|
|
|
|
destroyEmoji(emoji) {
|
|
|
|
return bootbox.confirm(
|
|
|
|
I18n.t("admin.emoji.delete_confirm", { name: emoji.get("name") }),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
(destroy) => {
|
|
|
|
if (destroy) {
|
|
|
|
return ajax("/admin/customize/emojis/" + emoji.get("name"), {
|
|
|
|
type: "DELETE",
|
|
|
|
}).then(() => {
|
|
|
|
this.model.removeObject(emoji);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2014-12-23 08:12:26 +08:00
|
|
|
},
|
|
|
|
});
|