brotherton-erpnext/erpnext/setup/page/setup_wizard/setup_wizard.js

446 lines
15 KiB
JavaScript
Raw Normal View History

2014-02-14 10:17:51 +00:00
frappe.pages['setup-wizard'].onload = function(wrapper) {
2013-10-08 12:29:11 +00:00
if(sys_defaults.company) {
2014-02-14 10:17:51 +00:00
frappe.set_route("desktop");
2013-10-08 12:29:11 +00:00
return;
}
$(".navbar:first").toggle(false);
2013-10-08 12:29:11 +00:00
$("body").css({"padding-top":"30px"});
2013-12-24 13:21:32 +00:00
var wizard_settings = {
2013-10-08 12:29:11 +00:00
page_name: "setup-wizard",
2013-10-04 12:18:05 +00:00
parent: wrapper,
2013-10-08 12:29:11 +00:00
on_complete: function(wiz) {
var values = wiz.get_values();
wiz.show_working();
2014-02-14 10:17:51 +00:00
frappe.call({
method: "erpnext.setup.page.setup_wizard.setup_wizard.setup_account",
2013-10-08 12:29:11 +00:00
args: values,
callback: function(r) {
if(r.exc) {
2014-02-14 10:17:51 +00:00
var d = msgprint(frappe._("There were errors."));
2013-10-08 12:29:11 +00:00
d.custom_onhide = function() {
2014-02-14 10:17:51 +00:00
frappe.set_route(erpnext.wiz.page_name, "0");
2013-10-08 12:29:11 +00:00
}
} else {
wiz.show_complete();
setTimeout(function() {
if(user==="Administrator") {
2014-02-14 10:17:51 +00:00
msgprint(frappe._("Login with your new User ID") + ":" + values.email);
2013-10-08 12:29:11 +00:00
setTimeout(function() {
2014-02-14 10:17:51 +00:00
frappe.app.logout();
2013-10-08 12:29:11 +00:00
}, 2000);
} else {
window.location = "/desk";
2013-10-08 12:29:11 +00:00
}
}, 2000);
}
}
})
},
2014-02-14 10:17:51 +00:00
title: frappe._("ERPNext Setup Guide"),
2013-10-08 12:29:11 +00:00
welcome_html: '<h1 class="text-muted text-center"><i class="icon-magic"></i></h1>\
2014-02-14 10:17:51 +00:00
<h2 class="text-center">'+frappe._('ERPNext Setup')+'</h2>\
2013-10-08 12:29:11 +00:00
<p class="text-center">' +
2014-02-14 10:17:51 +00:00
frappe._('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!') +
2013-10-08 12:29:11 +00:00
'</p>',
working_html: '<h3 class="text-muted text-center"><i class="icon-refresh icon-spin"></i></h3>\
2014-02-14 10:17:51 +00:00
<h2 class="text-center">'+frappe._('Setting up...')+'</h2>\
2013-10-08 12:29:11 +00:00
<p class="text-center">' +
2014-02-14 10:17:51 +00:00
frappe._('Sit tight while your system is being setup. This may take a few moments.') +
2013-10-08 12:29:11 +00:00
'</p>',
complete_html: '<h1 class="text-muted text-center"><i class="icon-thumbs-up"></i></h1>\
2014-02-14 10:17:51 +00:00
<h2 class="text-center">'+frappe._('Setup Complete!')+'</h2>\
2013-10-08 12:29:11 +00:00
<p class="text-center">' +
2014-02-14 10:17:51 +00:00
frappe._('Your setup is complete. Refreshing...') +
2013-10-08 12:29:11 +00:00
'</p>',
2013-10-04 12:18:05 +00:00
slides: [
// User
{
2014-02-14 10:17:51 +00:00
title: frappe._("The First User: You"),
icon: "icon-user",
2013-10-04 12:18:05 +00:00
fields: [
2014-02-14 10:17:51 +00:00
{"fieldname": "first_name", "label": frappe._("First Name"), "fieldtype": "Data",
2013-12-24 13:21:32 +00:00
reqd:1},
2014-02-14 10:17:51 +00:00
{"fieldname": "last_name", "label": frappe._("Last Name"), "fieldtype": "Data",
2013-12-24 13:21:32 +00:00
reqd:1},
2014-02-14 10:17:51 +00:00
{"fieldname": "email", "label": frappe._("Email Id"), "fieldtype": "Data",
2013-12-24 13:21:32 +00:00
reqd:1, "description":"Your Login Id", "options":"Email"},
2014-02-14 10:17:51 +00:00
{"fieldname": "password", "label": frappe._("Password"), "fieldtype": "Password",
2013-12-24 13:21:32 +00:00
reqd:1},
{fieldtype:"Attach Image", fieldname:"attach_profile",
label:"Attach Your Profile..."},
2013-10-04 12:18:05 +00:00
],
2014-02-14 10:17:51 +00:00
help: frappe._('The first user will become the System Manager (you can change that later).'),
2013-10-08 12:29:11 +00:00
onload: function(slide) {
if(user!=="Administrator") {
slide.form.fields_dict.password.$wrapper.toggle(false);
slide.form.fields_dict.email.$wrapper.toggle(false);
2014-02-14 10:17:51 +00:00
slide.form.fields_dict.first_name.set_input(frappe.boot.profile.first_name);
slide.form.fields_dict.last_name.set_input(frappe.boot.profile.last_name);
2013-12-24 13:21:32 +00:00
2013-10-08 12:29:11 +00:00
delete slide.form.fields_dict.email;
delete slide.form.fields_dict.password;
}
}
2013-10-04 12:18:05 +00:00
},
2013-12-24 13:21:32 +00:00
2013-10-04 12:18:05 +00:00
// Organization
{
2014-02-14 10:17:51 +00:00
title: frappe._("The Organization"),
icon: "icon-building",
2013-10-04 12:18:05 +00:00
fields: [
2014-02-14 10:17:51 +00:00
{fieldname:'company_name', label: frappe._('Company Name'), fieldtype:'Data', reqd:1,
2013-10-04 12:18:05 +00:00
placeholder: 'e.g. "My Company LLC"'},
2014-02-14 10:17:51 +00:00
{fieldname:'company_abbr', label: frappe._('Company Abbreviation'), fieldtype:'Data',
2013-10-04 12:18:05 +00:00
placeholder:'e.g. "MC"',reqd:1},
{fieldname:'fy_start_date', label:'Financial Year Start Date', fieldtype:'Date',
description:'Your financial year begins on', reqd:1},
{fieldname:'fy_end_date', label:'Financial Year End Date', fieldtype:'Date',
description:'Your financial year ends on', reqd:1},
2014-02-14 10:17:51 +00:00
{fieldname:'company_tagline', label: frappe._('What does it do?'), fieldtype:'Data',
2013-10-08 12:29:11 +00:00
placeholder:'e.g. "Build tools for builders"', reqd:1},
2013-10-04 12:18:05 +00:00
],
2014-02-14 10:17:51 +00:00
help: frappe._('The name of your company for which you are setting up this system.'),
2013-10-04 12:18:05 +00:00
onload: function(slide) {
slide.get_input("company_name").on("change", function() {
var parts = slide.get_input("company_name").val().split(" ");
var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
slide.get_input("company_abbr").val(abbr.toUpperCase());
2014-02-14 10:17:51 +00:00
}).val(frappe.boot.control_panel.company_name || "").trigger("change");
slide.get_input("fy_start_date").on("change", function() {
var year_end_date =
2014-02-14 10:17:51 +00:00
frappe.datetime.add_days(frappe.datetime.add_months(slide.get_input("fy_start_date").val(), 12), -1);
slide.get_input("fy_end_date").val(year_end_date);
});
2013-10-04 12:18:05 +00:00
}
},
2013-12-24 13:21:32 +00:00
2013-10-04 12:18:05 +00:00
// Country
{
2014-02-14 10:17:51 +00:00
title: frappe._("Country, Timezone and Currency"),
icon: "icon-flag",
2013-10-04 12:18:05 +00:00
fields: [
2014-02-14 10:17:51 +00:00
{fieldname:'country', label: frappe._('Country'), reqd:1,
2013-10-04 12:18:05 +00:00
options: "", fieldtype: 'Select'},
2014-02-14 10:17:51 +00:00
{fieldname:'currency', label: frappe._('Default Currency'), reqd:1,
2013-10-04 12:18:05 +00:00
options: "", fieldtype: 'Select'},
2014-02-14 10:17:51 +00:00
{fieldname:'timezone', label: frappe._('Time Zone'), reqd:1,
2013-10-04 12:18:05 +00:00
options: "", fieldtype: 'Select'},
],
2014-02-14 10:17:51 +00:00
help: frappe._('Select your home country and check the timezone and currency.'),
2013-10-04 12:18:05 +00:00
onload: function(slide, form) {
2014-02-14 10:17:51 +00:00
frappe.call({
method:"frappe.country_info.get_country_timezone_info",
2013-10-04 12:18:05 +00:00
callback: function(data) {
erpnext.country_info = data.message.country_info;
erpnext.all_timezones = data.message.all_timezones;
slide.get_input("country").empty()
.add_options([""].concat(keys(erpnext.country_info).sort()));
slide.get_input("currency").empty()
2014-02-14 10:17:51 +00:00
.add_options(frappe.utils.unique([""].concat($.map(erpnext.country_info,
2013-10-04 12:18:05 +00:00
function(opts, country) { return opts.currency; }))).sort());
slide.get_input("timezone").empty()
.add_options([""].concat(erpnext.all_timezones));
}
})
2013-12-24 13:21:32 +00:00
2013-10-04 12:18:05 +00:00
slide.get_input("country").on("change", function() {
var country = slide.get_input("country").val();
var $timezone = slide.get_input("timezone");
$timezone.empty();
// add country specific timezones first
if(country){
var timezone_list = erpnext.country_info[country].timezones || [];
$timezone.add_options(timezone_list.sort());
slide.get_input("currency").val(erpnext.country_info[country].currency);
}
// add all timezones at the end, so that user has the option to change it to any timezone
$timezone.add_options([""].concat(erpnext.all_timezones));
});
}
},
2013-12-24 13:21:32 +00:00
2013-10-04 12:18:05 +00:00
// Logo
{
icon: "icon-bookmark",
2014-02-14 10:17:51 +00:00
title: frappe._("Logo and Letter Heads"),
help: frappe._('Upload your letter head and logo - you can edit them later.'),
fields: [
{fieldtype:"Attach Image", fieldname:"attach_letterhead", label:"Attach Letterhead..."},
{fieldtype:"Attach Image", fieldname:"attach_logo", label:"Attach Logo..."},
],
2013-10-04 12:18:05 +00:00
},
2013-12-24 13:21:32 +00:00
2013-10-04 12:18:05 +00:00
// Taxes
{
icon: "icon-money",
2014-02-14 10:17:51 +00:00
"title": frappe._("Add Taxes"),
"help": frappe._("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."),
2013-12-24 13:21:32 +00:00
"fields": [],
},
// Customers
{
icon: "icon-group",
2014-02-14 10:17:51 +00:00
"title": frappe._("Your Customers"),
"help": frappe._("List a few of your customers. They could be organizations or individuals."),
2013-12-24 13:21:32 +00:00
"fields": [],
},
2013-12-24 13:21:32 +00:00
// Items to Sell
{
icon: "icon-barcode",
2014-02-14 10:17:51 +00:00
"title": frappe._("Your Products or Services"),
"help": frappe._("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."),
2013-12-24 13:21:32 +00:00
"fields": [],
},
// Suppliers
{
icon: "icon-group",
2014-02-14 10:17:51 +00:00
"title": frappe._("Your Suppliers"),
"help": frappe._("List a few of your suppliers. They could be organizations or individuals."),
2013-12-24 13:21:32 +00:00
"fields": [],
},
// Items to Buy
{
icon: "icon-barcode",
2014-02-14 10:17:51 +00:00
"title": frappe._("Products or Services You Buy"),
"help": frappe._("List a few products or services you buy from your suppliers or vendors. If these are same as your products, then do not add them."),
2013-12-24 13:21:32 +00:00
"fields": [],
},
2013-10-04 12:18:05 +00:00
]
2013-12-24 13:21:32 +00:00
}
// taxes
for(var i=1; i<4; i++) {
wizard_settings.slides[4].fields = wizard_settings.slides[4].fields.concat([
{fieldtype:"Data", fieldname:"tax_"+ i, label:"Tax " + 1, placeholder:"e.g. VAT"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"tax_rate_i", label:"Rate (%)", placeholder:"e.g. 5"},
{fieldtype:"Section Break"},
])
}
// customers
for(var i=1; i<6; i++) {
wizard_settings.slides[5].fields = wizard_settings.slides[5].fields.concat([
{fieldtype:"Data", fieldname:"customer_" + i, label:"Customer " + i,
placeholder:"Customer Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"customer_contact_" + i,
label:"Contact", placeholder:"Contact Name"},
{fieldtype:"Section Break"}
])
}
// products
2013-12-24 13:21:32 +00:00
for(var i=1; i<6; i++) {
wizard_settings.slides[6].fields = wizard_settings.slides[6].fields.concat([
{fieldtype:"Data", fieldname:"item_" + i, label:"Item " + i,
2013-12-24 13:21:32 +00:00
placeholder:"A Product or Service"},
{fieldtype:"Column Break"},
{fieldtype:"Attach", fieldname:"item_img_" + i, label:"Attach Image..."},
{fieldtype:"Section Break"},
{fieldtype:"Column Break"},
{fieldtype:"Select", label:"Group", fieldname:"item_group_" + i,
options:["Products", "Services", "Raw Material", "Sub Assemblies"]},
{fieldtype:"Column Break"},
{fieldtype:"Select", fieldname:"item_uom_" + i, label:"UOM",
options:["Unit", "Nos", "Box", "Pair", "Kg", "Set", "Hour", "Minute"]},
{fieldtype:"Section Break"}
])
}
for(var i=1; i<6; i++) {
wizard_settings.slides[7].fields = wizard_settings.slides[7].fields.concat([
{fieldtype:"Data", fieldname:"supplier_" + i, label:"Supplier " + i,
placeholder:"Supplier Name"},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"supplier_contact_" + i,
label:"Contact", placeholder:"Contact Name"},
{fieldtype:"Section Break"}
])
}
for(var i=1; i<6; i++) {
wizard_settings.slides[8].fields = wizard_settings.slides[8].fields.concat([
{fieldtype:"Data", fieldname:"item_buy_" + i, label:"Item " + i,
placeholder:"A Product or Service"},
{fieldtype:"Column Break"},
{fieldtype:"Section Break"},
{fieldtype:"Column Break"},
{fieldtype:"Select", fieldname:"item_buy_group_" + i, label: "Group",
options:["Raw Material", "Consumable", "Sub Assemblies", "Services", "Products"]},
{fieldtype:"Column Break"},
{fieldtype:"Select", fieldname:"item_buy_uom_" + i, label: "UOM",
options:["Unit", "Nos", "Box", "Pair", "Kg", "Set", "Hour", "Minute"]},
{fieldtype:"Section Break"},
])
}
2014-02-14 10:17:51 +00:00
erpnext.wiz = new frappe.wiz.Wizard(wizard_settings)
2013-10-04 12:18:05 +00:00
}
2014-02-14 10:17:51 +00:00
frappe.pages['setup-wizard'].onshow = function(wrapper) {
if(frappe.get_route()[1])
erpnext.wiz.show(frappe.get_route()[1]);
2013-10-04 12:18:05 +00:00
}
2014-02-14 10:17:51 +00:00
frappe.provide("frappe.wiz");
2013-10-04 12:18:05 +00:00
2014-02-14 10:17:51 +00:00
frappe.wiz.Wizard = Class.extend({
2013-10-04 12:18:05 +00:00
init: function(opts) {
$.extend(this, opts);
2013-10-08 12:29:11 +00:00
this.slides = this.slides;
2013-10-04 12:18:05 +00:00
this.slide_dict = {};
2013-10-08 12:29:11 +00:00
this.show_welcome();
},
get_message: function(html) {
return $(repl('<div class="panel panel-default">\
2013-10-08 12:29:11 +00:00
<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 +
2014-02-14 10:17:51 +00:00
'<br><p class="text-center"><button class="btn btn-primary">'+frappe._("Start")+'</button></p>')
2013-10-08 12:29:11 +00:00
.appendTo(this.parent);
this.$welcome.find(".btn").click(function() {
me.$welcome.toggle(false);
me.welcomed = true;
2014-02-14 10:17:51 +00:00
frappe.set_route(me.page_name, "0");
2013-10-08 12:29:11 +00:00
})
this.current_slide = {"$wrapper": this.$welcome};
},
show_working: function() {
this.hide_current_slide();
2014-02-14 10:17:51 +00:00
frappe.set_route(this.page_name);
2013-10-08 12:29:11 +00:00
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)};
2013-10-04 12:18:05 +00:00
},
show: function(id) {
2013-10-08 12:29:11 +00:00
if(!this.welcomed) {
2014-02-14 10:17:51 +00:00
frappe.set_route(this.page_name);
2013-10-08 12:29:11 +00:00
return;
}
2013-10-04 12:18:05 +00:00
id = cint(id);
if(this.current_slide && this.current_slide.id===id)
return;
if(!this.slide_dict[id]) {
2014-02-14 10:17:51 +00:00
this.slide_dict[id] = new frappe.wiz.WizardSlide($.extend(this.slides[id], {wiz:this, id:id}));
2013-10-04 12:18:05 +00:00
this.slide_dict[id].make();
}
2013-10-08 12:29:11 +00:00
this.hide_current_slide();
2013-10-04 12:18:05 +00:00
this.current_slide = this.slide_dict[id];
this.current_slide.$wrapper.toggle(true);
},
2013-10-08 12:29:11 +00:00
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;
}
2013-10-04 12:18:05 +00:00
});
2014-02-14 10:17:51 +00:00
frappe.wiz.WizardSlide = Class.extend({
2013-10-04 12:18:05 +00:00
init: function(opts) {
$.extend(this, opts);
},
make: function() {
var me = this;
this.$wrapper = $(repl('<div class="panel panel-default">\
2013-12-24 13:21:32 +00:00
<div class="panel-heading">\
<div class="panel-title row">\
2014-02-19 07:13:16 +00:00
<div class="col-sm-8"><h3 style="margin: 0px;">\
<i class="%(icon)s text-muted"></i> %(title)s</h3></div>\
<div class="col-sm-4 text-right"><a class="prev-btn hide btn btn-default">Previous</a> \
<a class="next-btn hide btn btn-primary">Next</a> \
<a class="complete-btn hide btn btn-primary"><b>Complete Setup</b></a>\
2013-12-24 13:21:32 +00:00
</div>\
</div>\
</div>\
2013-10-04 12:18:05 +00:00
<div class="panel-body">\
<div class="progress">\
<div class="progress-bar" style="width: %(width)s%"></div>\
</div>\
<br>\
2013-10-04 12:18:05 +00:00
<div class="row">\
<div class="col-sm-8 form"></div>\
<div class="col-sm-4 help">\
2013-10-08 12:29:11 +00:00
<p class="text-muted">%(help)s</p>\
</div>\
2013-10-04 12:18:05 +00:00
</div>\
<hr>\
<div class="footer"></div>\
</div>\
</div>', {help:this.help, title:this.title, main_title:this.wiz.title, step: this.id + 1,
width: (flt(this.id + 1) / (this.wiz.slides.length+1)) * 100, icon:this.icon}))
2013-10-04 12:18:05 +00:00
.appendTo(this.wiz.parent);
this.body = this.$wrapper.find(".form")[0];
if(this.fields) {
2014-02-14 10:17:51 +00:00
this.form = new frappe.ui.FieldGroup({
2013-10-04 12:18:05 +00:00
fields: this.fields,
body: this.body,
no_submit_on_enter: true
2013-10-04 12:18:05 +00:00
});
this.form.make();
} else {
$(this.body).html(this.html)
}
if(this.id > 0) {
2013-12-24 13:21:32 +00:00
this.$prev = this.$wrapper.find('.prev-btn').removeClass("hide")
2013-10-08 12:29:11 +00:00
.click(function() {
2014-02-14 10:17:51 +00:00
frappe.set_route(me.wiz.page_name, me.id-1 + "");
2013-10-08 12:29:11 +00:00
})
2013-12-24 13:21:32 +00:00
.css({"margin-right": "10px"});
2013-10-04 12:18:05 +00:00
}
if(this.id+1 < this.wiz.slides.length) {
2013-12-24 13:21:32 +00:00
this.$next = this.$wrapper.find('.next-btn').removeClass("hide")
2013-10-08 12:29:11 +00:00
.click(function() {
me.values = me.form.get_values();
if(me.values===null)
return;
2014-02-14 10:17:51 +00:00
frappe.set_route(me.wiz.page_name, me.id+1 + "");
2013-10-08 12:29:11 +00:00
})
2013-10-04 12:18:05 +00:00
} else {
2013-12-24 13:21:32 +00:00
this.$complete = this.$wrapper.find('.complete-btn').removeClass("hide")
2013-10-08 12:29:11 +00:00
.click(function() {
me.values = me.form.get_values();
if(me.values===null)
return;
me.wiz.on_complete(me.wiz);
2013-12-24 13:21:32 +00:00
})
2013-10-04 12:18:05 +00:00
}
if(this.onload) {
this.onload(this);
}
},
get_input: function(fn) {
return this.form.get_input(fn);
}
})