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-03-27 17:41:50 +08:00
|
|
|
|
|
|
|
export default DropdownSelectBox.extend({
|
|
|
|
classNames: ["user-notifications", "user-notifications-dropdown"],
|
|
|
|
nameProperty: "label",
|
2019-03-29 18:14:53 +08:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
2019-03-27 17:41:50 +08:00
|
|
|
if (this.get("user.ignored")) {
|
|
|
|
this.set("headerIcon", "eye-slash");
|
2019-03-29 18:14:53 +08:00
|
|
|
this.set("value", "changeToIgnored");
|
2019-03-27 17:41:50 +08:00
|
|
|
} else if (this.get("user.muted")) {
|
|
|
|
this.set("headerIcon", "times-circle");
|
2019-03-29 18:14:53 +08:00
|
|
|
this.set("value", "changeToMuted");
|
2019-03-27 17:41:50 +08:00
|
|
|
} else {
|
|
|
|
this.set("headerIcon", "user");
|
2019-03-29 18:14:53 +08:00
|
|
|
this.set("value", "changeToNormal");
|
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-03-29 18:14:53 +08:00
|
|
|
changeToNormal() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.updateNotificationLevel("normal")
|
2019-03-29 18:14:53 +08:00
|
|
|
.then(() => {
|
|
|
|
this.set("user.ignored", false);
|
|
|
|
this.set("user.muted", false);
|
|
|
|
this.set("headerIcon", "user");
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
changeToMuted() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.updateNotificationLevel("mute")
|
2019-03-29 18:14:53 +08:00
|
|
|
.then(() => {
|
|
|
|
this.set("user.ignored", false);
|
|
|
|
this.set("user.muted", true);
|
|
|
|
this.set("headerIcon", "times-circle");
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
changeToIgnored() {
|
|
|
|
const controller = showModal("ignore-duration", {
|
2019-05-27 16:15:39 +08:00
|
|
|
model: this.user
|
2019-03-29 18:14:53 +08:00
|
|
|
});
|
|
|
|
controller.setProperties({
|
|
|
|
onSuccess: () => {
|
|
|
|
this.set("headerIcon", "eye-slash");
|
|
|
|
},
|
|
|
|
onClose: () => {
|
|
|
|
if (this.get("user.muted")) {
|
|
|
|
this.set("headerIcon", "times-circle");
|
|
|
|
this._select("changeToMuted");
|
|
|
|
} else if (!this.get("user.muted") && !this.get("user.ignored")) {
|
|
|
|
this.set("headerIcon", "user");
|
|
|
|
this._select("changeToNormal");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|