2022-03-16 12:33:34 +01:00
|
|
|
import { findCustomWizard, updateCachedWizard } from "../models/wizard";
|
2021-09-22 10:22:05 +02:00
|
|
|
import WizardI18n from "../lib/wizard-i18n";
|
2022-03-16 12:33:34 +01:00
|
|
|
import Route from "@ember/routing/route";
|
|
|
|
import { scheduleOnce } from "@ember/runloop";
|
|
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
2017-10-13 15:02:34 +02:00
|
|
|
|
2022-03-16 12:33:34 +01:00
|
|
|
export default Route.extend({
|
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) {
|
|
|
|
const title = WizardI18n("wizard.incomplete_submission.title", {
|
|
|
|
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 = [
|
|
|
|
{
|
|
|
|
label: WizardI18n("wizard.incomplete_submission.restart"),
|
|
|
|
class: "btn btn-default",
|
|
|
|
callback: () => {
|
|
|
|
wizardModel.restart();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: WizardI18n("wizard.incomplete_submission.resume"),
|
|
|
|
class: "btn btn-primary",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
onEscape: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
bootbox.dialog(title, buttons, options);
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
2022-03-16 12:33:34 +01:00
|
|
|
renderTemplate() {
|
2022-06-15 08:59:09 +02:00
|
|
|
this.render("wizard/templates/wizard");
|
2017-10-13 15:02:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
2022-03-16 12:33:34 +01:00
|
|
|
const background = model ? model.get("background") : "";
|
|
|
|
|
|
|
|
scheduleOnce("afterRender", this, function () {
|
|
|
|
$("body").css("background", background);
|
2021-04-20 19:58:19 +02:00
|
|
|
|
|
|
|
if (model && model.id) {
|
2022-03-16 12:33:34 +01:00
|
|
|
$(getOwner(this).rootElement).addClass(model.id.dasherize());
|
2017-12-03 08:57:40 +01:00
|
|
|
}
|
2017-10-13 15:02:34 +02:00
|
|
|
});
|
2022-03-16 12:33:34 +01:00
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
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,
|
2017-10-13 15:02:34 +02:00
|
|
|
});
|
2022-03-16 12:33:34 +01:00
|
|
|
|
|
|
|
const stepModel = this.modelFor("step");
|
|
|
|
if (
|
|
|
|
model.resume_on_revisit &&
|
|
|
|
model.submission_last_updated_at &&
|
|
|
|
stepModel.index > 0
|
|
|
|
) {
|
|
|
|
this.showDialog(model);
|
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2017-10-13 15:02:34 +02:00
|
|
|
});
|