2019-03-27 17:41:50 +08:00
|
|
|
import DropdownSelectBox from "select-kit/components/dropdown-select-box";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2019-03-29 18:14:53 +08:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
2019-07-31 22:31:02 +08:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2019-03-27 17:41:50 +08:00
|
|
|
|
|
|
|
export default DropdownSelectBox.extend({
|
|
|
|
classNames: ["user-notifications", "user-notifications-dropdown"],
|
|
|
|
nameProperty: "label",
|
2019-07-31 22:31:02 +08:00
|
|
|
|
2019-03-27 17:41:50 +08:00
|
|
|
computeContent() {
|
|
|
|
const content = [];
|
|
|
|
|
|
|
|
content.push({
|
|
|
|
icon: "user",
|
2019-03-29 18:14:53 +08:00
|
|
|
id: "changeToNormal",
|
|
|
|
description: I18n.t("user.user_notifications.normal_option_title"),
|
|
|
|
label: I18n.t("user.user_notifications.normal_option")
|
2019-03-27 17:41:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
content.push({
|
|
|
|
icon: "times-circle",
|
2019-03-29 18:14:53 +08:00
|
|
|
id: "changeToMuted",
|
|
|
|
description: I18n.t("user.user_notifications.mute_option_title"),
|
|
|
|
label: I18n.t("user.user_notifications.mute_option")
|
2019-03-27 17:41:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (this.get("user.can_ignore_user")) {
|
|
|
|
content.push({
|
|
|
|
icon: "eye-slash",
|
2019-03-29 18:14:53 +08:00
|
|
|
id: "changeToIgnored",
|
|
|
|
description: I18n.t("user.user_notifications.ignore_option_title"),
|
|
|
|
label: I18n.t("user.user_notifications.ignore_option")
|
2019-03-27 17:41:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
2019-07-31 22:31:02 +08:00
|
|
|
@computed("value")
|
|
|
|
headerIcon(value) {
|
|
|
|
return this.computeContent().find(row => row.id === value).icon;
|
|
|
|
},
|
|
|
|
|
2019-03-29 18:14:53 +08:00
|
|
|
changeToNormal() {
|
2019-07-31 22:31:02 +08:00
|
|
|
this.updateNotificationLevel("normal").catch(popupAjaxError);
|
2019-03-29 18:14:53 +08:00
|
|
|
},
|
|
|
|
changeToMuted() {
|
2019-07-31 22:31:02 +08:00
|
|
|
this.updateNotificationLevel("mute").catch(popupAjaxError);
|
2019-03-29 18:14:53 +08:00
|
|
|
},
|
|
|
|
changeToIgnored() {
|
2019-07-31 22:31:02 +08:00
|
|
|
showModal("ignore-duration", {
|
2019-05-27 16:15:39 +08:00
|
|
|
model: this.user
|
2019-03-29 18:14:53 +08:00
|
|
|
});
|
2019-07-31 22:31:02 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
@computed("user.ignored", "user.muted")
|
|
|
|
value() {
|
|
|
|
if (this.get("user.ignored")) {
|
|
|
|
return "changeToIgnored";
|
|
|
|
} else if (this.get("user.muted")) {
|
|
|
|
return "changeToMuted";
|
|
|
|
} else {
|
|
|
|
return "changeToNormal";
|
|
|
|
}
|
2019-03-29 18:14:53 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
_select(id) {
|
|
|
|
this.select(
|
|
|
|
this.collectionComputedContent.find(c => c.originalContent.id === id)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2019-03-27 17:41:50 +08:00
|
|
|
actions: {
|
2019-03-29 18:14:53 +08:00
|
|
|
onSelect(level) {
|
|
|
|
this[level]();
|
2019-03-27 17:41:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|