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