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

498 lines
16 KiB
JavaScript
Raw Normal View History

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) {
wiz.show_complete();
setTimeout(function() {
if(user==="Administrator") {
msgprint(__("Login with your new User ID") + ": " + values.email);
setTimeout(function() {
frappe.app.logout();
}, 2000);
} else {
window.location = "/desk";
2013-10-08 12:29:11 +00:00
}
}, 2000);
},
error: function(r) {
var d = msgprint(__("There were errors."));
d.custom_onhide = function() {
frappe.set_route(erpnext.wiz.page_name, "0");
};
2013-10-08 12:29:11 +00:00
}
})
},
title: __("Welcome"),
working_html: function() { return '<h3 class="text-muted text-center"><i class="icon-refresh icon-spin"></i></h3>\
2014-04-14 10:55:30 +00:00
<h2 class="text-center">'+__('Setting up...')+'</h2>\
<p class="text-center">' +
__('Sit tight while your system is being setup. This may take a few moments.') +
'</p>' },
2015-01-19 12:04:33 +00:00
complete_html: function() { return '<h1 class="text-muted text-center"></h1>\
2014-04-21 06:12:22 +00:00
<h2 class="text-center">'+__('Setup Complete')+'</h2>\
<p class="text-center">' +
__('Your setup is complete. Refreshing...') +
'</p>'},
2013-10-04 12:18:05 +00:00
slides: [
// User
{
title: __("Select Your Language"),
icon: "icon-globe",
fields: [
{
"fieldname": "language", "label": __("Language"), "fieldtype": "Select",
reqd:1
},
],
2015-01-15 06:36:42 +00:00
help: "",
onload: function(slide) {
var me = this;
2015-01-15 06:36:42 +00:00
var select = slide.get_field("language");
if (!this.language_list) {
frappe.call({
method: "erpnext.setup.page.setup_wizard.setup_wizard.load_languages",
callback: function(r) {
me.language_list = r.message;
2015-01-15 06:36:42 +00:00
select.df.options = me.language_list;
select.set_input("english");
}
})
} else {
2015-01-15 06:36:42 +00:00
select.df.options = this.language_list;
select.refresh();
}
slide.get_input("language").on("change", function() {
var lang = $(this).val() || "english";
frappe._messages = {};
frappe.call({
method: "erpnext.setup.page.setup_wizard.setup_wizard.load_messages",
args: {
language: lang
},
callback: function(r) {
// re-render all slides
$.each(slide.wiz.slide_dict, function(key, s) {
s.make();
});
2015-01-15 06:36:42 +00:00
// select is re-made after language change
var select = slide.get_field("language");
select.set_input(lang);
}
})
});
}
},
2013-10-04 12:18:05 +00:00
{
2014-04-14 10:55:30 +00:00
title: __("The First User: You"),
icon: "icon-user",
2013-10-04 12:18:05 +00:00
fields: [
{"fieldname": "first_name", "label": __("First Name"), "fieldtype": "Data",
2013-12-24 13:21:32 +00:00
reqd:1},
{"fieldname": "last_name", "label": __("Last Name"), "fieldtype": "Data",
2013-12-24 13:21:32 +00:00
reqd:1},
{"fieldname": "email", "label": __("Email Id"), "fieldtype": "Data",
2014-05-13 15:32:47 +00:00
reqd:1, "description": __("Your Login Id"), "options":"Email"},
{"fieldname": "password", "label": __("Password"), "fieldtype": "Password",
2013-12-24 13:21:32 +00:00
reqd:1},
{fieldtype:"Attach Image", fieldname:"attach_user",
label: __("Attach Your Picture")},
2013-10-04 12:18:05 +00:00
],
2014-04-14 10:55:30 +00:00
help: __('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);
slide.form.fields_dict.first_name.set_input(frappe.boot.user.first_name);
slide.form.fields_dict.last_name.set_input(frappe.boot.user.last_name);
2014-04-22 10:00:05 +00:00
var user_image = frappe.get_cookie("user_image");
if(user_image) {
var $attach_user = slide.form.fields_dict.attach_user.$wrapper;
$attach_user.find(".missing-image").toggle(false);
$attach_user.find("img").attr("src", user_image).toggle(true);
}
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-10-04 12:18:05 +00:00
// Country
{
2014-04-14 10:55:30 +00:00
title: __("Country, Timezone and Currency"),
icon: "icon-flag",
2013-10-04 12:18:05 +00:00
fields: [
2014-04-14 10:55:30 +00:00
{fieldname:'country', label: __('Country'), reqd:1,
2013-10-04 12:18:05 +00:00
options: "", fieldtype: 'Select'},
2014-04-14 10:55:30 +00:00
{fieldname:'currency', label: __('Default Currency'), reqd:1,
2013-10-04 12:18:05 +00:00
options: "", fieldtype: 'Select'},
2014-04-14 10:55:30 +00:00
{fieldname:'timezone', label: __('Time Zone'), reqd:1,
2013-10-04 12:18:05 +00:00
options: "", fieldtype: 'Select'},
2014-09-16 05:38:08 +00:00
{fieldname:'chart_of_accounts', label: __('Chart of Accounts'),
options: "", fieldtype: 'Select'}
2013-10-04 12:18:05 +00:00
],
2014-04-14 10:55:30 +00:00
help: __('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({
2014-10-22 10:44:41 +00:00
method:"frappe.geo.country_info.get_country_timezone_info",
2013-10-04 12:18:05 +00:00
callback: function(data) {
frappe.country_info = data.message.country_info;
frappe.all_timezones = data.message.all_timezones;
2013-10-04 12:18:05 +00:00
slide.get_input("country").empty()
.add_options([""].concat(keys(frappe.country_info).sort()));
2013-10-04 12:18:05 +00:00
slide.get_input("currency").empty()
.add_options(frappe.utils.unique([""].concat($.map(frappe.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(frappe.all_timezones));
2013-10-04 12:18:05 +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 = frappe.country_info[country].timezones || [];
2013-10-04 12:18:05 +00:00
$timezone.add_options(timezone_list.sort());
2015-01-15 06:36:42 +00:00
slide.get_field("currency").set_input(frappe.country_info[country].currency);
2013-10-04 12:18:05 +00:00
}
// add all timezones at the end, so that user has the option to change it to any timezone
$timezone.add_options([""].concat(frappe.all_timezones));
2015-01-15 06:36:42 +00:00
slide.get_field("timezone").set_input($timezone.val());
// temporarily set date format
frappe.boot.sysdefaults.date_format = (frappe.country_info[country].date_format
|| "dd-mm-yyyy");
// get country specific chart of accounts
frappe.call({
method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
args: {"country": country},
callback: function(r) {
if(r.message)
slide.get_input("chart_of_accounts").empty()
.add_options([""].concat(r.message));
}
})
2013-10-04 12:18:05 +00:00
});
}
},
// Organization
{
title: __("The Organization"),
icon: "icon-building",
fields: [
{fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
placeholder: __('e.g. "My Company LLC"')},
{fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
2014-05-21 07:09:37 +00:00
description: __('Max 5 characters'), placeholder: __('e.g. "MC"'), reqd:1},
2015-01-19 12:04:33 +00:00
{fieldname:'bank_account', label: __('Bank Account'), fieldtype:'Data',
placeholder: __('e.g. "XYZ National Bank"'), 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},
{fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
placeholder:__('e.g. "Build tools for builders"'), reqd:1},
],
help: __('The name of your company for which you are setting up this system.'),
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("");
2015-01-15 06:36:42 +00:00
slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
}).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
slide.get_input("company_abbr").on("change", function() {
if(slide.get_input("company_abbr").val().length > 5) {
msgprint("Company Abbreviation cannot have more than 5 characters");
2015-01-15 06:36:42 +00:00
slide.get_field("company_abbr").set_input("");
}
});
slide.get_input("fy_start_date").on("change", function() {
var year_end_date =
frappe.datetime.add_days(frappe.datetime.add_months(
frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
2015-01-19 12:04:33 +00:00
slide.get_field("fy_end_date").set_input(year_end_date);
});
}
},
2013-10-04 12:18:05 +00:00
// Logo
{
icon: "icon-bookmark",
2014-04-14 10:55:30 +00:00
title: __("Logo and Letter Heads"),
help: __('Upload your letter head and logo - you can edit them later.'),
fields: [
{fieldtype:"Attach Image", fieldname:"attach_letterhead",
label: __("Attach Letterhead"),
description: __("Keep it web friendly 900px (w) by 100px (h)")
},
{fieldtype:"Attach Image", fieldname:"attach_logo",
label:__("Attach Logo"),
description: __("100px by 100px")},
],
2013-10-04 12:18:05 +00:00
},
2013-10-04 12:18:05 +00:00
// Taxes
{
icon: "icon-money",
2014-04-14 10:55:30 +00:00
"title": __("Add Taxes"),
"help": __("List your tax heads (e.g. VAT, Excise; they should have unique names) and their standard rates. This will create a standard template, which you can edit and add more later."),
2013-12-24 13:21:32 +00:00
"fields": [],
2014-04-21 06:12:22 +00:00
before_load: function(slide) {
slide.fields = [];
2014-04-21 06:12:22 +00:00
for(var i=1; i<4; i++) {
slide.fields = slide.fields.concat([
{fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
placeholder:__("e.g. VAT") + " " + i},
2014-04-21 06:12:22 +00:00
{fieldtype:"Column Break"},
{fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
2014-04-21 06:12:22 +00:00
{fieldtype:"Section Break"},
]);
}
}
},
// Customers
{
icon: "icon-group",
2014-04-14 10:55:30 +00:00
"title": __("Your Customers"),
"help": __("List a few of your customers. They could be organizations or individuals."),
2013-12-24 13:21:32 +00:00
"fields": [],
2014-04-21 06:12:22 +00:00
before_load: function(slide) {
slide.fields = [];
2014-04-21 06:12:22 +00:00
for(var i=1; i<6; i++) {
slide.fields = slide.fields.concat([
{fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
placeholder:__("Customer Name")},
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"customer_contact_" + i,
label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
2014-04-21 06:12:22 +00:00
{fieldtype:"Section Break"}
])
}
}
},
// Suppliers
{
icon: "icon-group",
2014-04-14 10:55:30 +00:00
"title": __("Your Suppliers"),
"help": __("List a few of your suppliers. They could be organizations or individuals."),
2013-12-24 13:21:32 +00:00
"fields": [],
2014-04-21 06:12:22 +00:00
before_load: function(slide) {
slide.fields = [];
2014-04-21 06:12:22 +00:00
for(var i=1; i<6; i++) {
slide.fields = slide.fields.concat([
{fieldtype:"Data", fieldname:"supplier_" + i, label:__("Supplier")+" " + i,
placeholder:__("Supplier Name")},
2014-04-21 06:12:22 +00:00
{fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"supplier_contact_" + i,
label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
2014-04-21 06:12:22 +00:00
{fieldtype:"Section Break"}
])
}
}
},
// Items to Sell
{
icon: "icon-barcode",
"title": __("Your Products or Services"),
"help": __("List your products or services that you buy or sell. 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": [],
2014-04-21 06:12:22 +00:00
before_load: function(slide) {
slide.fields = [];
2014-04-21 06:12:22 +00:00
for(var i=1; i<6; i++) {
slide.fields = slide.fields.concat([
{fieldtype:"Section Break", show_section_border: true},
{fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
2014-04-21 06:12:22 +00:00
placeholder:__("A Product or Service")},
{fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item")},
{fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
2014-04-21 06:12:22 +00:00
{fieldtype:"Column Break"},
{fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
options:[__("Products"), __("Services"),
__("Raw Material"), __("Consumable"), __("Sub Assemblies")]},
{fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
__("Hour"), __("Minute")]},
{fieldtype:"Attach", fieldname:"item_img_" + i, label:__("Attach Image")},
2014-04-21 06:12:22 +00:00
])
}
}
},
2013-10-04 12:18:05 +00:00
]
2013-12-24 13:21:32 +00:00
}
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);
this.make();
2013-10-08 12:29:11 +00:00
this.slides = this.slides;
2013-10-04 12:18:05 +00:00
this.slide_dict = {};
this.welcomed = true;
frappe.set_route(this.page_name, "0");
},
make: function() {
this.parent = $('<div class="setup-wizard-wrapper">').appendTo(this.parent);
2013-10-08 12:29:11 +00:00
},
get_message: function(html) {
2015-01-19 12:04:33 +00:00
return $(repl('<div data-state="setup-complete">\
<div style="padding: 40px;" class="text-center">%(html)s</div>\
2013-10-08 12:29:11 +00:00
</div>', {html:html}))
},
show_working: function() {
this.hide_current_slide();
2014-02-14 10:17:51 +00:00
frappe.set_route(this.page_name);
this.current_slide = {"$wrapper": this.get_message(this.working_html()).appendTo(this.parent)};
2013-10-08 12:29:11 +00:00
},
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)
2013-10-04 12:18:05 +00:00
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);
2014-05-03 10:52:25 +00:00
this.$wrapper = $("<div>")
.appendTo(this.wiz.parent)
.attr("data-slide-id", this.id);
2013-10-04 12:18:05 +00:00
},
make: function() {
var me = this;
if(this.$body) this.$body.remove();
2014-04-21 06:12:22 +00:00
if(this.before_load) {
this.before_load(this);
}
2015-01-15 06:36:42 +00:00
this.$body = $(frappe.render_template("setup_wizard_page",
{help: __(this.help), title:__(this.title), main_title:__(this.wiz.title), step: this.id + 1 }))
.appendTo(this.$wrapper);
this.body = this.$body.find(".form")[0];
2013-10-04 12:18:05 +00:00
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)
}
2013-10-04 12:18:05 +00:00
if(this.id > 0) {
this.$prev = this.$body.find('.prev-btn').removeClass("hide")
.click(function() {
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) {
this.$next = this.$body.find('.next-btn').removeClass("hide")
.click(function() {
2013-10-08 12:29:11 +00:00
me.values = me.form.get_values();
if(me.values===null)
2013-10-08 12:29:11 +00:00
return;
if(me.validate && !me.validate())
return;
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 {
this.$complete = this.$body.find('.complete-btn').removeClass("hide")
.click(function() {
2013-10-08 12:29:11 +00:00
me.values = me.form.get_values();
if(me.values===null)
2013-10-08 12:29:11 +00:00
return;
if(me.validate && !me.validate())
return;
me.wiz.on_complete(me.wiz);
2013-12-24 13:21:32 +00:00
})
2013-10-04 12:18:05 +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);
2015-01-15 06:36:42 +00:00
},
get_field: function(fn) {
return this.form.get_field(fn);
2013-10-04 12:18:05 +00:00
}
})