Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | // License: GNU General Public License v3. See license.txt |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 3 | |
| 4 | // complete my company registration |
| 5 | // -------------------------------- |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 6 | wn.provide('erpnext.complete_setup'); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 7 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 8 | $.extend(erpnext.complete_setup, { |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 9 | show: function() { |
| 10 | d = erpnext.complete_setup.prepare_dialog(); |
| 11 | d.show(); |
| 12 | }, |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 13 | |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 14 | prepare_dialog: function() { |
Rushabh Mehta | 2d700dd | 2012-10-01 14:46:37 +0530 | [diff] [blame] | 15 | var d = new wn.ui.Dialog({ |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 16 | title: "Setup", |
| 17 | fields: [ |
| 18 | {fieldname:'first_name', label:'Your First Name', fieldtype:'Data', reqd: 1}, |
| 19 | {fieldname:'last_name', label:'Your Last Name', fieldtype:'Data'}, |
| 20 | {fieldname:'company_name', label:'Company Name', fieldtype:'Data', reqd:1, |
| 21 | description: 'e.g. "My Company LLC"'}, |
| 22 | {fieldname:'company_abbr', label:'Company Abbreviation', fieldtype:'Data', |
| 23 | description:'e.g. "MC"',reqd:1}, |
| 24 | {fieldname:'fy_start', label:'Financial Year Start Date', fieldtype:'Select', |
| 25 | description:'Your financial year begins on"', reqd:1, |
| 26 | options: erpnext.complete_setup.fy_start_list.join('\n')}, |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 27 | {fieldname:'country', label: 'Country', reqd:1, |
| 28 | options: "", fieldtype: 'Select'}, |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 29 | {fieldname:'currency', label: 'Default Currency', reqd:1, |
Anand Doshi | 6b2aa7e | 2013-05-20 13:43:50 +0530 | [diff] [blame] | 30 | options: "", fieldtype: 'Select'}, |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 31 | {fieldname:'timezone', label: 'Time Zone', reqd:1, |
| 32 | options: "", fieldtype: 'Select'}, |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 33 | {fieldname:'industry', label: 'Industry', reqd:1, |
Rushabh Mehta | 982ad35 | 2013-07-10 18:39:06 +0530 | [diff] [blame] | 34 | options: erpnext.complete_setup.domains.join('\n'), fieldtype: 'Select'}, |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 35 | {fieldname:'update', label:'Setup',fieldtype:'Button'}, |
| 36 | ], |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 37 | }); |
Anand Doshi | afad0ef | 2013-07-10 12:00:26 +0530 | [diff] [blame] | 38 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 39 | if(user != 'Administrator'){ |
Anand Doshi | c8f4bda | 2013-07-16 16:51:55 +0530 | [diff] [blame] | 40 | d.$wrapper.find('.close').toggle(false); // Hide close image |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 41 | $('header').toggle(false); // hide toolbar |
| 42 | } |
| 43 | |
Anand Doshi | a648f46 | 2013-07-30 14:42:15 +0530 | [diff] [blame] | 44 | wn.call({ |
Anand Doshi | 6b2aa7e | 2013-05-20 13:43:50 +0530 | [diff] [blame] | 45 | method:"webnotes.country_info.get_country_timezone_info", |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 46 | callback: function(data) { |
Anand Doshi | 6b2aa7e | 2013-05-20 13:43:50 +0530 | [diff] [blame] | 47 | erpnext.country_info = data.message.country_info; |
| 48 | erpnext.all_timezones = data.message.all_timezones; |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 49 | d.get_input("country").empty() |
Anand Doshi | 6b2aa7e | 2013-05-20 13:43:50 +0530 | [diff] [blame] | 50 | .add_options([""].concat(keys(erpnext.country_info).sort())); |
| 51 | d.get_input("currency").empty() |
| 52 | .add_options(wn.utils.unique([""].concat($.map(erpnext.country_info, |
| 53 | function(opts, country) { return opts.currency; }))).sort()); |
| 54 | d.get_input("timezone").empty() |
| 55 | .add_options([""].concat(erpnext.all_timezones)); |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 56 | } |
| 57 | }) |
| 58 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 59 | // on clicking update |
| 60 | d.fields_dict.update.input.onclick = function() { |
| 61 | var data = d.get_values(); |
| 62 | if(!data) return; |
| 63 | $(this).set_working(); |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 64 | return $c_obj('Setup Control','setup_account',data,function(r, rt){ |
Rushabh Mehta | e41bceb | 2013-07-10 20:42:44 +0530 | [diff] [blame] | 65 | $(this).done_working(); |
Anand Doshi | 7edb191 | 2013-06-24 12:11:15 +0530 | [diff] [blame] | 66 | if(!r.exc) { |
| 67 | sys_defaults = r.message; |
| 68 | user_fullname = r.message.user_fullname; |
| 69 | wn.boot.user_info[user].fullname = user_fullname; |
| 70 | d.hide(); |
| 71 | $('header').toggle(true); |
| 72 | wn.container.wntoolbar.set_user_name(); |
| 73 | |
| 74 | setTimeout(function() { window.location.reload(); }, 3000); |
| 75 | } |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 76 | }); |
| 77 | }; |
Rushabh Mehta | e41bceb | 2013-07-10 20:42:44 +0530 | [diff] [blame] | 78 | |
| 79 | d.fields_dict.company_name.input.onchange = function() { |
| 80 | var parts = d.get_input("company_name").val().split(" "); |
| 81 | var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join(""); |
| 82 | d.get_input("company_abbr").val(abbr.toUpperCase()); |
| 83 | } |
| 84 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 85 | d.fields_dict.country.input.onchange = function() { |
| 86 | var country = d.fields_dict.country.input.value; |
| 87 | var $timezone = $(d.fields_dict.timezone.input); |
| 88 | $timezone.empty(); |
Anand Doshi | 6b2aa7e | 2013-05-20 13:43:50 +0530 | [diff] [blame] | 89 | // add country specific timezones first |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 90 | if(country){ |
Anand Doshi | 6b2aa7e | 2013-05-20 13:43:50 +0530 | [diff] [blame] | 91 | var timezone_list = erpnext.country_info[country].timezones || []; |
| 92 | $timezone.add_options(timezone_list.sort()); |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 93 | |
| 94 | d.get_input("currency").val(erpnext.country_info[country].currency); |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 95 | } |
Anand Doshi | 6b2aa7e | 2013-05-20 13:43:50 +0530 | [diff] [blame] | 96 | // add all timezones at the end, so that user has the option to change it to any timezone |
| 97 | $timezone.add_options([""].concat(erpnext.all_timezones)); |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 98 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | // company name already set |
| 102 | if(wn.control_panel.company_name) { |
| 103 | var inp = d.fields_dict.company_name.input; |
| 104 | inp.value = wn.control_panel.company_name; |
| 105 | inp.disabled = true; |
Anand Doshi | 9c2bb0e | 2013-07-16 16:56:28 +0530 | [diff] [blame] | 106 | d.fields_dict.company_name.$input.trigger("change"); |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // set first name, last name |
| 110 | if(user_fullname) { |
| 111 | u = user_fullname.split(' '); |
| 112 | if(u[0]) { |
| 113 | d.fields_dict.first_name.input.value = u[0]; |
| 114 | } |
| 115 | if(u[1]) { |
| 116 | d.fields_dict.last_name.input.value = u[1]; |
| 117 | } |
| 118 | } |
| 119 | |
Anand Doshi | afad0ef | 2013-07-10 12:00:26 +0530 | [diff] [blame] | 120 | return d; |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 121 | }, |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 122 | |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 123 | fy_start_list: ['', '1st Jan', '1st Apr', '1st Jul', '1st Oct'], |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 124 | |
Nabin Hait | 4af2dbf | 2013-08-12 12:24:08 +0530 | [diff] [blame] | 125 | domains: ['', "Manufacturing", "Retail", "Distribution", "Services", "Other"], |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 126 | }); |