2022-07-26 16:18:09 +02:00
|
|
|
import I18n from "I18n";
|
2022-07-27 12:47:50 +02:00
|
|
|
import { getCachedWizard } from "../models/custom-wizard";
|
2022-03-16 12:33:34 +01:00
|
|
|
import Route from "@ember/routing/route";
|
2023-04-03 07:07:25 +02:00
|
|
|
import { scrollTop } from "discourse/mixins/scroll-top";
|
|
|
|
import { action } from "@ember/object";
|
2020-05-14 05:42:11 +02:00
|
|
|
|
2022-03-16 12:33:34 +01:00
|
|
|
export default Route.extend({
|
2021-04-20 19:58:19 +02:00
|
|
|
beforeModel() {
|
2022-08-01 09:41:11 +02:00
|
|
|
const wizard = getCachedWizard();
|
|
|
|
this.set("wizard", wizard);
|
|
|
|
|
2023-02-07 12:46:17 +01:00
|
|
|
if (!wizard || !wizard.permitted || wizard.completed) {
|
2022-08-01 09:41:11 +02:00
|
|
|
this.replaceWith("customWizard");
|
|
|
|
}
|
2021-04-20 19:58:19 +02:00
|
|
|
},
|
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
model(params) {
|
2021-04-20 19:58:19 +02:00
|
|
|
const wizard = this.wizard;
|
2017-09-29 13:27:03 +02:00
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
if (wizard && wizard.steps) {
|
|
|
|
const step = wizard.steps.findBy("id", params.step_id);
|
|
|
|
return step ? step : wizard.steps[0];
|
|
|
|
} else {
|
|
|
|
return wizard;
|
|
|
|
}
|
2017-10-13 15:02:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
afterModel(model) {
|
2021-04-12 08:26:22 +02:00
|
|
|
if (model.completed) {
|
2022-03-16 12:33:34 +01:00
|
|
|
return this.transitionTo("wizard.index");
|
2021-04-12 08:26:22 +02:00
|
|
|
}
|
2021-04-20 19:58:19 +02:00
|
|
|
return model.set("wizardId", this.wizard.id);
|
2017-10-13 15:02:34 +02:00
|
|
|
},
|
|
|
|
|
2019-07-02 06:49:14 +02:00
|
|
|
setupController(controller, model) {
|
|
|
|
let props = {
|
|
|
|
step: model,
|
2021-04-20 19:58:19 +02:00
|
|
|
wizard: this.wizard,
|
2019-07-02 06:49:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!model.permitted) {
|
2021-03-28 11:06:49 +02:00
|
|
|
props["stepMessage"] = {
|
|
|
|
state: "not-permitted",
|
2022-07-26 16:18:09 +02:00
|
|
|
text: model.permitted_message || I18n.t("wizard.step_not_permitted"),
|
2019-07-02 06:49:14 +02:00
|
|
|
};
|
2019-07-27 09:01:29 +02:00
|
|
|
if (model.index > 0) {
|
2021-03-28 11:06:49 +02:00
|
|
|
props["showReset"] = true;
|
2019-07-27 09:01:29 +02:00
|
|
|
}
|
2019-07-02 06:49:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
controller.setProperties(props);
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2023-04-03 07:07:25 +02:00
|
|
|
|
|
|
|
@action
|
|
|
|
didTransition() {
|
|
|
|
scrollTop();
|
|
|
|
return true;
|
|
|
|
},
|
2017-10-13 15:02:34 +02:00
|
|
|
});
|