2015-01-29 12:39:11 +00:00
frappe . pages [ 'setup-wizard' ] . on _page _load = 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 ;
}
2013-10-07 12:52:29 +00:00
$ ( ".navbar:first" ) . toggle ( false ) ;
2013-10-08 12:29:11 +00:00
$ ( "body" ) . css ( { "padding-top" : "30px" } ) ;
2014-04-17 13:18:59 +00:00
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 ( {
2013-12-12 13:42:19 +00:00
method : "erpnext.setup.page.setup_wizard.setup_wizard.setup_account" ,
2013-10-08 12:29:11 +00:00
args : values ,
callback : function ( r ) {
2014-04-17 13:18:59 +00:00
wiz . show _complete ( ) ;
setTimeout ( function ( ) {
if ( user === "Administrator" ) {
2014-05-13 11:22:26 +00:00
msgprint ( _ _ ( "Login with your new User ID" ) + ": " + values . email ) ;
2014-04-17 13:18:59 +00:00
setTimeout ( function ( ) {
frappe . app . logout ( ) ;
} , 2000 ) ;
} else {
window . location = "/desk" ;
2013-10-08 12:29:11 +00:00
}
2014-04-17 13:18:59 +00:00
} , 2000 ) ;
} ,
error : function ( r ) {
2014-05-12 11:15:12 +00:00
2014-04-17 13:18:59 +00:00
var d = msgprint ( _ _ ( "There were errors." ) ) ;
d . custom _onhide = function ( ) {
frappe . set _route ( erpnext . wiz . page _name , "0" ) ;
2014-04-18 05:10:17 +00:00
} ;
2013-10-08 12:29:11 +00:00
}
} )
} ,
2014-04-17 13:18:59 +00:00
title : _ _ ( "Welcome" ) ,
2014-04-18 05:10:17 +00:00
working _html : function ( ) { return ' < h3 class = "text-muted text-center" > < i class = "icon-refresh icon-spin" > < / i > < / h 3 > \
2014-04-14 10:55:30 +00:00
< h2 class = "text-center" > '+__(' Setting up ... ')+' < / h 2 > \
2014-04-17 13:18:59 +00:00
< p class = "text-center" > ' +
_ _ ( 'Sit tight while your system is being setup. This may take a few moments.' ) +
2014-04-18 05:10:17 +00:00
'</p>' } ,
2015-01-19 12:04:33 +00:00
complete _html : function ( ) { return ' < h1 class = "text-muted text-center" > < / h 1 > \
2014-04-21 06:12:22 +00:00
< h2 class = "text-center" > '+__(' Setup Complete ')+' < / h 2 > \
2014-04-17 13:18:59 +00:00
< p class = "text-center" > ' +
_ _ ( 'Your setup is complete. Refreshing...' ) +
2014-04-18 05:10:17 +00:00
'</p>' } ,
2013-10-04 12:18:05 +00:00
slides : [
// User
2014-04-17 13:18:59 +00:00
{
title : _ _ ( "Select Your Language" ) ,
icon : "icon-globe" ,
fields : [
2014-11-24 06:47:08 +00:00
{
"fieldname" : "language" , "label" : _ _ ( "Language" ) , "fieldtype" : "Select" ,
2014-12-18 12:01:21 +00:00
reqd : 1
2014-11-24 06:47:08 +00:00
} ,
2014-04-17 13:18:59 +00:00
] ,
2015-01-15 06:36:42 +00:00
help : "" ,
2014-04-17 13:18:59 +00:00
onload : function ( slide ) {
2014-12-18 12:01:21 +00:00
var me = this ;
2015-01-15 06:36:42 +00:00
var select = slide . get _field ( "language" ) ;
2014-12-18 12:01:21 +00:00
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" ) ;
2014-12-18 12:01:21 +00:00
}
} )
} else {
2015-01-15 06:36:42 +00:00
select . df . options = this . language _list ;
select . refresh ( ) ;
2014-12-18 12:01:21 +00:00
}
2014-04-17 13:18:59 +00:00
slide . get _input ( "language" ) . on ( "change" , function ( ) {
2014-11-24 06:47:08 +00:00
var lang = $ ( this ) . val ( ) || "english" ;
2014-05-16 14:26:06 +00:00
frappe . _messages = { } ;
2014-04-17 13:18:59 +00:00
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 ) ;
2014-04-17 13:18:59 +00:00
}
} )
} ) ;
}
} ,
2014-04-22 10:55:58 +00:00
2013-10-04 12:18:05 +00:00
{
2014-04-14 10:55:30 +00:00
title : _ _ ( "The First User: You" ) ,
2013-10-07 12:52:29 +00:00
icon : "icon-user" ,
2013-10-04 12:18:05 +00:00
fields : [
2014-04-17 13:18:59 +00:00
{ "fieldname" : "first_name" , "label" : _ _ ( "First Name" ) , "fieldtype" : "Data" ,
2013-12-24 13:21:32 +00:00
reqd : 1 } ,
2014-04-17 13:18:59 +00:00
{ "fieldname" : "last_name" , "label" : _ _ ( "Last Name" ) , "fieldtype" : "Data" ,
2013-12-24 13:21:32 +00:00
reqd : 1 } ,
2014-04-17 13:18:59 +00:00
{ "fieldname" : "email" , "label" : _ _ ( "Email Id" ) , "fieldtype" : "Data" ,
2014-05-13 15:32:47 +00:00
reqd : 1 , "description" : _ _ ( "Your Login Id" ) , "options" : "Email" } ,
2014-04-17 13:18:59 +00:00
{ "fieldname" : "password" , "label" : _ _ ( "Password" ) , "fieldtype" : "Password" ,
2013-12-24 13:21:32 +00:00
reqd : 1 } ,
2014-04-17 13:18:59 +00:00
{ 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 ) ;
2013-10-18 10:37:47 +00:00
slide . form . fields _dict . email . $wrapper . toggle ( false ) ;
2014-03-11 10:45:05 +00:00
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-17 13:18:59 +00:00
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
} ,
2014-04-17 13:18:59 +00:00
2013-10-04 12:18:05 +00:00
// Country
{
2014-04-14 10:55:30 +00:00
title : _ _ ( "Country, Timezone and Currency" ) ,
2013-10-07 12:52:29 +00:00
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 ) {
2014-04-17 13:18:59 +00:00
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 ( )
2014-04-17 13:18:59 +00:00
. add _options ( [ "" ] . concat ( keys ( frappe . country _info ) . sort ( ) ) ) ;
2013-10-04 12:18:05 +00:00
slide . get _input ( "currency" ) . empty ( )
2014-04-17 13:18:59 +00:00
. 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 ( )
2014-04-17 13:18:59 +00:00
. add _options ( [ "" ] . concat ( frappe . all _timezones ) ) ;
2013-10-04 12:18:05 +00:00
}
} )
2014-04-17 13:18:59 +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 ) {
2014-04-17 13:18:59 +00:00
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
2014-04-17 13:18:59 +00:00
$timezone . add _options ( [ "" ] . concat ( frappe . all _timezones ) ) ;
2015-01-15 06:36:42 +00:00
slide . get _field ( "timezone" ) . set _input ( $timezone . val ( ) ) ;
2014-04-22 10:55:58 +00:00
// temporarily set date format
frappe . boot . sysdefaults . date _format = ( frappe . country _info [ country ] . date _format
|| "dd-mm-yyyy" ) ;
2014-03-21 05:44:49 +00:00
// get country specific chart of accounts
2014-08-25 12:57:42 +00:00
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
} ) ;
}
} ,
2014-04-17 13:18:59 +00:00
2014-04-22 10:55:58 +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 } ,
2014-04-22 10:55:58 +00:00
{ 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 ( ) ) ;
2014-04-22 10:55:58 +00:00
} ) . val ( frappe . boot . sysdefaults . company _name || "" ) . trigger ( "change" ) ;
2014-05-20 18:08:09 +00:00
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 ( "" ) ;
2014-05-20 18:08:09 +00:00
}
} ) ;
2014-04-22 10:55:58 +00:00
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 ) ;
2014-04-22 10:55:58 +00:00
} ) ;
}
} ,
2013-10-04 12:18:05 +00:00
// Logo
{
2013-10-07 12:52:29 +00:00
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.' ) ,
2013-10-07 12:52:29 +00:00
fields : [
2014-05-12 11:15:12 +00:00
{ 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-07 12:52:29 +00:00
] ,
2013-10-04 12:18:05 +00:00
} ,
2014-04-17 13:18:59 +00:00
2013-10-04 12:18:05 +00:00
// Taxes
{
2013-10-07 12:52:29 +00:00
icon : "icon-money" ,
2014-04-14 10:55:30 +00:00
"title" : _ _ ( "Add Taxes" ) ,
2014-05-13 11:22:26 +00:00
"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 ) {
2014-05-16 14:26:06 +00:00
slide . fields = [ ] ;
2014-04-21 06:12:22 +00:00
for ( var i = 1 ; i < 4 ; i ++ ) {
slide . fields = slide . fields . concat ( [
2014-05-13 11:22:26 +00:00
{ fieldtype : "Data" , fieldname : "tax_" + i , label : _ _ ( "Tax" ) + " " + i ,
placeholder : _ _ ( "e.g. VAT" ) + " " + i } ,
2014-04-21 06:12:22 +00:00
{ fieldtype : "Column Break" } ,
2014-04-22 10:55:58 +00:00
{ fieldtype : "Float" , fieldname : "tax_rate_" + i , label : _ _ ( "Rate (%)" ) , placeholder : _ _ ( "e.g. 5" ) } ,
2014-04-21 06:12:22 +00:00
{ fieldtype : "Section Break" } ,
] ) ;
}
}
2013-10-07 12:52:29 +00:00
} ,
2013-11-19 09:42:10 +00:00
// 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 ) {
2014-05-16 14:26:06 +00:00
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 ,
2014-05-13 11:22:26 +00:00
label : _ _ ( "Contact Name" ) + " " + i , placeholder : _ _ ( "Contact Name" ) } ,
2014-04-21 06:12:22 +00:00
{ fieldtype : "Section Break" }
] )
}
}
2013-10-07 12:52:29 +00:00
} ,
2013-11-19 09:42:10 +00:00
// 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 ) {
2014-05-16 14:26:06 +00:00
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 ,
2014-05-13 11:22:26 +00:00
placeholder : _ _ ( "Supplier Name" ) } ,
2014-04-21 06:12:22 +00:00
{ fieldtype : "Column Break" } ,
{ fieldtype : "Data" , fieldname : "supplier_contact_" + i ,
2014-05-13 11:22:26 +00:00
label : _ _ ( "Contact Name" ) + " " + i , placeholder : _ _ ( "Contact Name" ) } ,
2014-04-21 06:12:22 +00:00
{ fieldtype : "Section Break" }
] )
}
}
2013-11-19 09:42:10 +00:00
} ,
2014-05-13 11:22:26 +00:00
// Items to Sell
2013-10-07 12:52:29 +00:00
{
icon : "icon-barcode" ,
2014-05-13 11:22:26 +00:00
"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 ) {
2014-05-16 14:26:06 +00:00
slide . fields = [ ] ;
2014-04-21 06:12:22 +00:00
for ( var i = 1 ; i < 6 ; i ++ ) {
slide . fields = slide . fields . concat ( [
2014-05-13 11:22:26 +00:00
{ 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" ) } ,
2014-05-13 11:22:26 +00:00
{ 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" } ,
2014-05-16 14:26:06 +00:00
{ fieldtype : "Select" , label : _ _ ( "Group" ) , fieldname : "item_group_" + i ,
2014-05-13 11:22:26 +00:00
options : [ _ _ ( "Products" ) , _ _ ( "Services" ) ,
_ _ ( "Raw Material" ) , _ _ ( "Consumable" ) , _ _ ( "Sub Assemblies" ) ] } ,
2014-05-16 14:26:06 +00:00
{ fieldtype : "Select" , fieldname : "item_uom_" + i , label : _ _ ( "UOM" ) ,
2014-05-13 11:22:26 +00:00
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-07 12:52:29 +00:00
} ,
2013-10-04 12:18:05 +00:00
]
2013-12-24 13:21:32 +00:00
}
2014-04-17 13:18:59 +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
}
2015-01-29 12:39:11 +00:00
frappe . pages [ 'setup-wizard' ] . on _page _show = function ( wrapper ) {
2014-02-14 10:17:51 +00:00
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 ) ;
2014-04-17 13:18:59 +00:00
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 = { } ;
2014-04-17 13:18:59 +00:00
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 < / d i v > \
2013-10-08 12:29:11 +00:00
< / d i v > ' , { h t m l : h t m l } ) )
} ,
show _working : function ( ) {
this . hide _current _slide ( ) ;
2014-02-14 10:17:51 +00:00
frappe . set _route ( this . page _name ) ;
2014-04-18 05:10:17 +00:00
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 ( ) ;
2014-04-18 05:10:17 +00:00
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 ) ;
2014-04-17 13:18:59 +00:00
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 ( ) ;
}
2014-04-17 13:18:59 +00:00
2013-10-08 12:29:11 +00:00
this . hide _current _slide ( ) ;
2014-04-17 13:18:59 +00:00
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 ;
2014-04-17 13:18:59 +00:00
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 } ) )
2014-04-17 13:18:59 +00:00
. 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 ,
2013-10-07 12:52:29 +00:00
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 )
}
2014-04-17 13:18:59 +00:00
2013-10-04 12:18:05 +00:00
if ( this . id > 0 ) {
2014-04-17 13:18:59 +00:00
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 ) {
2014-04-17 13:18:59 +00:00
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 ( ) ;
2014-04-17 13:18:59 +00:00
if ( me . values === null )
2013-10-08 12:29:11 +00:00
return ;
2014-05-13 11:22:26 +00:00
if ( me . validate && ! me . validate ( ) )
return ;
2014-04-17 13:18:59 +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 {
2014-04-17 13:18:59 +00:00
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 ( ) ;
2014-04-17 13:18:59 +00:00
if ( me . values === null )
2013-10-08 12:29:11 +00:00
return ;
2014-05-13 11:22:26 +00:00
if ( me . validate && ! me . validate ( ) )
return ;
2014-04-17 13:18:59 +00:00
me . wiz . on _complete ( me . wiz ) ;
2013-12-24 13:21:32 +00:00
} )
2013-10-04 12:18:05 +00:00
}
2014-04-17 13:18:59 +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
}
2014-04-17 13:18:59 +00:00
} )