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).data, 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                     },
94                     remoteSort : true,
95                     sortInfo : { field : 'name', direction: 'ASC' },
96                     proxy : {
97                         xtype: 'HttpProxy',
98                         xns: Roo.data,
99                         method : 'GET',
100                         url : baseURL + '/Roo/Office.php'
101                     },
102                     reader : {
103                         xtype: 'JsonReader',
104                         xns: Roo.data,
105                         totalProperty : 'total',
106                         root : 'data',
107                         id : 'id',
108                         fields : [
109                             {
110                                 'name': 'id',
111                                 'type': 'int'
112                             },
113                             {
114                                 'name': 'company_id',
115                                 'type': 'int'
116                             },
117                             {
118                                 'name': 'name',
119                                 'type': 'string'
120                             },
121                             {
122                                 'name': 'address',
123                                 'type': 'string'
124                             },
125                             {
126                                 'name': 'phone',
127                                 'type': 'string'
128                             },
129                             {
130                                 'name': 'fax',
131                                 'type': 'string'
132                             },
133                             {
134                                 'name': 'email',
135                                 'type': 'string'
136                             },
137                             {
138                                 'name': 'role',
139                                 'type': 'string'
140                             },
141                             {
142                                 'name': 'company_id_code',
143                                 'type': 'string'
144                             },
145                             {
146                                 'name': 'company_id_name',
147                                 'type': 'string'
148                             },
149                             {
150                                 'name': 'company_id_remarks',
151                                 'type': 'string'
152                             },
153                             {
154                                 'name': 'company_id_owner_id',
155                                 'type': 'int'
156                             },
157                             {
158                                 'name': 'company_id_address',
159                                 'type': 'string'
160                             },
161                             {
162                                 'name': 'company_id_tel',
163                                 'type': 'string'
164                             },
165                             {
166                                 'name': 'company_id_fax',
167                                 'type': 'string'
168                             },
169                             {
170                                 'name': 'company_id_email',
171                                 'type': 'string'
172                             },
173                             {
174                                 'name': 'company_id_id',
175                                 'type': 'int'
176                             },
177                             {
178                                 'name': 'company_id_isOwner',
179                                 'type': 'int'
180                             },
181                             {
182                                 'name': 'company_id_logo_id',
183                                 'type': 'int'
184                             },
185                             {
186                                 'name': 'company_id_background_color',
187                                 'type': 'string'
188                             },
189                             {
190                                 'name': 'company_id_comptype',
191                                 'type': 'string'
192                             },
193                             {
194                                 'name': 'company_id_url',
195                                 'type': 'string'
196                             },
197                             {
198                                 'name': 'company_id_main_office_id',
199                                 'type': 'int'
200                             },
201                             {
202                                 'name': 'company_id_created_by',
203                                 'type': 'int'
204                             },
205                             {
206                                 'name': 'company_id_created_dt',
207                                 'type': 'date'
208                             },
209                             {
210                                 'name': 'company_id_updated_by',
211                                 'type': 'int'
212                             },
213                             {
214                                 'name': 'company_id_updated_dt',
215                                 'type': 'date'
216                             },
217                             {
218                                 'name': 'company_id_passwd',
219                                 'type': 'string'
220                             },
221                             {
222                                 'name': 'company_id_dispatch_port',
223                                 'type': 'string'
224                             },
225                             {
226                                 'name': 'company_id_province',
227                                 'type': 'string'
228                             },
229                             {
230                                 'name': 'company_id_country',
231                                 'type': 'string'
232                             }
233                         ]
234                     }
235                 },
236                 footer : {
237                     xtype: 'PagingToolbar',
238                     xns: Roo,
239                     pageSize : 25,
240                     displayInfo : true,
241                     displayMsg : 'Displaying Office{0} - {1} of {2}',
242                     emptyMsg : 'No Office found'
243                 },
244                 toolbar : {
245                     xtype: 'Toolbar',
246                     xns: Roo,
247                     items : [
248                         {
249                             xtype: 'Button',
250                             xns: Roo.Toolbar,
251                             listeners : {
252                                 click : function()
253                                 {
254                                     if (!_this.dialog) return;
255                                     
256                                     var cdata = Pman.Tab.AdminCompanies.grid.getSelectionModel().getSelected().data;
257                                     _dialog.show( { 
258                                         id : 0 ,
259                                         company_name : cdata.name,
260                                         company_id : cdata.id,
261                                         address : cdata.address,
262                                         phone : cdata.tel,
263                                         fax : cdata.fax,
264                                         email  : cdata.email
265                                     } , function() {
266                                         _this.grid.footer.onClick('first');
267                                    });
268                                 }
269                             },
270                             cls : 'x-btn-text-icon',
271                             text : "Add",
272                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
273                         },
274                         {
275                             xtype: 'Button',
276                             xns: Roo.Toolbar,
277                             listeners : {
278                                 click : function()
279                                 {
280                                     var s = _this.grid.getSelectionModel().getSelections();
281                                     if (!s.length || (s.length > 1))  {
282                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
283                                         return;
284                                     }
285                                     if (!_this.dialog) return;
286                                     s[0].data.company_name = Pman.Tab.AdminCompanies.grid.getSelectionModel().getSelected().data.name;
287                                     _this.dialog.show(s[0].data, function() {
288                                         _this.grid.footer.onClick('first');
289                                     }); 
290                                     
291                                 }
292                             },
293                             cls : 'x-btn-text-icon',
294                             text : "Edit",
295                             icon : Roo.rootURL + 'images/default/tree/leaf.gif'
296                         },
297                         {
298                             xtype: 'Button',
299                             xns: Roo.Toolbar,
300                             text : "Delete",
301                             cls : 'x-btn-text-icon',
302                             icon : rootURL + '/Pman/templates/images/trash.gif',
303                             listeners : {
304                                 click : function()
305                                 {
306                                      Pman.genericDelete(_this, 'Office'); 
307                                 }
308                             }
309                         }
310                     ]
311                 },
312                 colModel : [
313                     {
314                         xtype: 'ColumnModel',
315                         xns: Roo.grid,
316                         dataIndex : 'name',
317                         header : 'Name / Department / Sub Comp.',
318                         sortable : true,
319                         width : 200,
320                         renderer : function(v) { return String.format('{0}', v); }
321                     },
322                     {
323                         xtype: 'ColumnModel',
324                         xns: Roo.grid,
325                         dataIndex : 'phone',
326                         header : 'Phone',
327                         width : 100,
328                         renderer : function(v) { return String.format('{0}', v); }
329                     },
330                     {
331                         xtype: 'ColumnModel',
332                         xns: Roo.grid,
333                         dataIndex : 'fax',
334                         header : 'Fax',
335                         width : 100,
336                         renderer : function(v) { return String.format('{0}', v); }
337                     },
338                     {
339                         xtype: 'ColumnModel',
340                         xns: Roo.grid,
341                         dataIndex : 'email',
342                         header : 'Email',
343                         width : 200,
344                         renderer : function (v) {
345                             return (v.length && v.indexOf('@') > 0 ) ? 
346                                 String.format('<a href="mailto:{0}">{0}</a>',v) : v;
347                                 
348                         }
349                     },
350                     {
351                         xtype: 'ColumnModel',
352                         xns: Roo.grid,
353                         dataIndex : 'address',
354                         header : 'Address',
355                         width : 300,
356                         renderer : function(v) { return String.format('{0}', v); }
357                     }
358                 ]
359             }
360         });
361         this.layout = this.panel.layout;
362
363     }
364 });