2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-31 04:28:29 +08:00
|
|
|
import { alias } from "@ember/object/computed";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2016-06-16 01:49:57 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2016-06-16 01:49:57 +08:00
|
|
|
classNames: ["hook-event"],
|
2019-10-31 04:28:29 +08:00
|
|
|
typeName: alias("type.name"),
|
2016-06-16 01:49:57 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("typeName")
|
2016-06-16 01:49:57 +08:00
|
|
|
name(typeName) {
|
|
|
|
return I18n.t(`admin.web_hooks.${typeName}_event.name`);
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("typeName")
|
2016-06-16 01:49:57 +08:00
|
|
|
details(typeName) {
|
|
|
|
return I18n.t(`admin.web_hooks.${typeName}_event.details`);
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("model.[]", "typeName")
|
2016-06-16 01:49:57 +08:00
|
|
|
eventTypeExists(eventTypes, typeName) {
|
|
|
|
return eventTypes.any(event => event.name === typeName);
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("eventTypeExists")
|
2016-06-16 01:49:57 +08:00
|
|
|
enabled: {
|
|
|
|
get(eventTypeExists) {
|
|
|
|
return eventTypeExists;
|
|
|
|
},
|
|
|
|
set(value, eventTypeExists) {
|
2019-05-27 16:15:39 +08:00
|
|
|
const type = this.type;
|
|
|
|
const model = this.model;
|
2016-06-16 01:49:57 +08:00
|
|
|
// add an association when not exists
|
|
|
|
if (value !== eventTypeExists) {
|
|
|
|
if (value) {
|
|
|
|
model.addObject(type);
|
|
|
|
} else {
|
|
|
|
model.removeObjects(
|
|
|
|
model.filter(eventType => eventType.name === type.name)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|