wizard-custom-input.js.es6 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { default as computed, on, observes } from 'ember-addons/ember-computed-decorators';
  2. import { getOwner } from 'discourse-common/lib/get-owner';
  3. const fieldNotPresent = (f) => { return f == null || f === undefined };
  4. export default Ember.Component.extend({
  5. classNames: 'custom-input',
  6. noneKey: 'admin.wizard.select_field',
  7. noneValue: 'admin.wizard.none',
  8. inputKey: 'admin.wizard.key',
  9. inputValue: 'admin.wizard.value',
  10. customDisabled: Ember.computed.alias('input.user_field'),
  11. @computed('input.value_custom', 'input.user_field')
  12. valueDisabled(custom, user) {
  13. return Boolean(custom || user);
  14. },
  15. @on('init')
  16. setupUserFields() {
  17. const allowUserField = this.get('allowUserField');
  18. if (allowUserField) {
  19. const store = getOwner(this).lookup('store:main');
  20. store.findAll('user-field').then((result) => {
  21. if (result && result.content && result.content.length) {
  22. this.set('userFields', result.content.map((f) => {
  23. return {
  24. id: `user_field_${f.id}`,
  25. name: f.name
  26. }
  27. }));
  28. }
  29. });
  30. }
  31. }
  32. });