Skip to content

Instantly share code, notes, and snippets.

@eggsurplus
Created February 27, 2014 16:39
Show Gist options
  • Select an option

  • Save eggsurplus/9253799 to your computer and use it in GitHub Desktop.

Select an option

Save eggsurplus/9253799 to your computer and use it in GitHub Desktop.
Basic step wizard
({
className: 'sugarchimp-setup',
currentStep: 1,
events:
{
'click .nextStep':'nextStep',
'click .previousStep':'previousStep'
},
initialize: function(opts) {
Handlebars.registerPartial('setup.header', app.template.get('setup.header.SugarChimp'));
Handlebars.registerPartial('setup.footer', app.template.get('setup.footer.SugarChimp'));
app.view.View.prototype.initialize.call(this, opts);
this.setStep(1);
},
_render: function () {
app.view.View.prototype._render.call(this);
//update top status bar for current step
$('#sugarchimp-setup-status').html(this.steps[this.currentStep].message);
return this;
},
setStep: function(step) {
this.currentStep = step;
this.template = app.template.getView('setup.step'+this.currentStep, 'SugarChimp');
if (!this.template) {
//just in case the .hbs doesn't exist
app.error.handleRenderError(this, 'view_render_denied');
}
},
previousStep: function(){
if (this.isFirstStep()) return;
this.setStep(this.currentStep - 1);
this.render();
},
nextStep: function(){
if (this.isLastStep()) return;
this.setStep(this.currentStep + 1);
this.render();
},
isFirstStep: function() {
return (this.currentStep <= 1);
},
isLastStep: function() {
return (this.currentStep == Object.keys(this.steps).length);
},
steps: {
1 : {
message : "Welcome to SugarChimp! Let's get started below..."
},
2 : {
message : "Next up...setting up your..."
},
3 : {
message : "All done!"
},
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment