pscript['onshow_Sales Browser'] = function(){ wn.require('lib/js/legacy/widgets/tree.js'); var route = decodeURIComponent(location.hash); if(route.indexOf('/')!=-1) { var chart_type = route.split('/')[1]; new SalesBrowser().set_val(chart_type) return; } var parent = $i('tr_body'); parent.innerHTML = 'Please select your chart: ' var sel = $a(parent,'select'); add_sel_options(sel, ['Territory', 'Customer Group', 'Item Group', 'Sales Person'], 'Territory'); var btn = $btn(parent, 'Go', function() { new SalesBrowser().set_val(sel_val(sel)) }, {marginTop:'8px'}); } //================================= SalesBrowser Class ====================================== SalesBrowser = function(){ this.make_body = function(){ $i('tr_header').innerHTML = ''; $i('tr_body').innerHTML = ''; //make header var desc = this.sel; var me = this; var h = new PageHeader($i('tr_header'),desc); h.add_button('New '+this.sel, function() { me.set_dialog(1); }, 0, 'ui-icon-plus', 1); h.add_button('Refresh', function() { me.refresh_tree(); }, 0, 'ui-icon-refresh'); var div_body = $a($i('tr_body'),'div'); var tr_main_grid = make_table(div_body,1,2,'100%',['60%','40%'],{width: "100%", tableLayout: "fixed", borderCollapse: "collapse", border:"0px", padding:"4px 4px 4px 4px"}); $y($td(tr_main_grid,0,0),{border: "1px solid #dddddd", padding: "8px", width: "60%"}); this.tree_area = $a($td(tr_main_grid,0,0),'div'); $y($td(tr_main_grid,0,1),{border: "1px solid #DDD"}); this.detail_area = $a($td(tr_main_grid,0,1),'div'); this.make_tree_body(this.tree_area); this.refresh_tree(); } this.set_val = function(b){ var me = this; me.sel = b; me.make_body(); } } //================================================================================================================================= SalesBrowser.prototype.make_tree_body = function(parent){ //this.tab2 =make_table(this.wrapper,1,2,'100%',['60%','40%']); this.make_tree(); this.make_rgt_sect(); } //================================================================================================================================= SalesBrowser.prototype.make_rgt_sect=function(){ //var d = $a($td(this.tab2,0,1),'div','',{border:'1px solid #000'}); this.rgt_tab =make_table(this.detail_area,4,1,'','',{padding:"4px",spacing:"4px"}); this.dtl = $a($td(this.rgt_tab,0,0),'div'); this.btn = $a($td(this.rgt_tab,1,0),'div','span'); this.help = $a($td(this.rgt_tab,2,0),'div'); this.help.innerHTML = "Note: Explore and click on the tree node to see details." this.set_btn(); } //================================================================================================================================= SalesBrowser.prototype.set_btn = function(){ var me = this; this.edit_btn = $btn(this.btn,'Edit',function(){ me.set_dialog(2); }); this.trash_btn = $btn(this.btn,'Trash',null); this.trash_btn.onclick = function(){ var check = confirm("Are you sure you want to trash "+me.cur_node.rec.name+" node?"); if(check){ var arg = [me.cur_node.rec.name, me.sel]; $c_obj('Sales Browser Control','trash_record',arg.join(','),function(r,rt){ me.refresh_tree();}); } } } //===================================================== SalesBrowser.prototype.set_dialog = function(f){ if(this.sel == 'Territory') new MakeDialog('Territory','territory',f,this); //Territory Dialog if(this.sel == 'Customer Group') new MakeDialog('Customer Group','customer_group',f,this); //Customer Group Dialog if(this.sel == 'Item Group') new MakeDialog('Item Group','item_group',f,this); //Item Group Dialog if(this.sel == 'Sales Person') new MakeDialog('Sales Person','sales_person',f,this);//Sales Person Dialog } //=====================================================Make Tree============================================================================ SalesBrowser.prototype.make_tree = function() { var me = this; this.tree = new Tree(this.tree_area, '100%'); //--------------------------------------------------------------------------------------------------------------------------------- // on click this.tree.std_onclick = function(node) { me.cur_node = node; if(node.rec.name =='All Customer Groups' || node.rec.name =='All Sales Persons' || node.rec.name =='All Item Groups' || node.rec.name =='All Territories'){ //$di(me.add_btn); $dh(me.edit_btn); $dh(me.trash_btn); } else{ //$di(me.add_btn); //if(node.has_children == false) //$dh(me.add_btn); $di(me.edit_btn); $di(me.trash_btn); } me.make_details(); } //--------------------------------------------------------------------------------------------------------------------------------- // on expand this.tree.std_onexp = function(node) { if(node.expanded_once)return; $di(node.loading_div); var callback = function(r,rt) { $dh(node.loading_div); var n = me.tree.allnodes[r.message.parent]; var cl = r.message.cl; for(var i=0;i