0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-30 04:30:29 +01:00
discourse-custom-wizard/assets/javascripts/wizard/routes/custom.js.es6
Faizaan Gagan 2678ee153d
FEATURE: add resume wizard popup (#146)
* FEATURE: add resume wizard popup

* code cleanup, copy edits

* FIX: address functionality, setting and copy issues

@fzngagan a few issues fixed

1. The resume button wasn't working (old reference to ``resumeDialog`` remained in callback.
2. This needs a wizard setting
3. It's not necessary to serialize the first step separately. We have all the steps in ``steps`` and steps have indexes.
4. Button copy

* Fix linting

* Ensure aa submission exists

* Apply prettier

Co-authored-by: angusmcleod <angus@mcleod.org.au>
2021-09-22 13:52:05 +05:30

84 Zeilen
2 KiB
JavaScript

/* eslint no-undef: 0*/
import { findCustomWizard, updateCachedWizard } from "../models/custom";
import { ajax } from "wizard/lib/ajax";
import WizardI18n from "../lib/wizard-i18n";
export default Ember.Route.extend({
beforeModel(transition) {
this.set("queryParams", transition.intent.queryParams);
},
model(params) {
return findCustomWizard(params.wizard_id, this.get("queryParams"));
},
renderTemplate() {
this.render("custom");
const wizardModel = this.modelFor("custom");
const stepModel = this.modelFor("custom.step");
if (
wizardModel.resume_on_revisit &&
wizardModel.submission_last_updated_at &&
stepModel.index > 0
) {
this.showDialog(wizardModel);
}
},
showDialog(wizardModel) {
const title = WizardI18n("wizard.incomplete_submission.title", {
date: moment(wizardModel.submission_last_updated_at).format(
"MMMM Do YYYY"
),
});
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);
},
afterModel(model) {
updateCachedWizard(model);
return ajax({
url: `/site/settings`,
type: "GET",
}).then((result) => {
$.extend(Wizard.SiteSettings, result);
});
},
setupController(controller, model) {
const background = model ? model.get("background") : "AliceBlue";
Ember.run.scheduleOnce("afterRender", this, function () {
$("body.custom-wizard").css("background", background);
if (model && model.id) {
$("#custom-wizard-main").addClass(model.id.dasherize());
}
});
controller.setProperties({
customWizard: true,
logoUrl: Wizard.SiteSettings.logo_small,
reset: null,
});
},
});