2017-09-23 04:34:07 +02:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2017-09-24 05:01:18 +02:00
|
|
|
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
const CustomWizard = Discourse.Model.extend({
|
|
|
|
steps: Ember.A(),
|
|
|
|
|
2017-09-24 05:01:18 +02:00
|
|
|
@computed('name')
|
|
|
|
dasherizedName(name) {
|
|
|
|
return Ember.String.dasherize(name);
|
|
|
|
},
|
|
|
|
|
2017-09-23 04:34:07 +02:00
|
|
|
save() {
|
2017-09-24 05:01:18 +02:00
|
|
|
const wizard = {
|
|
|
|
id: this.get('id'),
|
|
|
|
steps: this.get('steps').toArray(),
|
|
|
|
name: this.get('name')
|
|
|
|
};
|
|
|
|
|
|
|
|
return ajax(`/admin/wizards/custom/save`, {
|
2017-09-23 04:34:07 +02:00
|
|
|
type: 'PUT',
|
2017-09-24 05:01:18 +02:00
|
|
|
data: {
|
|
|
|
wizard: JSON.stringify(wizard)
|
|
|
|
}
|
2017-09-23 04:34:07 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-09-24 05:01:18 +02:00
|
|
|
remove() {
|
|
|
|
return ajax(`/admin/wizards/custom/remove`, {
|
|
|
|
type: 'DELETE',
|
|
|
|
data: {
|
|
|
|
id: this.get('id')
|
|
|
|
}
|
|
|
|
}).then(() => this.destroy());
|
2017-09-23 04:34:07 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
CustomWizard.reopenClass({
|
|
|
|
findAll() {
|
|
|
|
return ajax("/admin/wizards/custom/all").then(result => {
|
|
|
|
return result.wizards.map(w => CustomWizard.create(w));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
create() {
|
|
|
|
const wizard = this._super.apply(this, arguments);
|
|
|
|
const steps = wizard.get('steps');
|
|
|
|
|
|
|
|
steps.forEach((s) => {
|
|
|
|
s.fields = Ember.A(s.fields);
|
2017-09-24 05:01:18 +02:00
|
|
|
s.fields.forEach((f) => f.choices = Ember.A(f.choices));
|
2017-09-23 04:34:07 +02:00
|
|
|
s.actions = Ember.A(s.actions);
|
|
|
|
});
|
|
|
|
|
|
|
|
return wizard;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default CustomWizard;
|