New Setup Wizard

This commit is contained in:
Rushabh Mehta
2013-10-08 17:59:11 +05:30
parent 8941841a9c
commit 8c5a5f1ed5
16 changed files with 589 additions and 484 deletions

View File

@@ -1,9 +1,59 @@
wn.pages['setup-wizard'].onload = function(wrapper) {
if(sys_defaults.company) {
wn.set_route("desktop");
return;
}
$(".navbar:first").toggle(false);
$("body").css({"padding-top":"30px"});
erpnext.wiz = new wn.wiz.Wizard({
page_name: "setup-wizard",
parent: wrapper,
on_complete: function(wiz) {
var values = wiz.get_values();
wiz.show_working();
console.log(values);
wn.call({
method: "setup.page.setup_wizard.setup_wizard.setup_account",
args: values,
callback: function(r) {
if(r.exc) {
var d = msgprint(wn._("There were errors."));
d.custom_onhide = function() {
wn.set_route(me.wiz.page_name, "0");
}
} else {
wiz.show_complete();
setTimeout(function() {
if(user==="Administrator") {
wn.msgprint(wn._("Login with your new User ID") + ":" + values.email);
setTimeout(function() {
wn.app.logout();
}, 2000);
} else {
window.location = "app.html";
}
}, 2000);
}
}
})
},
title: wn._("ERPNext Setup Guide"),
welcome_html: '<h1 class="text-muted text-center"><i class="icon-magic"></i></h1>\
<h2 class="text-center">'+wn._('ERPNext Setup')+'</h2>\
<p class="text-center">' +
wn._('Welcome to ERPNext. Over the next few minutes we will help you setup your ERPNext account. Try and fill in as much information as you have even if it takes a bit longer. It will save you a lot of time later. Good Luck!') +
'</p>',
working_html: '<h3 class="text-muted text-center"><i class="icon-refresh icon-spin"></i></h3>\
<h2 class="text-center">'+wn._('Setting up...')+'</h2>\
<p class="text-center">' +
wn._('Sit tight while your system is being setup. This may take a few moments.') +
'</p>',
complete_html: '<h1 class="text-muted text-center"><i class="icon-thumbs-up"></i></h1>\
<h2 class="text-center">'+wn._('Setup Complete!')+'</h2>\
<p class="text-center">' +
wn._('Your setup is complete. Refreshing...') +
'</p>',
slides: [
// User
{
@@ -12,9 +62,19 @@ wn.pages['setup-wizard'].onload = function(wrapper) {
fields: [
{"fieldname": "first_name", "label": wn._("First Name"), "fieldtype": "Data", reqd:1},
{"fieldname": "last_name", "label": wn._("Last Name"), "fieldtype": "Data", reqd:1},
{"email_id": "email", "label": wn._("Email Id"), "fieldtype": "Data", reqd:1, "description":"Your Login Id"},
{"password": "password", "label": wn._("Password"), "fieldtype": "Password", reqd:1},
{fieldtype:"Attach Image", fieldname:"attach_profile", label:"Attach Your Profile..."},
],
help: wn._('The first user will become the System Manager (you can change that later).')
help: wn._('The first user will become the System Manager (you can change that later).'),
onload: function(slide) {
if(user!=="Administrator") {
slide.form.fields_dict.password.$wrapper.toggle(false);
slide.form.fields_dict.email_id.$wrapper.toggle(false);
delete slide.form.fields_dict.email;
delete slide.form.fields_dict.password;
}
}
},
// Organization
@@ -26,8 +86,11 @@ wn.pages['setup-wizard'].onload = function(wrapper) {
placeholder: 'e.g. "My Company LLC"'},
{fieldname:'company_abbr', label: wn._('Company Abbreviation'), fieldtype:'Data',
placeholder:'e.g. "MC"',reqd:1},
{fieldname:'fy_start', label:'Financial Year Start Date', fieldtype:'Select',
description:'Your financial year begins on', reqd:1,
options: ['', '1st Jan', '1st Apr', '1st Jul', '1st Oct'] },
{fieldname:'company_tagline', label: wn._('What does it do?'), fieldtype:'Data',
placeholder:'e.g. "Build tools for builders"',reqd:1},
placeholder:'e.g. "Build tools for builders"', reqd:1},
],
help: wn._('The name of your company for which you are setting up this system.'),
onload: function(slide) {
@@ -94,24 +157,6 @@ wn.pages['setup-wizard'].onload = function(wrapper) {
{fieldtype:"Attach Image", fieldname:"attach_letterhead", label:"Attach Letterhead..."},
{fieldtype:"Attach Image", fieldname:"attach_logo", label:"Attach Logo..."},
],
// html: '<h4>' + wn._('Upload Logo') + '</h4><div class="upload-area-letter-head"></div><hr>'
// +'<h4>' + wn._('Upload Letter Head') + '</h4><div class="upload-area-logo"></div>',
onload: function(slide) {
// wn.upload.make({
// parent: slide.$wrapper.find(".upload-area-letter-head").css({"margin-left": "10px"}),
// on_attach: function(fileobj) {
// console.log(fileobj);
// }
// });
//
// wn.upload.make({
// parent: slide.$wrapper.find(".upload-area-logo").css({"margin-left": "10px"}),
// on_attach: function(fileobj) {
// console.log(fileobj);
// }
// });
}
},
// Taxes
@@ -120,39 +165,46 @@ wn.pages['setup-wizard'].onload = function(wrapper) {
"title": wn._("Add Taxes"),
"help": wn._("List your tax heads (e.g. VAT, Excise) (upto 3) and their standard rates. This will create a standard template, you can edit and add more later."),
"fields": [
{fieldtype:"Column Break", fieldname:"cb_1", "label": "Tax Heads"},
{fieldtype:"Data", fieldname:"tax_1", label:"Tax 1", placeholder:"e.g. VAT"},
{fieldtype:"Data", fieldname:"tax_2", label:"Tax 2", placeholder:"e.g. Customs Duty"},
{fieldtype:"Data", fieldname:"tax_3", label:"Tax 3", placeholder:"e.g. Excise"},
{fieldtype:"Column Break", fieldname:"cb_2", "label": "Tax Rates"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"tax_rate_1", label:"Rate (%)", placeholder:"e.g. 5"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"tax_2", label:"Tax 2", placeholder:"e.g. Customs Duty"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"tax_rate_2", label:"Rate (%)", placeholder:"e.g. 5"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"tax_3", label:"Tax 3", placeholder:"e.g. Excise"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"tax_rate_3", label:"Rate (%)", placeholder:"e.g. 5"},
],
onload: function(slide) {
}
},
// Items to Sell
{
icon: "icon-barcode",
"title": wn._("Your Products or Services"),
"help": wn._("List your products or services that you sell to your customers."),
"help": wn._("List your products or services that you sell to your customers. Make sure to check the Item Group, Unit of Measure and other properties when you start."),
"fields": [
{fieldtype:"Data", fieldname:"item_1", label:"Item 1", placeholder:"A Product or Service"},
{fieldtype:"Data", fieldname:"item_2", label:"Item 2", placeholder:"A Product or Service"},
{fieldtype:"Data", fieldname:"item_3", label:"Item 3", placeholder:"A Product or Service"},
{fieldtype:"Data", fieldname:"item_4", label:"Item 4", placeholder:"A Product or Service"},
{fieldtype:"Data", fieldname:"item_5", label:"Item 5", placeholder:"A Product or Service"},
{fieldtype:"Column Break", fieldname:"cb_2", "label": "Attachments"},
{fieldtype:"Column Break"},
{fieldtype:"Attach", fieldname:"item_img_1", label:"Attach Image..."},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"item_2", label:"Item 2", placeholder:"A Product or Service"},
{fieldtype:"Column Break"},
{fieldtype:"Attach", fieldname:"item_img_2", label:"Attach Image..."},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"item_3", label:"Item 3", placeholder:"A Product or Service"},
{fieldtype:"Column Break"},
{fieldtype:"Attach", fieldname:"item_img_3", label:"Attach Image..."},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"item_4", label:"Item 4", placeholder:"A Product or Service"},
{fieldtype:"Column Break"},
{fieldtype:"Attach", fieldname:"item_img_4", label:"Attach Image..."},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"item_5", label:"Item 5", placeholder:"A Product or Service"},
{fieldtype:"Column Break"},
{fieldtype:"Attach", fieldname:"item_img_5", label:"Attach Image..."},
],
onload: function(slide) {
}
},
// Items to Buy
@@ -167,8 +219,6 @@ wn.pages['setup-wizard'].onload = function(wrapper) {
{fieldtype:"Data", fieldname:"item_buy_4", label:"Item 4", placeholder:"A Product or Service"},
{fieldtype:"Data", fieldname:"item_buy_5", label:"Item 5", placeholder:"A Product or Service"},
],
onload: function(slide) {
}
},
// Customers
@@ -178,13 +228,25 @@ wn.pages['setup-wizard'].onload = function(wrapper) {
"help": wn._("List a few of your customers. They could be organizations or individuals."),
"fields": [
{fieldtype:"Data", fieldname:"customer_1", label:"Customer 1", placeholder:"Customer Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"customer_contact_1", label:"", placeholder:"Contact Name"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"customer_2", label:"Customer 2", placeholder:"Customer Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"customer_contact_2", label:"", placeholder:"Contact Name"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"customer_3", label:"Customer 3", placeholder:"Customer Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"customer_contact_3", label:"", placeholder:"Contact Name"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"customer_4", label:"Customer 4", placeholder:"Customer Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"customer_contact_4", label:"", placeholder:"Contact Name"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"customer_5", label:"Customer 5", placeholder:"Customer Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"customer_contact_5", label:"", placeholder:"Contact Name"},
],
onload: function(slide) {
}
},
// Suppliers
@@ -194,13 +256,25 @@ wn.pages['setup-wizard'].onload = function(wrapper) {
"help": wn._("List a few of your suppliers. They could be organizations or individuals."),
"fields": [
{fieldtype:"Data", fieldname:"supplier_1", label:"Supplier 1", placeholder:"Supplier Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"supplier_contact_1", label:"", placeholder:"Contact Name"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"supplier_2", label:"Supplier 2", placeholder:"Supplier Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"supplier_contact_2", label:"", placeholder:"Contact Name"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"supplier_3", label:"Supplier 3", placeholder:"Supplier Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"supplier_contact_3", label:"", placeholder:"Contact Name"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"supplier_4", label:"Supplier 4", placeholder:"Supplier Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"supplier_contact_4", label:"", placeholder:"Contact Name"},
{fieldtype:"Section Break"},
{fieldtype:"Data", fieldname:"supplier_5", label:"Supplier 5", placeholder:"Supplier Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"supplier_contact_5", label:"", placeholder:"Contact Name"},
],
onload: function(slide) {
}
}
]
@@ -209,7 +283,8 @@ wn.pages['setup-wizard'].onload = function(wrapper) {
}
wn.pages['setup-wizard'].onshow = function(wrapper) {
erpnext.wiz.show(wn.get_route()[1] || "0");
if(wn.get_route()[1])
erpnext.wiz.show(wn.get_route()[1]);
}
wn.provide("wn.wiz");
@@ -217,10 +292,45 @@ wn.provide("wn.wiz");
wn.wiz.Wizard = Class.extend({
init: function(opts) {
$.extend(this, opts);
this.slides = this.slides;
this.slide_dict = {};
wn.set_route("setup-wizard", "0");
this.show_welcome();
},
get_message: function(html) {
return $(repl('<div class="panel panel-default" style="max-width: 400px; margin: auto;">\
<div class="panel-body" style="padding: 40px;">%(html)s</div>\
</div>', {html:html}))
},
show_welcome: function() {
if(this.$welcome)
return;
var me = this;
this.$welcome = this.get_message(this.welcome_html +
'<br><p class="text-center"><button class="btn btn-primary">'+wn._("Start")+'</button></p>')
.appendTo(this.parent);
this.$welcome.find(".btn").click(function() {
me.$welcome.toggle(false);
me.welcomed = true;
wn.set_route(me.page_name, "0");
})
this.current_slide = {"$wrapper": this.$welcome};
},
show_working: function() {
this.hide_current_slide();
wn.set_route(this.page_name);
this.current_slide = {"$wrapper": this.get_message(this.working_html).appendTo(this.parent)};
},
show_complete: function() {
this.hide_current_slide();
this.current_slide = {"$wrapper": this.get_message(this.complete_html).appendTo(this.parent)};
},
show: function(id) {
if(!this.welcomed) {
wn.set_route(this.wiz.page_name);
return;
}
id = cint(id);
if(this.current_slide && this.current_slide.id===id)
return;
@@ -229,12 +339,24 @@ wn.wiz.Wizard = Class.extend({
this.slide_dict[id].make();
}
if(this.current_slide)
this.current_slide.$wrapper.toggle(false);
this.hide_current_slide();
this.current_slide = this.slide_dict[id];
this.current_slide.$wrapper.toggle(true);
},
hide_current_slide: function() {
if(this.current_slide) {
this.current_slide.$wrapper.toggle(false);
this.current_slide = null;
}
},
get_values: function() {
var values = {};
$.each(this.slide_dict, function(id, slide) {
$.extend(values, slide.values)
})
return values;
}
});
wn.wiz.WizardSlide = Class.extend({
@@ -249,10 +371,12 @@ wn.wiz.WizardSlide = Class.extend({
<div class="progress">\
<div class="progress-bar" style="width: %(width)s%"></div>\
</div>\
<h3><i class="%(icon)s text-muted"></i> %(title)s</h3><br>\
<div class="row">\
<div class="col-sm-6 form"></div>\
<div class="col-sm-6 help"><p class="text-muted">%(help)s</p></div>\
<div class="col-sm-6 help">\
<h3><i class="%(icon)s text-muted"></i> %(title)s</h3><br>\
<p class="text-muted">%(help)s</p>\
</div>\
</div>\
<hr>\
<div class="footer"></div>\
@@ -276,17 +400,29 @@ wn.wiz.WizardSlide = Class.extend({
if(this.id > 0) {
this.$prev = $("<button class='btn btn-default'>Previous</button>")
.click(function() { wn.set_route("setup-wizard", me.id-1 + ""); })
.click(function() {
wn.set_route(me.wiz.page_name, me.id-1 + "");
})
.appendTo(this.$wrapper.find(".footer"))
.css({"margin-right": "5px"});
}
if(this.id+1 < this.wiz.slides.length) {
this.$next = $("<button class='btn btn-primary'>Next</button>")
.click(function() { wn.set_route("setup-wizard", me.id+1 + ""); })
.click(function() {
me.values = me.form.get_values();
if(me.values===null)
return;
wn.set_route(me.wiz.page_name, me.id+1 + "");
})
.appendTo(this.$wrapper.find(".footer"));
} else {
this.$complete = $("<button class='btn btn-primary'>Complete Setup</button>")
.click(function() { me.wiz.complete(); }).appendTo(this.$wrapper.find(".footer"));
.click(function() {
me.values = me.form.get_values();
if(me.values===null)
return;
me.wiz.on_complete(me.wiz);
}).appendTo(this.$wrapper.find(".footer"));
}
if(this.onload) {