discourse/app/assets/javascripts/select-kit/components/admin-agree-flag-dropdown.js.es6

132 lines
3.7 KiB
Plaintext
Raw Normal View History

import DropdownSelectBox from "select-kit/components/dropdown-select-box";
import computed from "ember-addons/ember-computed-decorators";
export default DropdownSelectBox.extend({
pluginApiIdentifiers: ["admin-agree-flag-dropdown"],
classNames: ["agree-flag", "admin-agree-flag-dropdown"],
adminTools: Ember.inject.service(),
nameProperty: "label",
allowInitialValueMutation: false,
headerIcon: "thumbs-o-up",
computeHeaderContent() {
let content = this._super(...arguments);
content.name = `${I18n.t("admin.flags.agree")}...`;
return content;
},
@computed("adminTools", "post.user")
spammerDetails(adminTools, user) {
return adminTools.spammerDetails(user);
},
2018-06-15 23:03:24 +08:00
canDeleteSpammer: Ember.computed.and(
"spammerDetails.canDelete",
"post.flaggedForSpam"
),
computeContent() {
const content = [];
const post = this.get("post");
const canDeleteSpammer = this.get("canDeleteSpammer");
if (post.user_deleted) {
content.push({
2019-01-22 19:02:02 +08:00
icon: "far-eye",
id: "confirm-agree-restore",
action: () => this.send("perform", "restore"),
2018-06-15 23:03:24 +08:00
label: I18n.t("admin.flags.agree_flag_restore_post"),
description: I18n.t("admin.flags.agree_flag_restore_post_title")
});
} else {
if (!post.get("postHidden")) {
content.push({
2019-01-22 19:02:02 +08:00
icon: "far-eye-slash",
action: () => this.send("perform", "hide"),
id: "confirm-agree-hide",
label: I18n.t("admin.flags.agree_flag_hide_post"),
description: I18n.t("admin.flags.agree_flag_hide_post_title")
});
}
}
content.push({
icon: "thumbs-o-up",
id: "confirm-agree-keep",
2018-06-15 23:03:24 +08:00
description: I18n.t("admin.flags.agree_flag_title"),
action: () => this.send("perform", "keep"),
2018-06-15 23:03:24 +08:00
label: I18n.t("admin.flags.agree_flag")
});
content.push({
2018-06-15 23:03:24 +08:00
icon: "ban",
id: "confirm-agree-suspend",
description: I18n.t("admin.flags.agree_flag_suspend_title"),
action: () => this.send("showSuspendModal"),
2018-06-15 23:03:24 +08:00
label: I18n.t("admin.flags.agree_flag_suspend")
});
content.push({
2018-06-15 23:03:24 +08:00
icon: "microphone-slash",
id: "confirm-agree-silence",
description: I18n.t("admin.flags.agree_flag_silence_title"),
action: () => this.send("showSilenceModal"),
2018-06-15 23:03:24 +08:00
label: I18n.t("admin.flags.agree_flag_silence")
});
if (canDeleteSpammer) {
content.push({
2018-06-15 23:03:24 +08:00
title: I18n.t("admin.flags.delete_spammer_title"),
icon: "exclamation-triangle",
id: "delete-spammer",
action: () => this.send("deleteSpammer"),
2018-06-15 23:03:24 +08:00
label: I18n.t("admin.flags.delete_spammer")
});
}
return content;
},
mutateValue(value) {
2018-06-15 23:03:24 +08:00
const computedContentItem = this.get("computedContent").findBy(
"value",
value
);
Ember.get(computedContentItem, "originalContent.action")();
},
actions: {
deleteSpammer() {
let spammerDetails = this.get("spammerDetails");
2017-11-11 04:55:48 +08:00
this.attrs.removeAfter(spammerDetails.deleteUser());
},
showSuspendModal() {
2018-06-15 23:03:24 +08:00
let post = this.get("post");
let user = post.get("user");
this.get("adminTools").showSuspendModal(user, {
post,
before: () => {
2018-06-15 23:03:24 +08:00
return this.attrs.removeAfter(post.agreeFlags("suspended"));
}
});
},
showSilenceModal() {
2018-06-15 23:03:24 +08:00
let post = this.get("post");
let user = post.get("user");
this.get("adminTools").showSilenceModal(user, {
post,
before: () => {
2018-06-15 23:03:24 +08:00
return this.attrs.removeAfter(post.agreeFlags("silenced"));
}
});
},
perform(action) {
let flaggedPost = this.get("post");
2017-11-11 04:55:48 +08:00
this.attrs.removeAfter(flaggedPost.agreeFlags(action));
2018-06-15 23:03:24 +08:00
}
}
});