2022-07-27 12:47:50 +02:00
|
|
|
import CustomWizardAdmin from "../models/custom-wizard-admin";
|
2021-03-28 11:06:49 +02:00
|
|
|
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";
|
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(params) {
|
2021-03-28 11:06:49 +02:00
|
|
|
if (params.wizardId === "create") {
|
2020-04-13 14:17:22 +02:00
|
|
|
return { create: true };
|
|
|
|
} else {
|
|
|
|
return ajax(`/admin/wizards/wizard/${params.wizardId}`);
|
|
|
|
}
|
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
afterModel(model) {
|
|
|
|
if (model.none) {
|
2023-09-14 15:42:12 +02:00
|
|
|
return this.router.transitionTo("adminWizardsWizard");
|
2020-04-13 14:17:22 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-14 01:39:21 +02:00
|
|
|
setupController(controller, model) {
|
2021-03-28 11:06:49 +02:00
|
|
|
const parentModel = this.modelFor("adminWizardsWizard");
|
2022-07-27 12:47:50 +02:00
|
|
|
const wizard = CustomWizardAdmin.create(
|
|
|
|
!model || model.create ? {} : model
|
|
|
|
);
|
2021-03-28 11:06:49 +02:00
|
|
|
const fieldTypes = Object.keys(parentModel.field_types).map((type) => {
|
2020-04-20 13:40:32 +02:00
|
|
|
return {
|
|
|
|
id: type,
|
2021-03-28 11:06:49 +02:00
|
|
|
name: I18n.t(`admin.wizard.field.type.${type}`),
|
2020-04-20 13:40:32 +02:00
|
|
|
};
|
2021-03-28 11:06:49 +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,
|
2021-06-08 13:39:49 +02:00
|
|
|
customFields: parentModel.custom_fields,
|
2020-04-13 14:17:22 +02:00
|
|
|
apis: parentModel.apis,
|
|
|
|
themes: parentModel.themes,
|
|
|
|
wizard,
|
|
|
|
currentStep: wizard.steps[0],
|
|
|
|
currentAction: wizard.actions[0],
|
2021-03-28 11:06:49 +02:00
|
|
|
creating: model.create,
|
2020-04-20 11:41:13 +02:00
|
|
|
};
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 11:41:13 +02:00
|
|
|
controller.setProperties(props);
|
2024-10-17 16:15:25 +02:00
|
|
|
controller.setAfterTimeGroupIds();
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2020-04-13 14:17:22 +02:00
|
|
|
});
|