2018-06-15 11:03:24 -04:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2016-06-15 13:49:57 -04:00
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
2018-06-15 11:03:24 -04:00
|
|
|
classNames: ["hook-event"],
|
|
|
|
typeName: Ember.computed.alias("type.name"),
|
2016-06-15 13:49:57 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@computed("typeName")
|
2016-06-15 13:49:57 -04:00
|
|
|
name(typeName) {
|
|
|
|
return I18n.t(`admin.web_hooks.${typeName}_event.name`);
|
|
|
|
},
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@computed("typeName")
|
2016-06-15 13:49:57 -04:00
|
|
|
details(typeName) {
|
|
|
|
return I18n.t(`admin.web_hooks.${typeName}_event.details`);
|
|
|
|
},
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@computed("model.[]", "typeName")
|
2016-06-15 13:49:57 -04:00
|
|
|
eventTypeExists(eventTypes, typeName) {
|
|
|
|
return eventTypes.any(event => event.name === typeName);
|
|
|
|
},
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@computed("eventTypeExists")
|
2016-06-15 13:49:57 -04:00
|
|
|
enabled: {
|
|
|
|
get(eventTypeExists) {
|
|
|
|
return eventTypeExists;
|
|
|
|
},
|
|
|
|
set(value, eventTypeExists) {
|
2019-05-27 04:15:39 -04:00
|
|
|
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 {
|
2018-06-15 11:03:24 -04:00
|
|
|
model.removeObjects(
|
|
|
|
model.filter(eventType => eventType.name === type.name)
|
|
|
|
);
|
2016-06-15 13:49:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|