2012-02-23 07:05:32 +00:00
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2011-06-08 09:07:15 +00:00
pscript [ 'onload_Setup Wizard' ] = function ( )
{
// header and toolbar
var h = new PageHeader ( 'setup_wizard_wrapper' , 'Setup Wizard' , 'All important setup items in one place' ) ;
pscript . setup _wizard _callback ( ) ;
}
// ==================================================================================================
pscript . setup _wizard _callback = function ( ) {
var items = { } ;
items [ 'Customer' ] = new pscript . Setup _Wizard _Obj ( 'Customer' , 'customer_name' , 0 , '' , 'Customer' , 'Manage your customers' , 1 ) ;
items [ 'Supplier' ] = new pscript . Setup _Wizard _Obj ( 'Supplier' , 'supplier_name' , 0 , '' , 'Supplier' , 'Manage your supplier' , 1 ) ;
items [ 'Item' ] = new pscript . Setup _Wizard _Obj ( 'Item' , 'item_name' , 0 , '' , 'Item' , 'Create your items' , 1 ) ;
//items['Customer Group'] = new pscript.Setup_Wizard_Obj('Customer Group', 'group_name', 0, '', 'Customer Group', 'Organizes your customers for better analysis');
items [ 'Price List' ] = new pscript . Setup _Wizard _Obj ( 'Price List' , 'price_list_name' , 0 , '' , 'Price List' , 'Helps you maintain different prices for different customers, currencies etc.' ) ;
items [ 'Supplier Type' ] = new pscript . Setup _Wizard _Obj ( 'Supplier Type' , 'supplier_type' , 0 , '' , 'Supplier Type' , 'Organizes your suppliers for better analysis' ) ;
//items['Item Group'] = new pscript.Setup_Wizard_Obj('Item Group', 'group_name', 0, '', 'Item Group', 'Organizes your items for better analysis');
items [ 'UoM' ] = new pscript . Setup _Wizard _Obj ( 'UOM' , 'uom_name' , 0 , '' , 'UOM' , 'Maintain multiple Units of Measure (UOM)' ) ;
items [ 'Warehouse Type' ] = new pscript . Setup _Wizard _Obj ( 'Warehouse Type' , 'warehouse_type' , 0 , '' , 'Warehouse Type' , 'Define types of warehouses' ) ;
items [ 'Warehouse' ] = new pscript . Setup _Wizard _Obj ( 'Warehouse' , 'warehouse_name' , 'warehouse_type' , 'Warehouse Type' , 'Warehouse' , 'Manage stock across different warehouses' ) ;
items [ 'Print Heading' ] = new pscript . Setup _Wizard _Obj ( 'Print Heading' , 'print_heading' , 'transaction' , 'Transaction' , 'Print Heading' , 'Define print heading for various transaction.' ) ;
items [ 'Warehouse Type' ] . onmake = function ( ) {
items [ 'Warehouse' ] . refresh _select ( 'warehouse_type' , 'Warehouse Type' , 'Warehouse' ) ;
}
items [ 'Print Heading' ] . onmake = function ( ) {
items [ 'Print Heading' ] . refresh _select ( 'transaction' , 'Transaction' , 'Print Heading' ) ;
}
}
// ==================================================================================================
pscript . Setup _Wizard _Obj = function ( lbl , name _field , opt _fieldname , opt _field _tbl , dt , desc , important )
{
this . lbl = lbl ;
this . make _body ( lbl , important ) ;
if ( lbl != 'Item' )
this . make _input ( name _field ) ;
if ( opt _fieldname ) {
this . make _select ( opt _fieldname , opt _field _tbl , dt ) ;
}
this . show _description ( desc ) ;
this . make _button ( ) ;
this . create _doc _link ( dt ) ;
}
pscript . Setup _Wizard _Obj . prototype . make _body = function ( lbl , important ) {
var wrapper = $a ( $i ( 'setup_wizard_wrapper' ) , 'div' , '' , { padding : '8px' , borderBottom : '1px solid #AAA' } ) ;
if ( important ) $y ( wrapper , { backgroundColor : '#FFD' } ) ;
this . tab = make _table ( wrapper , 1 , 3 , '90%' , [ '20%' , '50%' , '30%' ] , { padding : '2px 0px' , verticalAlign : 'middle' } ) ;
this . desc _area = $a ( wrapper , 'div' , 'comment' ) ;
$td ( this . tab , 0 , 0 ) . innerHTML = lbl . bold ( ) ;
}
pscript . Setup _Wizard _Obj . prototype . make _input = function ( name _field ) {
this . input = $a _input ( $td ( this . tab , 0 , 1 ) , 'text' ) ;
this . name _field = name _field ;
}
pscript . Setup _Wizard _Obj . prototype . make _select = function ( fn , ft , dt ) {
this . select = $a ( $td ( this . tab , 0 , 1 ) , 'select' , '' , { width : '120px' , marginLeft : '8px' } ) ;
this . opt _field = fn ;
this . sel _field = 'Select ' + ft + '...' ;
this . refresh _select ( fn , ft , dt ) ;
}
pscript . Setup _Wizard _Obj . prototype . refresh _select = function ( fn , ft , dt ) {
var me = this ;
if ( ft == 'Transaction' ) {
empty _select ( me . select ) ;
add _sel _options ( me . select , [ 'Select Transaction ...' , 'Purchase Order' , 'Sales Order' , 'Service Order' , 'Purchase Receipt' , 'Delivery Note' , 'Receivable Voucher' , 'Payable Voucher' , 'Journal Voucher' ] ) ;
}
else {
$c _obj ( 'Setup Wizard Control' , 'get_master_lists' , '' , function ( r , rt ) {
var ft _lst = [ ] ;
if ( r . message ) ft _lst = r . message ;
ft _lst . push ( 'Select Warehouse Type ...' ) ;
empty _select ( me . select ) ;
add _sel _options ( me . select , ft _lst . reverse ( ) , 'Warehouse Type' ) ;
} ) ;
}
}
pscript . Setup _Wizard _Obj . prototype . make _button = function ( ) {
var me = this ;
var create = $a ( $td ( this . tab , 0 , 1 ) , 'button' , '' , { marginLeft : '8px' } ) ;
create . innerHTML = 'Create' ;
create . onclick = function ( ) {
me . create _record ( this ) ;
}
}
// show description
pscript . Setup _Wizard _Obj . prototype . show _description = function ( desc ) {
this . desc _area . innerHTML = desc ;
}
// create link to show listing of all records
pscript . Setup _Wizard _Obj . prototype . create _doc _link = function ( doc _link ) {
this . obj _link = $a ( $td ( this . tab , 0 , 2 ) , 'span' , 'link_type' , { marginLeft : '8px' } ) ;
this . obj _link . innerHTML = 'View ' + doc _link + ' list' ;
this . dt = doc _link ;
this . obj _link . onclick = function ( ) {
if ( doc _link == 'Customer' ) doc _lst = 'customer_group' + NEWLINE + 'country' ;
else if ( doc _link == 'Supplier' ) doc _lst = 'supplier_type' + NEWLINE + 'supplier_status' + NEWLINE + 'company' ;
else if ( doc _link == 'Item' ) doc _lst = 'item_group' + NEWLINE + 'description' ;
if ( doc _link == 'Customer' || doc _link == 'Supplier' || doc _link == 'Item' )
loaddocbrowser ( doc _link , doc _link , doc _lst ) ;
else
loaddocbrowser ( doc _link ) ;
}
}
pscript . Setup _Wizard _Obj . prototype . create _record = function ( cur _obj )
{
var me = this ;
if ( me . lbl == 'Item' ) { me . create _master _rec ( ) ; }
else {
if ( this . input . value ) { //check for input value
if ( this . select && ( this . sel _field == this . select . value ) ) { //check for value is selected or not
alert ( 'Please select ' + this . select . value ) ;
this . input . value = '' ;
}
else {
args = { } ;
args [ 'Doctype' ] = this . dt ;
if ( strip ( this . input . value ) == '' ) { alert ( "Please enter proper name." ) ; me . input . value = '' ; }
else {
if ( me . lbl == 'Customer' || me . lbl == 'Supplier' ) { this . create _master _rec ( ) ; }
else {
args [ this . name _field ] = this . input . value ;
args [ this . opt _field ] = this . opt _field ? this . select . value : '' ;
$c _obj ( 'Setup Wizard Control' , 'create_record' , JSON . stringify ( args ) , function ( r , rt ) {
alert ( r . message ) ;
me . input . value = '' ;
if ( me . onmake ) me . onmake ( ) ;
} ) ;
}
}
}
}
else
alert ( "Please enter " + this . dt ) ;
}
}
pscript . Setup _Wizard _Obj . prototype . create _master _rec = function ( ) {
var me = this ;
var fn = function ( new _docname ) {
var new _doc = locals [ me . lbl ] [ new _docname ] ;
if ( me . lbl == 'Customer' )
new _doc . customer _name = me . input . value ;
else if ( me . lbl == 'Supplier' )
new _doc . supplier _name = me . input . value ;
}
new _doc ( me . lbl , fn ) ;
}