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 : 'south',
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                             listeners : {
251                                 click : function()
252                                 {
253                                     if (!_this.dialog) return;
254                                     
255                                     var cdata = Pman.Tab.AdminCompanies.grid.getSelectionModel().getSelected().data;
256                                     _dialog.show( { 
257                                         id : 0 ,
258                                         company_name : cdata.name,
259                                         company_id : cdata.id,
260                                         address : cdata.address,
261                                         phone : cdata.tel,
262                                         fax : cdata.fax,
263                                         email  : cdata.email
264                                     } , function() {
265                                         _this.grid.footer.onClick('first');
266                                    });
267                                 }
268                             },
269                             cls : 'x-btn-text-icon',
270                             text : "Add",
271                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
272                         },
273                         {
274                             xtype: 'Button',
275                             xns: Roo.Toolbar,
276                             listeners : {
277                                 click : function()
278                                 {
279                                     var s = _this.grid.getSelectionModel().getSelections();
280                                     if (!s.length || (s.length > 1))  {
281                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
282                                         return;
283                                     }
284                                     if (!_this.dialog) return;
285                                     s[0].data.company_name = Pman.Tab.AdminCompanies.grid.getSelectionModel().getSelected().data.name;
286                                     _this.dialog.show(s[0].data, function() {
287                                         _this.grid.footer.onClick('first');
288                                     }); 
289                                     
290                                 }
291                             },
292                             cls : 'x-btn-text-icon',
293                             text : "Edit",
294                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
295                         },
296                         {
297                             xtype: 'Button',
298                             xns: Roo.Toolbar,
299                             text : "Delete",
300                             cls : 'x-btn-text-icon',
301                             icon : rootURL + '/Pman/templates/images/trash.gif',
302                             listeners : {
303                                 click : function()
304                                 {
305                                      Pman.genericDelete(_this, 'Office'); 
306                                 }
307                             }
308                         }
309                     ]
310                 },
311                 colModel : [
312                     {
313                         xtype: 'ColumnModel',
314                         xns: Roo.grid,
315                         dataIndex : 'name',
316                         header : 'Name / Department / Sub Comp.',
317                         sortable : true,
318                         width : 200,
319                         renderer : function(v) { return String.format('{0}', v); }
320                     },
321                     {
322                         xtype: 'ColumnModel',
323                         xns: Roo.grid,
324                         dataIndex : 'phone',
325                         header : 'Phone',
326                         width : 100,
327                         renderer : function(v) { return String.format('{0}', v); }
328                     },
329                     {
330                         xtype: 'ColumnModel',
331                         xns: Roo.grid,
332                         dataIndex : 'fax',
333                         header : 'Fax',
334                         width : 100,
335                         renderer : function(v) { return String.format('{0}', v); }
336                     },
337                     {
338                         xtype: 'ColumnModel',
339                         xns: Roo.grid,
340                         dataIndex : 'email',
341                         header : 'Email',
342                         width : 200,
343                         renderer : function (v) {
344                             return (v.length && v.indexOf('@') > 0 ) ? 
345                                 String.format('<a href="mailto:{0}">{0}</a>',v) : v;
346                                 
347                         }
348                     },
349                     {
350                         xtype: 'ColumnModel',
351                         xns: Roo.grid,
352                         dataIndex : 'address',
353                         header : 'Address',
354                         width : 300,
355                         renderer : function(v) { return String.format('{0}', v); }
356                     }
357                 ]
358             }
359         });
360         this.layout = this.panel.layout;
361
362     }
363 });