wizard-custom-field.js.es6 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { default as computed, on, observes } from 'ember-addons/ember-computed-decorators';
  2. export default Ember.Component.extend({
  3. classNames: 'wizard-custom-field',
  4. isDropdown: Ember.computed.equal('field.type', 'dropdown'),
  5. @on('init')
  6. @observes('field')
  7. setup() {
  8. this.set('existingId', this.get('field.id'));
  9. },
  10. @computed('field.type')
  11. isInput: (type) => type === 'text' || type === 'textarea',
  12. @computed('field.choices.[]')
  13. dropdownChoices: choices => choices,
  14. @computed('field.choices_filters.[]')
  15. presetFilters: filters => filters,
  16. @computed()
  17. presetChoices() {
  18. return [
  19. { id: 'categories', name: I18n.t('admin.wizard.field.choices_preset.categories') }
  20. ];
  21. },
  22. actions: {
  23. addFilter() {
  24. if (!this.get('field.choices_filters')) {
  25. this.set('field.choices_filters', Ember.A());
  26. }
  27. this.get('field.choices_filters').pushObject(Ember.Object.create());
  28. },
  29. removeFilter(f) {
  30. this.get('field.choices_filters').removeObject(f);
  31. },
  32. addChoice() {
  33. if (!this.get('field.choices')) {
  34. this.set('field.choices', Ember.A());
  35. }
  36. this.get('field.choices').pushObject(Ember.Object.create());
  37. },
  38. removeChoice(c) {
  39. this.get('field.choices').removeObject(c);
  40. }
  41. }
  42. });