1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/components/wizard-custom-field.js.es6

53 Zeilen
1,3 KiB
Text

2017-10-06 04:59:02 +02:00
import { default as computed, on, observes } from 'ember-addons/ember-computed-decorators';
2017-09-23 04:34:07 +02:00
export default Ember.Component.extend({
classNames: 'wizard-custom-field',
isDropdown: Ember.computed.equal('field.type', 'dropdown'),
2017-09-24 05:01:18 +02:00
2017-10-06 04:59:02 +02:00
@on('init')
2017-10-13 15:02:34 +02:00
@observes('field')
setup() {
this.set('existingId', this.get('field.id'));
2017-09-24 05:01:18 +02:00
},
2017-09-23 04:34:07 +02:00
2017-10-13 15:02:34 +02:00
@computed('field.type')
isInput: (type) => type === 'text' || type === 'textarea',
2017-10-06 04:59:02 +02:00
@computed('field.choices.[]')
dropdownChoices: choices => choices,
2017-09-23 04:34:07 +02:00
2017-10-13 15:02:34 +02:00
@computed('field.choices_filters.[]')
presetFilters: filters => filters,
@computed()
presetChoices() {
return [
{ id: 'categories', name: I18n.t('admin.wizard.field.choices_preset.categories') }
];
},
2017-09-23 04:34:07 +02:00
actions: {
2017-10-13 15:02:34 +02:00
addFilter() {
if (!this.get('field.choices_filters')) {
this.set('field.choices_filters', Ember.A());
}
this.get('field.choices_filters').pushObject(Ember.Object.create());
},
removeFilter(f) {
this.get('field.choices_filters').removeObject(f);
},
2017-09-23 04:34:07 +02:00
addChoice() {
2017-10-13 15:02:34 +02:00
if (!this.get('field.choices')) {
this.set('field.choices', Ember.A());
}
2017-09-24 05:01:18 +02:00
this.get('field.choices').pushObject(Ember.Object.create());
2017-10-06 04:59:02 +02:00
},
removeChoice(c) {
this.get('field.choices').removeObject(c);
2017-09-23 04:34:07 +02:00
}
}
});