2024-11-22 17:11:51 +01:00
|
|
|
import { service } from "@ember/service";
|
2022-07-27 15:40:05 +02:00
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
2024-11-22 17:11:51 +01:00
|
|
|
import I18n from "I18n";
|
|
|
|
import { findCustomWizard, updateCachedWizard } from "../models/custom-wizard";
|
2022-07-27 15:40:05 +02:00
|
|
|
|
|
|
|
export default DiscourseRoute.extend({
|
2024-02-23 10:33:42 +01:00
|
|
|
dialog: service(),
|
|
|
|
|
2022-07-27 15:40:05 +02:00
|
|
|
titleToken() {
|
2022-07-27 15:40:48 +02:00
|
|
|
const wizard = this.modelFor("custom-wizard");
|
|
|
|
return wizard ? wizard.name || wizard.id : I18n.t("wizard.custom_title");
|
2022-07-27 15:40:05 +02:00
|
|
|
},
|
2017-10-13 15:02:34 +02:00
|
|
|
|
2019-07-02 06:49:14 +02:00
|
|
|
beforeModel(transition) {
|
2022-03-16 12:33:34 +01:00
|
|
|
if (transition.intent.queryParams) {
|
|
|
|
this.set("queryParams", transition.intent.queryParams);
|
|
|
|
}
|
2019-07-02 06:49:14 +02:00
|
|
|
},
|
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
model(params) {
|
2021-03-28 11:06:49 +02:00
|
|
|
return findCustomWizard(params.wizard_id, this.get("queryParams"));
|
2017-10-13 15:02:34 +02:00
|
|
|
},
|
|
|
|
|
2021-09-22 10:22:05 +02:00
|
|
|
showDialog(wizardModel) {
|
2022-07-26 16:18:09 +02:00
|
|
|
const title = I18n.t("wizard.incomplete_submission.title", {
|
2021-09-22 10:22:05 +02:00
|
|
|
date: moment(wizardModel.submission_last_updated_at).format(
|
|
|
|
"MMMM Do YYYY"
|
2022-06-15 08:59:09 +02:00
|
|
|
),
|
2021-09-22 10:22:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const buttons = [
|
|
|
|
{
|
2022-07-26 16:18:09 +02:00
|
|
|
label: I18n.t("wizard.incomplete_submission.restart"),
|
2021-09-22 10:22:05 +02:00
|
|
|
class: "btn btn-default",
|
2024-02-23 10:33:42 +01:00
|
|
|
action: () => {
|
2021-09-22 10:22:05 +02:00
|
|
|
wizardModel.restart();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-07-26 16:18:09 +02:00
|
|
|
label: I18n.t("wizard.incomplete_submission.resume"),
|
2021-09-22 10:22:05 +02:00
|
|
|
class: "btn btn-primary",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-02-23 10:39:12 +01:00
|
|
|
this.dialog.dialog({ title, buttons, type: "confirm" });
|
2021-09-22 10:22:05 +02:00
|
|
|
},
|
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
afterModel(model) {
|
|
|
|
updateCachedWizard(model);
|
2022-03-16 12:33:34 +01:00
|
|
|
},
|
2021-04-20 19:58:19 +02:00
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
setupController(controller, model) {
|
|
|
|
controller.setProperties({
|
|
|
|
customWizard: true,
|
2022-03-16 12:33:34 +01:00
|
|
|
logoUrl: this.siteSettings.logo_small,
|
2021-03-28 11:06:49 +02:00
|
|
|
reset: null,
|
2022-07-27 12:47:50 +02:00
|
|
|
model,
|
2017-10-13 15:02:34 +02:00
|
|
|
});
|
2022-03-16 12:33:34 +01:00
|
|
|
|
2022-07-29 17:32:41 +02:00
|
|
|
const stepModel = this.modelFor("custom-wizard-step");
|
2022-03-16 12:33:34 +01:00
|
|
|
if (
|
|
|
|
model.resume_on_revisit &&
|
|
|
|
model.submission_last_updated_at &&
|
|
|
|
stepModel.index > 0
|
|
|
|
) {
|
|
|
|
this.showDialog(model);
|
|
|
|
}
|
2022-07-26 16:18:09 +02:00
|
|
|
|
2022-07-27 12:47:50 +02:00
|
|
|
const background = model.get("background");
|
|
|
|
if (background) {
|
|
|
|
document.body.style.background = background;
|
|
|
|
}
|
2022-07-26 16:18:09 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
activate() {
|
|
|
|
if (!document.body.classList.contains("custom-wizard")) {
|
|
|
|
document.body.classList.add("custom-wizard");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
deactivate() {
|
|
|
|
if (document.body.classList.contains("custom-wizard")) {
|
|
|
|
document.body.classList.remove("custom-wizard");
|
|
|
|
}
|
|
|
|
|
2022-07-27 12:47:50 +02:00
|
|
|
document.body.style.background = "";
|
2022-07-26 16:18:09 +02:00
|
|
|
},
|
2017-10-13 15:02:34 +02:00
|
|
|
});
|