jam-cloud/web/app/assets/javascripts/wizard/loopback/loopback_wizard.js

98 lines
2.0 KiB
JavaScript

(function (context, $) {
"use strict";
context.JK = context.JK || {};
context.JK.LoopbackWizard = function (app) {
var logger = context.JK.logger;
var $dialog = null;
var wizard = null;
var $wizardSteps = null;
var step1 = new context.JK.Step1(app, this);
var step2 = new context.JK.Step2(app, this);
var step3 = new context.JK.Step3(app, this);
var STEPS = {
0: step1,
1: step2,
2: step3
}
function beforeShow(args) {
wizard.onBeforeShow(args);
}
function afterHide() {
wizard.onAfterHide();
}
function closeDialog() {
wizard.onCloseDialog();
app.layout.closeDialog('your-wizard');
}
function setNextState(enabled) {
wizard.setNextState(enabled);
}
function setBackState(enabled) {
wizard.setBackState(enabled);
}
function onStepChanged(e, data) {
var step = wizard.getCurrentStep();
var $currentWizardStep = wizard.getCurrentWizardStep();
}
function onCanceled() {
closeDialog();
return false;
}
function onClosed() {
closeDialog();
return false;
}
function events() {
$(wizard).on('step_changed', onStepChanged);
$(wizard).on('wizard_cancel', onCanceled);
$(wizard).on('wizard_close', onClosed);
}
function initialize() {
var dialogBindings = { beforeShow: beforeShow, afterHide: afterHide };
app.bindDialog('your-wizard', dialogBindings);
$dialog = $('#your-wizard');
$wizardSteps = $dialog.find('.wizard-step');
step1.initialize($wizardSteps.filter($('[layout-wizard-step=0]')));
step2.initialize($wizardSteps.filter($('[layout-wizard-step=1]')));
step3.initialize($wizardSteps.filter($('[layout-wizard-step=2]')));
wizard = new context.JK.Wizard(app);
wizard.initialize($dialog, $wizardSteps, STEPS);
events();
}
this.setNextState = setNextState;
this.setBackState = setBackState;
this.initialize = initialize;
return this;
}
})(window, jQuery);