discourse/app/assets/javascripts/admin/components/admin-web-hook-event-chooser.js.es6
Mark VanLandingham 2ae21e9c35
DEV: Import every instance of Ember.computed function (#8267)
* DEV: Import every instance of Ember.computed function

* export default for Ember.computed
2019-10-30 15:28:29 -05:00

47 lines
1.1 KiB
JavaScript

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