wizard-custom-action.js.es6 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
  2. const ACTION_TYPES = [
  3. { id: 'create_topic', name: 'Create Topic' },
  4. { id: 'update_profile', name: 'Update Profile' },
  5. { id: 'send_message', name: 'Send Message' }
  6. ];
  7. const PROFILE_FIELDS = [
  8. 'name',
  9. 'date_of_birth',
  10. 'title',
  11. 'locale',
  12. 'location',
  13. 'website',
  14. 'bio_raw',
  15. 'profile_background',
  16. 'card_background',
  17. 'theme_id'
  18. ];
  19. export default Ember.Component.extend({
  20. classNames: 'wizard-custom-action',
  21. types: ACTION_TYPES,
  22. profileFields: PROFILE_FIELDS,
  23. createTopic: Ember.computed.equal('action.type', 'create_topic'),
  24. updateProfile: Ember.computed.equal('action.type', 'update_profile'),
  25. sendMessage: Ember.computed.equal('action.type', 'send_message'),
  26. disableId: Ember.computed.not('action.isNew'),
  27. @computed('currentStepId', 'wizard.save_submissions')
  28. availableFields(currentStepId, saveSubmissions) {
  29. const allSteps = this.get('wizard.steps');
  30. let steps = allSteps;
  31. let fields = [];
  32. if (!saveSubmissions) {
  33. steps = [allSteps.findBy('id', currentStepId)];
  34. }
  35. steps.forEach((s) => {
  36. if (s.fields && s.fields.length > 0) {
  37. let stepFields = s.fields.map((f) => {
  38. return Ember.Object.create({
  39. id: f.id,
  40. label: `${f.id} (${s.id})`
  41. });
  42. });
  43. fields.push(...stepFields);
  44. }
  45. });
  46. return fields;
  47. },
  48. @computed('availableFields')
  49. builderWizardFields(fields) {
  50. return fields.map((f) => ` w{${f.id}}`);
  51. },
  52. @computed()
  53. builderUserFields() {
  54. const noTheme = PROFILE_FIELDS.filter((f) => f !== 'theme_id');
  55. const fields = noTheme.concat(['email', 'username']);
  56. return fields.map((f) => ` u{${f}}`);
  57. },
  58. @observes('action.custom_category_wizard_field')
  59. toggleCustomCategoryUserField() {
  60. const wizard = this.get('action.custom_category_wizard_field');
  61. if (wizard) this.set('action.custom_category_user_field', false);
  62. },
  63. @observes('action.custom_category_user_field')
  64. toggleCustomCategoryWizardField() {
  65. const user = this.get('action.custom_category_user_field');
  66. if (user) this.set('action.custom_category_wizard_field', false);
  67. }
  68. });