Pman.Tab.AdminOffice.js
[Pman.Admin] / Pman.Tab.AdminOffice.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5
6
7 // register the module first
8 Pman.on('beforeload', function()
9 {
10     Pman.register({
11         modKey : '001-Pman.Tab.AdminOffice',
12         module : Pman.Tab.AdminOffice,
13         region : 'center',
14         parent : Pman.Tab.AdminCompanies,
15         name : "Pman.Tab.AdminOffice",
16         disabled : false, 
17         permname: '' 
18     });
19 });
20
21 Pman.Tab.AdminOffice = new Roo.util.Observable({
22
23     panel : false,
24     disabled : false,
25     parentLayout:  false,
26
27     add : function(parentLayout, region)
28     {
29
30         var _this = this;
31         this.parentLayout = parentLayout;
32
33         this.panel = parentLayout.addxtype({
34             xtype: 'GridPanel',
35             xns: Roo,
36             listeners : {
37                 activate : function() {
38                     _this.panel = this;
39                     if (_this.grid) {
40                         _this.grid.footer.onClick('first');
41                     }
42                 }
43             },
44             background : true,
45             fitContainer : true,
46             fitToframe : true,
47             region : 'center',
48             tableName : 'Office',
49             title : "Offices / Departments / Sub-Companies",
50             grid : {
51                 xtype: 'Grid',
52                 xns: Roo.grid,
53                 listeners : {
54                     render : function() 
55                     {
56                         _this.grid = this; 
57                         _this.dialog =Pman.Dialog.Office;
58                         if (_this.panel.active) {
59                            this.footer.onClick('first');
60                         }
61                     },
62                     rowdblclick : function (_self, rowIndex, e)
63                     {
64                         if (!_this.dialog) return;
65                         _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
66                             _this.grid.footer.onClick('first');
67                         }); 
68                     }
69                 },
70                 autoExpandColumn : 'name',
71                 loadMask : true,
72                 dataSource : {
73                     xtype: 'Store',
74                     xns: Roo.data,
75                     listeners : {
76                         beforeload : function (_self, o)
77                         {
78                             try {
79                                 var sm = Pman.Tab.AdminCompanies.grid.getSelectionModel();
80                                 sm = sm.getSelected();
81                                 if (!sm || !sm.data.id) {
82                                     // mask??
83                                     return false;
84                                 }
85                                        
86                                 o.params.company_id = sm.data.id ;
87                             } catch (e) {
88                                 return false;
89                             }
90                             
91                          }
92                     },
93                     remoteSort : true,
94                     sortInfo : { field : 'name', direction: 'ASC' },
95                     proxy : {
96                         xtype: 'HttpProxy',
97                         xns: Roo.data,
98                         method : 'GET',
99                         url : baseURL + '/Roo/Office.php'
100                     },
101                     reader : {
102                         xtype: 'JsonReader',
103                         xns: Roo.data,
104                         totalProperty : 'total',
105                         root : 'data',
106                         id : 'id',
107                         fields : [
108                             {
109                                 'name': 'id',
110                                 'type': 'int'
111                             },
112                             {
113                                 'name': 'company_id',
114                                 'type': 'int'
115                             },
116                             {
117                                 'name': 'name',
118                                 'type': 'string'
119                             },
120                             {
121                                 'name': 'address',
122                                 'type': 'string'
123                             },
124                             {
125                                 'name': 'phone',
126                                 'type': 'string'
127                             },
128                             {
129                                 'name': 'fax',
130                                 'type': 'string'
131                             },
132                             {
133                                 'name': 'email',
134                                 'type': 'string'
135                             },
136                             {
137                                 'name': 'role',
138                                 'type': 'string'
139                             },
140                             {
141                                 'name': 'company_id_code',
142                                 'type': 'string'
143                             },
144                             {
145                                 'name': 'company_id_name',
146                                 'type': 'string'
147                             },
148                             {
149                                 'name': 'company_id_remarks',
150                                 'type': 'string'
151                             },
152                             {
153                                 'name': 'company_id_owner_id',
154                                 'type': 'int'
155                             },
156                             {
157                                 'name': 'company_id_address',
158                                 'type': 'string'
159                             },
160                             {
161                                 'name': 'company_id_tel',
162                                 'type': 'string'
163                             },
164                             {
165                                 'name': 'company_id_fax',
166                                 'type': 'string'
167                             },
168                             {
169                                 'name': 'company_id_email',
170                                 'type': 'string'
171                             },
172                             {
173                                 'name': 'company_id_id',
174                                 'type': 'int'
175                             },
176                             {
177                                 'name': 'company_id_isOwner',
178                                 'type': 'int'
179                             },
180                             {
181                                 'name': 'company_id_logo_id',
182                                 'type': 'int'
183                             },
184                             {
185                                 'name': 'company_id_background_color',
186                                 'type': 'string'
187                             },
188                             {
189                                 'name': 'company_id_comptype',
190                                 'type': 'string'
191                             },
192                             {
193                                 'name': 'company_id_url',
194                                 'type': 'string'
195                             },
196                             {
197                                 'name': 'company_id_main_office_id',
198                                 'type': 'int'
199                             },
200                             {
201                                 'name': 'company_id_created_by',
202                                 'type': 'int'
203                             },
204                             {
205                                 'name': 'company_id_created_dt',
206                                 'type': 'date'
207                             },
208                             {
209                                 'name': 'company_id_updated_by',
210                                 'type': 'int'
211                             },
212                             {
213                                 'name': 'company_id_updated_dt',
214                                 'type': 'date'
215                             },
216                             {
217                                 'name': 'company_id_passwd',
218                                 'type': 'string'
219                             },
220                             {
221                                 'name': 'company_id_dispatch_port',
222                                 'type': 'string'
223                             },
224                             {
225                                 'name': 'company_id_province',
226                                 'type': 'string'
227                             },
228                             {
229                                 'name': 'company_id_country',
230                                 'type': 'string'
231                             }
232                         ]
233                     }
234                 },
235                 footer : {
236                     xtype: 'PagingToolbar',
237                     xns: Roo,
238                     pageSize : 25,
239                     displayInfo : true,
240                     displayMsg : 'Displaying Office{0} - {1} of {2}',
241                     emptyMsg : 'No Office found'
242                 },
243                 toolbar : {
244                     xtype: 'Toolbar',
245                     xns: Roo,
246                     items : [
247                         {
248                             xtype: 'Button',
249                             xns: Roo.Toolbar,
250                             text : "Add",
251                             cls : 'x-btn-text-icon',
252                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
253                             listeners : {
254                                 click : function()
255                                 {
256                                     if (!_this.dialog) return;
257                                     _this.dialog.show( { id : 0 } , function() {
258                                         _this.grid.footer.onClick('first');
259                                    }); 
260                                 }
261                             }
262                         },
263                         {
264                             xtype: 'Button',
265                             xns: Roo.Toolbar,
266                             text : "Edit",
267                             cls : 'x-btn-text-icon',
268                             icon : Roo.rootURL + 'images/default/tree/leaf.gif',
269                             listeners : {
270                                 click : function()
271                                 {
272                                     var s = _this.grid.getSelectionModel().getSelections();
273                                     if (!s.length || (s.length > 1))  {
274                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
275                                         return;
276                                     }
277                                     if (!_this.dialog) return;
278                                     _this.dialog.show(s[0].data, function() {
279                                         _this.grid.footer.onClick('first');
280                                     }); 
281                                     
282                                 }
283                             }
284                         },
285                         {
286                             xtype: 'Button',
287                             xns: Roo.Toolbar,
288                             text : "Delete",
289                             cls : 'x-btn-text-icon',
290                             icon : rootURL + '/Pman/templates/images/trash.gif',
291                             listeners : {
292                                 click : function()
293                                 {
294                                      Pman.genericDelete(_this, 'Office'); 
295                                 }
296                             }
297                         }
298                     ]
299                 },
300                 colModel : [
301                     {
302                         xtype: 'ColumnModel',
303                         xns: Roo.grid,
304                         dataIndex : 'name',
305                         header : 'Name / Department / Sub Comp.',
306                         sortable : true,
307                         width : 200,
308                         renderer : function(v) { return String.format('{0}', v); }
309                     },
310                     {
311                         xtype: 'ColumnModel',
312                         xns: Roo.grid,
313                         dataIndex : 'phone',
314                         header : 'Phone',
315                         width : 100,
316                         renderer : function(v) { return String.format('{0}', v); }
317                     },
318                     {
319                         xtype: 'ColumnModel',
320                         xns: Roo.grid,
321                         dataIndex : 'fax',
322                         header : 'Fax',
323                         width : 100,
324                         renderer : function(v) { return String.format('{0}', v); }
325                     },
326                     {
327                         xtype: 'ColumnModel',
328                         xns: Roo.grid,
329                         dataIndex : 'email',
330                         header : 'Email',
331                         width : 200,
332                         renderer : function (v) {
333                             return (v.length && v.indexOf('@') > 0 ) ? 
334                                 String.format('<a href="mailto:{0}">{0}</a>',v) : v;
335                                 
336                         }
337                     },
338                     {
339                         xtype: 'ColumnModel',
340                         xns: Roo.grid,
341                         dataIndex : 'address',
342                         header : 'Address',
343                         width : 300,
344                         renderer : function(v) { return String.format('{0}', v); }
345                     }
346                 ]
347             }
348         });
349         this.layout = this.panel.layout;
350
351     }
352 });