Files
discourse-chat-integration/assets/javascripts/admin/models/rule.js.es6
T

89 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-09-12 16:16:18 +01:00
import RestModel from "discourse/models/rest";
import Category from "discourse/models/category";
import {
default as computed,
observes
} from "ember-addons/ember-computed-decorators";
export default RestModel.extend({
2017-06-28 18:04:21 +01:00
available_filters: [
2018-09-12 16:16:18 +01:00
{
id: "watch",
name: I18n.t("chat_integration.filter.watch"),
icon: "exclamation-circle"
},
{
id: "follow",
name: I18n.t("chat_integration.filter.follow"),
icon: "circle"
},
{
id: "mute",
name: I18n.t("chat_integration.filter.mute"),
icon: "times-circle"
}
2017-06-28 18:04:21 +01:00
],
available_types: [
2018-09-12 16:16:18 +01:00
{ id: "normal", name: I18n.t("chat_integration.type.normal") },
{
id: "group_message",
name: I18n.t("chat_integration.type.group_message")
},
{ id: "group_mention", name: I18n.t("chat_integration.type.group_mention") }
],
category_id: null,
tags: null,
channel_id: null,
2018-09-12 16:16:18 +01:00
filter: "watch",
type: "normal",
2017-07-04 19:37:56 +01:00
error_key: null,
2018-09-12 16:16:18 +01:00
@observes("type")
2017-10-03 17:42:07 +08:00
removeUnneededInfo() {
2018-09-12 16:16:18 +01:00
const type = this.get("type");
2017-08-21 16:46:43 +01:00
2018-09-12 16:16:18 +01:00
if (type === "normal") {
this.set("group_id", null);
2017-10-03 17:42:07 +08:00
} else {
2018-09-12 16:16:18 +01:00
this.set("category_id", null);
}
2017-10-03 17:42:07 +08:00
},
2018-09-12 16:16:18 +01:00
@computed("category_id")
category(categoryId) {
2018-09-12 16:16:18 +01:00
if (categoryId) {
return Category.findById(categoryId);
2017-10-03 17:42:07 +08:00
} else {
return false;
}
},
2018-09-12 16:16:18 +01:00
@computed("filter")
filterName(filter) {
return I18n.t(`chat_integration.filter.${filter}`);
},
updateProperties() {
2018-09-12 16:16:18 +01:00
return this.getProperties([
"type",
"category_id",
"group_id",
"tags",
"filter"
]);
2017-06-29 20:19:40 +01:00
},
createProperties() {
2018-09-12 16:16:18 +01:00
return this.getProperties([
"type",
"channel_id",
"category_id",
"group_id",
"tags",
"filter"
]);
}
});