1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/routes/custom-wizard.js.es6

90 Zeilen
2,1 KiB
Text

2022-07-27 12:47:50 +02:00
import { findCustomWizard, updateCachedWizard } from "../models/custom-wizard";
import I18n from "I18n";
import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({
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");
},
2017-10-13 15:02:34 +02:00
beforeModel(transition) {
2022-03-16 12:33:34 +01:00
if (transition.intent.queryParams) {
this.set("queryParams", transition.intent.queryParams);
}
},
2017-10-13 15:02:34 +02:00
model(params) {
return findCustomWizard(params.wizard_id, this.get("queryParams"));
2017-10-13 15:02:34 +02:00
},
showDialog(wizardModel) {
const title = I18n.t("wizard.incomplete_submission.title", {
date: moment(wizardModel.submission_last_updated_at).format(
"MMMM Do YYYY"
2022-06-15 08:59:09 +02:00
),
});
const buttons = [
{
label: I18n.t("wizard.incomplete_submission.restart"),
class: "btn btn-default",
callback: () => {
wizardModel.restart();
},
},
{
label: I18n.t("wizard.incomplete_submission.resume"),
class: "btn btn-primary",
},
];
const options = {
onEscape: false,
};
bootbox.dialog(title, buttons, options);
},
afterModel(model) {
updateCachedWizard(model);
2022-03-16 12:33:34 +01: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,
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-27 12:47:50 +02:00
const background = model.get("background");
if (background) {
document.body.style.background = background;
}
},
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 = "";
},
2017-10-13 15:02:34 +02:00
});