Pman.Tab.AdminCompanies.bjs
[Pman.Admin] / Pman.Tab.Office.js
1  //<script type="text/javascript">
2
3  
4 Pman.Tab.Office = {
5     grid : false,
6     panel : false,
7     add : function(parentLayout, region) {
8         
9         if (!Pman.hasPerm('Core.Office','S')) {
10             return;
11         }
12         
13
14         if (this.panel) {
15             parentLayout.getRegion(region).showPanel(this.panel);
16             return;
17         }
18      
19         
20         this.innerLayout = new Ext.BorderLayout(
21             parentLayout.getEl().createChild({tag:'div'}),
22             {
23                
24                 center: {
25                     autoScroll:true,
26                     hideTabs: true
27                 }
28             }
29         );
30
31  
32         this.tab = parentLayout.add(region,  new Ext.NestedLayoutPanel(
33             this.innerLayout, {title: "Offices / Departments / Sub-Companies" }));
34
35        
36         this.innerLayout.beginUpdate();
37         var _dialog = Pman.Dialog.Office;
38         var refreshPager = function() {
39             _this.paging.onClick('refresh');
40         }
41       
42         //this.grid = new Ext.grid.EditorGrid(frm,  {
43         this.grid = new Ext.grid.Grid(this.innerLayout.getEl().createChild({tag:'div'}),  {
44                 id: 'grid-Office',
45                 ds:   new Ext.data.Store({
46                     // load using HTTP
47                     proxy: new Ext.data.HttpProxy({
48                         url: baseURL + '/Roo/Office.html',
49                         method: 'GET'
50                     }),
51                     reader: Pman.Readers.Office,
52                     remoteSort: true,
53                     listeners : {
54                         beforeload: function(t, o) {
55                             //console.log(o.params);
56                             o.params.company_id = Pman.Tab.Companies.getSelectedId();
57                             if (!o.params.company_id) {
58                                 return false;
59                                }
60                             
61                         },
62                      
63                         loadexception : Pman.loadException
64                     
65                     }
66                 }),
67                 cm: new Ext.grid.ColumnModel(
68                     [ {
69                         'id' : 'Office-name',
70                         header : "Name / Department / Sub Comp.",
71                         'dataIndex' : 'name',
72                         'sortable' : true,
73                         'width' : 200
74                     },{
75                         'id' : 'Office-phone',
76                         header : "Phone",
77                         'dataIndex' : 'phone',
78                         'sortable' : true,
79                         'width' : 100
80                     },{
81                         'id' : 'Office-fax',
82                         header : "Fax",
83                         'dataIndex' : 'fax',
84                         'sortable' : true,
85                         'width' : 100
86                     },{
87                         'id' : 'Office-email',
88                         header : "Email",
89                         'dataIndex' : 'email',
90                         'sortable' : true,
91                         'width' : 150,
92                         renderer : function (v) {
93                             return (v.length && v.indexOf('@') > 0 ) ? 
94                                 String.format('<a href="mailto:{0}">{0}</a>',v) : v;
95                                 
96                         }
97                     },{
98                         'id' : 'Office-address',
99                         header : "Address",
100                         'dataIndex' : 'address',
101                         'sortable' : true,
102                         'width' : 300
103                     }]
104                 ),
105                 autoExpandColumn: 'Office-address' , // fixme!!!!
106                 clicksToEdit : 1,
107                 
108                 loadMask: true,
109
110                 listeners : {
111                     rowdblclick : function(g, ri, e) {
112                         var s = g.getDataSource().getAt(ri).data
113                         s.company_name = Pman.Tab.Companies.grid.getSelectionModel().getSelected().data.name;
114                         _dialog.show(s, refreshPager); 
115                     }
116                 }
117                  
118         });
119         this.panel  = this.innerLayout.add('center',  new Ext.GridPanel(this.grid ,
120             { fitToframe: true,fitContainer: true })
121         );
122         this.grid.render();
123         var gridFoot = this.grid.getView().getFooterPanel(true);
124         this.paging = new Ext.PagingToolbar(gridFoot, this.grid.getDataSource(), {
125             pageSize: 25,
126             displayInfo: true,
127             displayMsg: "Displaying Offices {0} - {1} of {2}",
128             emptyMsg: "No Offices found"
129         });
130         var grid = this.grid;
131  
132         var gridHead = this.grid.getView().getHeaderPanel(true);
133         var tb = new Ext.Toolbar(gridHead);
134         var _this = Pman.Tab.Office;
135          
136        
137         
138         tb.add(
139             {
140                 text: "Add",
141                 cls: 'x-btn-text-icon',
142                 icon: Ext.rootURL + 'images/default/dd/drop-add.gif',
143                 hidden : !Pman.hasPerm('Core.Offices', 'A'),
144                 handler : function(){
145                     if (!Pman.Tab.Companies.grid.getSelectionModel().getSelections().length) {
146                         Ext.MessageBox.alert("Select a company to add a office to");
147                         return;
148                     }
149                     var cdata = Pman.Tab.Companies.grid.getSelectionModel().getSelected().data;
150                     _dialog.show( { 
151                         id : 0 ,
152                         company_name : cdata.name,
153                         company_id : cdata.id,
154                         address : cdata.address,
155                         phone : cdata.tel,
156                         fax : cdata.fax,
157                         email  : cdata.email
158                     }, refreshPager );  
159                 }
160             }, 
161             {
162                 text: "Edit",
163                 cls: 'x-btn-text-icon',
164                 icon: Ext.rootURL + 'images/default/tree/leaf.gif',
165                hidden : !Pman.hasPerm('Core.Offices', 'E'),
166                 handler : function(){
167                     var s = grid.getSelectionModel().getSelections();
168                     if (!s.length || (s.length > 1))  {
169                         Ext.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
170                         return;
171                     }
172                     // we should have company_id - just need name..
173                     s[0].data.company_name = Pman.Tab.Companies.grid.getSelectionModel().getSelected().data.name;
174                     _dialog.show(s[0].data, refreshPager); 
175                     
176                 }
177             },  
178             {
179                 text: "Delete",
180                 cls: 'x-btn-text-icon',
181                 icon: rootURL + '/Pman/templates/images/trash.gif',
182                 hidden : !Pman.hasPerm('Core.Offices', 'D'),
183                 handler : function(){
184                     Pman.genericDelete(_this, 'Office'); 
185                 }
186             } 
187         );
188         this.tab.on('activate', function() {
189            //_this.paging.onClick('refresh');
190         });
191             
192         //this.toolbar = tb;
193         // add stuff to toolbar?
194         this.innerLayout.endUpdate();
195         
196         
197         
198     },
199     show: function (parentLayout, region)
200     {
201         this.add(parentLayout, region);
202         this.grid.getDataSource().load({
203             params: {
204                 start:0, 
205                 limit:25
206             }
207         });
208
209     }
210 };