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-show.js.es6

50 Zeilen
1,3 KiB
Text

import CustomWizard from "../models/custom-wizard";
import { ajax } from "discourse/lib/ajax";
2020-04-13 14:17:22 +02:00
import DiscourseRoute from "discourse/routes/discourse";
2020-05-28 05:06:06 +02:00
import I18n from "I18n";
import { selectKitContent } from "../lib/wizard";
2020-04-13 14:17:22 +02:00
export default DiscourseRoute.extend({
model(params) {
if (params.wizardId === "create") {
2020-04-13 14:17:22 +02:00
return { create: true };
} else {
return ajax(`/admin/wizards/wizard/${params.wizardId}`);
}
},
2020-04-13 14:17:22 +02:00
afterModel(model) {
if (model.none) {
return this.transitionTo("adminWizardsWizard");
2020-04-13 14:17:22 +02:00
}
},
2020-04-14 01:39:21 +02:00
setupController(controller, model) {
const parentModel = this.modelFor("adminWizardsWizard");
const wizard = CustomWizard.create(!model || model.create ? {} : model);
const fieldTypes = Object.keys(parentModel.field_types).map((type) => {
2020-04-20 13:40:32 +02:00
return {
id: type,
name: I18n.t(`admin.wizard.field.type.${type}`),
2020-04-20 13:40:32 +02:00
};
});
2020-04-20 11:41:13 +02:00
let props = {
2020-04-13 14:17:22 +02:00
wizardList: parentModel.wizard_list,
2020-04-20 13:40:32 +02:00
fieldTypes,
2020-04-13 14:17:22 +02:00
userFields: parentModel.userFields,
customFields: selectKitContent(
parentModel.custom_fields.map((f) => f.name)
),
2020-04-13 14:17:22 +02:00
apis: parentModel.apis,
themes: parentModel.themes,
wizard,
currentStep: wizard.steps[0],
currentAction: wizard.actions[0],
creating: model.create,
2020-04-20 11:41:13 +02:00
};
2020-04-20 11:41:13 +02:00
controller.setProperties(props);
},
2020-04-13 14:17:22 +02:00
});