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

106 Zeilen
2,5 KiB
Text

2020-04-13 14:17:22 +02:00
import DiscourseRoute from "discourse/routes/discourse";
2023-03-02 10:36:06 +01:00
import { buildFieldTypes, buildFieldValidations } 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";
2023-09-14 15:47:52 +02:00
import { inject as service } from "@ember/service";
2020-04-13 14:17:22 +02:00
export default DiscourseRoute.extend({
2023-09-14 15:42:12 +02:00
router: service(),
2020-04-13 14:17:22 +02:00
model() {
2020-04-14 01:39:21 +02:00
return ajax("/admin/wizards/wizard");
2020-04-13 14:17:22 +02:00
},
2020-04-13 14:17:22 +02:00
afterModel(model) {
2023-03-02 10:36:06 +01:00
buildFieldTypes(model.field_types);
2021-01-27 06:08:26 +01:00
buildFieldValidations(model.realtime_validations);
2020-04-13 14:17:22 +02:00
return all([
this._getThemes(model),
this._getApis(model),
this._getUserFields(model),
2020-04-13 14:17:22 +02:00
]);
},
2020-04-13 14:17:22 +02:00
_getThemes(model) {
return ajax("/admin/themes").then((result) => {
set(
model,
"themes",
result.themes.map((t) => {
2020-04-13 14:17:22 +02:00
return {
id: t.id,
name: t.name,
};
})
);
});
2020-04-13 14:17:22 +02:00
},
_getApis(model) {
return ajax("/admin/wizards/api").then((result) =>
set(model, "apis", result)
);
2020-04-13 14:17:22 +02:00
},
2020-04-13 14:17:22 +02:00
_getUserFields(model) {
return this.store.findAll("user-field").then((result) => {
2020-04-13 14:17:22 +02:00
if (result && result.content) {
set(
model,
"userFields",
2020-04-13 14:17:22 +02:00
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() {
const params = this.paramsFor("adminWizardsWizardShow");
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;
}
},
2020-04-14 01:39:21 +02:00
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
},
2020-04-13 14:17:22 +02:00
actions: {
changeWizard(wizardId) {
this.controllerFor("adminWizardsWizard").set("wizardId", wizardId);
2020-04-13 14:17:22 +02:00
if (wizardId) {
2023-09-14 15:42:12 +02:00
this.router.transitionTo("adminWizardsWizardShow", wizardId);
2020-04-13 14:17:22 +02:00
} else {
2023-09-14 15:42:12 +02:00
this.router.transitionTo("adminWizardsWizard");
2020-04-13 14:17:22 +02:00
}
},
2020-04-13 14:17:22 +02:00
afterDestroy() {
2023-09-14 15:42:12 +02:00
this.router.transitionTo("adminWizardsWizard").then(() => this.refresh());
2020-04-13 14:17:22 +02:00
},
2020-04-13 14:17:22 +02:00
afterSave(wizardId) {
this.refresh().then(() => this.send("changeWizard", wizardId));
2020-04-13 14:17:22 +02:00
},
2020-04-13 14:17:22 +02:00
createWizard() {
this.controllerFor("adminWizardsWizard").set("wizardId", "create");
2023-09-14 15:42:12 +02:00
this.router.transitionTo("adminWizardsWizardShow", "create");
},
},
});