discourse/app/assets/javascripts/admin/components/admin-web-hook-event-choose...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.2 KiB
Plaintext
Raw Normal View History

import discourseComputed from "discourse-common/utils/decorators";
import { alias } from "@ember/object/computed";
import Component from "@ember/component";
2016-06-15 13:49:57 -04:00
export default Component.extend({
2016-06-15 13:49:57 -04:00
classNames: ["hook-event"],
typeName: alias("type.name"),
2016-06-15 13:49:57 -04:00
@discourseComputed("typeName")
2016-06-15 13:49:57 -04:00
name(typeName) {
return I18n.t(`admin.web_hooks.${typeName}_event.name`);
},
@discourseComputed("typeName")
2016-06-15 13:49:57 -04:00
details(typeName) {
return I18n.t(`admin.web_hooks.${typeName}_event.details`);
},
@discourseComputed("model.[]", "typeName")
2016-06-15 13:49:57 -04:00
eventTypeExists(eventTypes, typeName) {
return eventTypes.any(event => event.name === typeName);
},
@discourseComputed("eventTypeExists")
2016-06-15 13:49:57 -04:00
enabled: {
get(eventTypeExists) {
return eventTypeExists;
},
set(value, eventTypeExists) {
const type = this.type;
const model = this.model;
2016-06-15 13:49:57 -04: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;
}
}
});