2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2020-02-03 21:22:14 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2017-11-21 18:53:09 +08:00
|
|
|
layoutName: "select-kit/templates/components/topic-notifications-button",
|
2020-02-03 21:22:14 +08:00
|
|
|
classNames: ["topic-notifications-button"],
|
|
|
|
appendReason: true,
|
2017-10-20 03:51:08 +08:00
|
|
|
showFullTitle: true,
|
2020-02-22 04:32:58 +08:00
|
|
|
placement: "bottom-start",
|
2020-02-03 21:22:14 +08:00
|
|
|
|
2020-02-13 17:01:28 +08:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
this.appEvents.on(
|
|
|
|
"topic-notifications-button:changed",
|
|
|
|
this,
|
|
|
|
"_changeTopicNotificationLevel"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
this.appEvents.off(
|
|
|
|
"topic-notifications-button:changed",
|
|
|
|
this,
|
|
|
|
"_changeTopicNotificationLevel"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_changeTopicNotificationLevel(level) {
|
2020-03-11 00:17:54 +08:00
|
|
|
// this change is coming from a keyboard event
|
|
|
|
if (level.event) {
|
|
|
|
const topicSectionNode = level.event.target.querySelector("#topic");
|
|
|
|
if (topicSectionNode && topicSectionNode.dataset.topicId) {
|
|
|
|
const topicId = parseInt(topicSectionNode.dataset.topicId, 10);
|
|
|
|
if (topicId && topicId !== this.topic.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-13 17:01:28 +08:00
|
|
|
if (level.id !== this.notificationLevel) {
|
|
|
|
this.topic.details.updateNotifications(level.id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
actions: {
|
2020-02-13 17:01:28 +08:00
|
|
|
changeTopicNotificationLevel(level, notification) {
|
|
|
|
this._changeTopicNotificationLevel(notification);
|
2020-02-03 21:22:14 +08:00
|
|
|
}
|
|
|
|
}
|
2017-10-20 03:51:08 +08:00
|
|
|
});
|