custom.js.es6 801 B

1234567891011121314151617181920212223242526272829
  1. import { default as computed } from 'ember-addons/ember-computed-decorators';
  2. import WizardField from 'wizard/models/wizard-field';
  3. import { ajax } from 'wizard/lib/ajax';
  4. import Step from 'wizard/models/step';
  5. const CustomWizard = Ember.Object.extend({
  6. @computed('steps.length')
  7. totalSteps: length => length
  8. });
  9. export function findCustomWizard(wizardId) {
  10. return ajax({ url: `/w/${wizardId}` }).then(result => {
  11. const wizard = result.wizard;
  12. if (!wizard) return null;
  13. if (!wizard.completed) {
  14. wizard.steps = wizard.steps.map(step => {
  15. const stepObj = Step.create(step);
  16. stepObj.fields = stepObj.fields.map(f => WizardField.create(f));
  17. return stepObj;
  18. });
  19. }
  20. return CustomWizard.create(wizard);
  21. });
  22. };
  23. export default CustomWizard;