Ghost/ghost/admin/app/components/gh-feature-flag.js
Austin Burdine 1e3adef145 convert feature controller to service
closes #6170
- add gh-feature-flag component to create a checkbox (reduce duplicate code)
2016-02-09 08:37:44 -06:00

49 lines
1.0 KiB
JavaScript

import Ember from 'ember';
const {
computed,
inject: {service},
Component
} = Ember;
const FeatureFlagComponent = Component.extend({
tagName: 'label',
classNames: 'checkbox',
attributeBindings: ['for'],
_flagValue: null,
feature: service(),
isVisible: computed.notEmpty('_flagValue'),
init() {
this._super(...arguments);
this.get(`feature.${this.get('flag')}`).then((flagValue) => {
this.set('_flagValue', flagValue);
});
},
value: computed('_flagValue', {
get() {
return this.get('_flagValue');
},
set(key, value) {
return this.set(`feature.${this.get('flag')}`, value);
}
}),
for: computed('flag', function () {
return `labs-${this.get('flag')}`;
}),
name: computed('flag', function () {
return `labs[${this.get('flag')}]`;
})
});
FeatureFlagComponent.reopenClass({
positionalParams: ['flag']
});
export default FeatureFlagComponent;