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

103 Zeilen
2,4 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";
2020-04-13 14:17:22 +02:00
export default DiscourseRoute.extend({
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) {
this.transitionTo("adminWizardsWizardShow", wizardId);
2020-04-13 14:17:22 +02:00
} else {
this.transitionTo("adminWizardsWizard");
2020-04-13 14:17:22 +02:00
}
},
2020-04-13 14:17:22 +02:00
afterDestroy() {
this.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");
this.transitionTo("adminWizardsWizardShow", "create");
},
},
});