0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6

95 Zeilen
2,3 KiB
Text

2020-04-13 14:17:22 +02:00
import DiscourseRoute from "discourse/routes/discourse";
import { buildFieldTypes } from '../lib/wizard-schema';
2020-10-20 07:40:23 +02:00
import EmberObject, { set } from "@ember/object";
import { A } from "@ember/array";
2020-04-13 14:17:22 +02:00
import { all } from "rsvp";
import { ajax } from 'discourse/lib/ajax';
export default DiscourseRoute.extend({
model() {
2020-04-14 01:39:21 +02:00
return ajax("/admin/wizards/wizard");
2020-04-13 14:17:22 +02:00
},
afterModel(model) {
buildFieldTypes(model.field_types);
2020-04-13 14:17:22 +02:00
return all([
this._getThemes(model),
this._getApis(model),
this._getUserFields(model)
]);
},
_getThemes(model) {
return ajax('/admin/themes')
.then((result) => {
set(model, 'themes', result.themes.map(t => {
return {
id: t.id,
name: t.name
}
}));
});
},
_getApis(model) {
2020-04-15 06:29:47 +02:00
return ajax('/admin/wizards/api')
2020-04-13 14:17:22 +02:00
.then((result) => set(model, 'apis', result));
},
_getUserFields(model) {
return this.store.findAll('user-field').then((result) => {
if (result && result.content) {
set(model, 'userFields',
result.content.map((f) => ({
id: `user_field_${f.id}`,
name: f.name
}))
2020-04-13 14:17:22 +02:00
);
}
});
},
2020-04-14 01:39:21 +02:00
currentWizard() {
2020-04-13 14:17:22 +02:00
const params = this.paramsFor('adminWizardsWizardShow');
2020-04-14 01:39:21 +02:00
2020-04-13 14:17:22 +02:00
if (params && params.wizardId) {
2020-04-14 01:39:21 +02:00
return params.wizardId;
} else {
return null;
}
},
setupController(controller, model) {
controller.setProperties({
2020-04-14 01:39:21 +02:00
wizardList: model.wizard_list,
2020-10-20 07:40:23 +02:00
wizardId: this.currentWizard(),
custom_fields: A(model.custom_fields.map(f => EmberObject.create(f)))
});
2020-04-13 14:17:22 +02:00
},
actions: {
changeWizard(wizardId) {
this.controllerFor('adminWizardsWizard').set('wizardId', wizardId);
if (wizardId) {
this.transitionTo('adminWizardsWizardShow', wizardId);
} else {
this.transitionTo('adminWizardsWizard');
}
},
afterDestroy() {
this.transitionTo('adminWizardsWizard').then(() => this.refresh());
},
afterSave(wizardId) {
this.refresh().then(() => this.send('changeWizard', wizardId));
},
createWizard() {
this.controllerFor('adminWizardsWizard').set('wizardId', 'create');
this.transitionTo('adminWizardsWizardShow', 'create');
}
}
});