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

85 lines
2.3 KiB
Plaintext
Raw Normal View History

import DropdownSelectBox from "select-kit/components/dropdown-select-box";
import computed from "ember-addons/ember-computed-decorators";
const { get } = Ember;
export default DropdownSelectBox.extend({
classNames: ["delete-flag", "admin-delete-flag-dropdown"],
adminTools: Ember.inject.service(),
nameProperty: "label",
2019-01-22 19:02:02 +08:00
headerIcon: "far-trash-alt",
computeHeaderContent() {
let content = this._super(...arguments);
content.name = `${I18n.t("admin.flags.delete")}...`;
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 canDeleteSpammer = this.get("canDeleteSpammer");
content.push({
2019-01-23 03:42:00 +08:00
icon: "external-link-alt",
id: "delete-defer",
action: () => this.send("deletePostDeferFlag"),
label: I18n.t("admin.flags.delete_post_defer_flag"),
2018-06-15 23:03:24 +08:00
description: I18n.t("admin.flags.delete_post_defer_flag_title")
});
content.push({
icon: "thumbs-o-up",
id: "delete-agree",
action: () => this.send("deletePostAgreeFlag"),
label: I18n.t("admin.flags.delete_post_agree_flag"),
2018-06-15 23:03:24 +08:00
description: I18n.t("admin.flags.delete_post_agree_flag_title")
});
if (canDeleteSpammer) {
content.push({
2018-06-15 23:03:24 +08:00
title: I18n.t("admin.flags.delete_post_agree_flag_title"),
icon: "exclamation-triangle",
id: "delete-spammer",
action: () => this.send("deleteSpammer"),
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
);
get(computedContentItem, "originalContent.action")();
},
actions: {
deleteSpammer() {
let spammerDetails = this.get("spammerDetails");
this.attrs.removeAfter(spammerDetails.deleteUser());
},
deletePostDeferFlag() {
2018-06-15 23:03:24 +08:00
let flaggedPost = this.get("post");
this.attrs.removeAfter(flaggedPost.deferFlags(true));
},
deletePostAgreeFlag() {
2018-06-15 23:03:24 +08:00
let flaggedPost = this.get("post");
this.attrs.removeAfter(flaggedPost.agreeFlags("delete"));
}
}
});