0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-24 02:10:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/routes/custom-wizard-step.js.es6

63 Zeilen
1,4 KiB
Text

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";
import { scrollTop } from "discourse/mixins/scroll-top";
import { action } from "@ember/object";
2023-09-14 15:47:52 +02:00
import { inject as service } from "@ember/service";
2020-05-14 05:42:11 +02:00
2022-03-16 12:33:34 +01:00
export default Route.extend({
router: service(),
beforeModel() {
const wizard = getCachedWizard();
this.set("wizard", wizard);
if (!wizard || !wizard.permitted || wizard.completed) {
this.router.replaceWith("customWizard");
}
},
2017-10-13 15:02:34 +02:00
model(params) {
const wizard = this.wizard;
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) {
if (model.completed) {
2023-09-14 15:42:12 +02:00
return this.router.transitionTo("wizard.index");
}
return model.set("wizardId", this.wizard.id);
2017-10-13 15:02:34 +02:00
},
setupController(controller, model) {
let props = {
step: model,
wizard: this.wizard,
};
if (!model.permitted) {
props["stepMessage"] = {
state: "not-permitted",
text: model.permitted_message || I18n.t("wizard.step_not_permitted"),
};
2019-07-27 09:01:29 +02:00
if (model.index > 0) {
props["showReset"] = true;
2019-07-27 09:01:29 +02:00
}
}
controller.setProperties(props);
},
@action
didTransition() {
scrollTop();
return true;
},
2017-10-13 15:02:34 +02:00
});