sync
[Pman.Admin] / old / Pman.Tab.AdminProjects.js
1 //<script type="text/javascript"> 
2        
3 // Auto generated file build Builder
4
5             
6        
7 // register the module first       
8 Pman.on('beforeload', function()
9 {
10
11     if (Pman.Login.authUser.company_id_comptype != 'OWNER') {
12         return;
13     }
14     
15     if (!Pman.hasPerm('Core.Projects_All', 'S')) {
16         return;
17     }
18     
19     Pman.register({
20         modKey : '010-pman_tab_adminprojects',
21         module : Pman.Tab.AdminProjects,
22         region : 'center',
23         parent : Pman.Tab.Admin,
24         name : "Admin - Projects"
25     });
26 });
27
28 Pman.Tab.AdminProjects = {
29     
30     panel : false,
31     disabled : false,
32     parentLayout:  false,
33
34     add : function(parentLayout, region)
35     {
36         
37         if (this.disabled) {
38             return;
39         }
40         var _this = this;
41         this.parentLayout = parentLayout;
42         
43         this.panel = this.parentLayout.addxtype({
44             xtype : 'GridPanel',
45             title : "Projects",
46             fitToframe : true,
47             fitContainer : true,
48             tableName : 'Projects',
49             background : true,
50             listeners : {
51                 activate: function() {
52                     _this.panel = this;
53                   
54                     
55                       if (_this.grid && _this.grid.rendered) {
56                         _this.grid.footer.onClick('first');
57                     }
58                 }
59             },
60             grid : {
61                 xtype : 'Grid',
62                 autoExpandColumn : 'remarks',
63                 loadMask : true,
64                 listeners : {
65                     render: function() { 
66                     
67                         _this.grid = this; 
68                         _this.dialog = Pman.Dialog.CoreProject;
69                         _this.filter =  'P,U';
70                         _this.getTypes = function()
71                         {
72                             return [
73                                 [  'U' , "Project (Unconfirmed)" ],
74                                 [  'P' , "Project" ],
75                                 [  'C' , "Project (Closed)" ],
76                                 [  'N' , "Non-Project" ],
77                                 [  'X' , "Non-Project (Closed)" ]
78                             
79                             ];
80                         };
81                         _this.typeToString = function(v)
82                         {
83                             var ar = this.getTypes();
84                             var ret = '';
85                             Roo.each(ar, function(a) {
86                                 if (a[0] == v) {
87                                     ret = a[1];
88                                     return false;
89                                 }
90                             });
91                             return ret;
92                         }
93                          _this.grid.footer.onClick('first');
94                     },
95                     rowdblclick: function (g, ri, e)
96                     {
97                         
98                         _this.dialog.show(g.getDataSource().getAt(ri).data, function() {
99                            g.footer.onClick('refresh');
100                         });
101                     }
102                 },
103                 dataSource : {
104                     xtype : 'Store',
105                     reader: Pman.Readers.Projects,
106                     listeners : {
107                         beforeload: function (_self, o)
108                         {
109                             if (!_this.searchBox) {
110                                 return false;
111                             }  
112                             o.params = o.params ? o.params : {};
113                                                     o.params['query[project_search]'] = _this.searchBox.getValue();
114                                                     o.params['query[project_filter]'] = _this.filter;
115                         }
116                     },
117                     sortInfo: {field:'code', direction:'DESC'},
118                     remoteSort : true,
119                     proxy : {
120                         xtype : 'HttpProxy',
121                         method : 'GET',
122                         url: baseURL + '/Roo/core_project.php'
123                     }
124                 },
125                 colModel : [
126                     {
127                         header : 'Type',
128                         width : 70,
129                         dataIndex : 'type',
130                         renderer: function(v) {return _this.typeToString(v); }
131                     },
132                     {
133                         header : 'Code',
134                         width : 90,
135                         dataIndex : 'code',
136                         renderer: function(v) { return String.format('{0}', v); }
137                     },
138                     {
139                         header : 'Project Name',
140                         width : 300,
141                         dataIndex : 'name',
142                         renderer: function(v) { return String.format('{0}', v); }
143                     },
144                     {
145                         header : 'Client ',
146                         width : 100,
147                         dataIndex : 'client_id_name',
148                         renderer: function(v) { return String.format('{0}', v); }
149                     },
150                     {
151                         header : 'Remarks',
152                         width : 300,
153                         dataIndex : 'remarks',
154                         renderer: function(v) { return String.format('{0}', v); }
155                     }
156                 ],
157                 footer : {
158                     xtype : 'PagingToolbar',
159                     pageSize : 25,
160                     displayInfo : true,
161                     displayMsg : "Displaying Projects  {0} - {1} of {2}",
162                     emptyMsg : "No Projects found"
163                 },
164                 toolbar : {
165                     xtype : 'Toolbar',
166                     items : [
167                         {
168                             text : "Add",
169                             xtype : 'Button',
170                             cls : 'x-btn-text-icon',
171                             icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
172                             listeners : {
173                                 click: function()
174                                         {
175                                             _this.dialog.show( { id : 0 }, function() {
176                                                 _this.grid.footer.onClick('first');
177                                 
178                                             }); 
179                                 
180                                         }
181                                         
182                             }
183                         },
184                         {
185                             text : "Edit",
186                             xtype : 'Button',
187                             cls : 'x-btn-text-icon',
188                             icon: Roo.rootURL + 'images/default/tree/leaf.gif',
189                             listeners : {
190                                 click: function()
191                                         {
192                                             var s = _this.grid.getSelectionModel().getSelections();
193                                             if (!s.length || (s.length > 1))  {
194                                                 Roo.MessageBox.alert("Error", s.length ? "Select only one Project" : "Select a Project");
195                                                 return;
196                                             }
197                                             
198                                             _this.dialog.show(s[0].data, function() {
199                                                 _this.grid.footer.onClick('refresh');
200                                                }); 
201                                             
202                                         }
203                                         
204                             }
205                         },
206                         {
207                             xtype : 'Separator',
208                             xns: Roo.Toolbar
209                         },
210                         {
211                             xtype : 'TextItem',
212                             xns: Roo.Toolbar,
213                             text : "Search:"
214                         },
215                         {
216                             xtype : 'TextField',
217                             xns: Roo.form,
218                             listeners : {
219                                 render: function (_self)
220                                 {
221                                    _this.searchBox = _self;
222                                 },
223                                 specialkey: function (_self, e)
224                                 {
225                                     if(e.getKey() == 13) {
226                                         _this.grid.footer.onClick('first');
227                                     }
228                                 }
229                             },
230                             width : 135
231                         },
232                         {
233                             xtype : 'Button',
234                             xns: Roo.Toolbar,
235                             listeners : {
236                                 click: function (_self, e)
237                                 {
238                                  _this.grid.footer.onClick('first');
239                                 }
240                             },
241                             icon: rootURL + '/Pman/templates/images/search.gif',
242                             cls : 'x-btn-icon'
243                         },
244                         {
245                             xtype : 'Button',
246                             xns: Roo.Toolbar,
247                             listeners : {
248                                 click: function (_self, e)
249                                 {
250                                     _this.searchBox.setValue('');
251                                     _this.grid.footer.onClick('first');
252                                 }
253                             },
254                             icon: rootURL + '/Pman/templates/images/edit-clear.gif',
255                             cls : 'x-btn-icon'
256                         },
257                         {
258                             xtype : 'Separator',
259                             xns: Roo.Toolbar
260                         },
261                         {
262                             xtype : 'TextItem',
263                             xns: Roo.Toolbar,
264                             text : "Show:"
265                         },
266                         {
267                             xtype : 'Button',
268                             xns: Roo.Toolbar,
269                             text : "All",
270                             listeners : {
271                                 toggle: function (_self, st)
272                                 {
273                                 if (st) { _this.filter = 'P,N,U'; } 
274                                     _this.grid.footer.onClick('first');
275                                 }
276                             },
277                             toggleGroup : 'pgrp',
278                             pressed : false,
279                             enableToggle : true
280                         },
281                         {
282                             xtype : 'Button',
283                             xns: Roo.Toolbar,
284                             text : "Projects",
285                             listeners : {
286                                 toggle: function (_self, st)
287                                 {
288                                 if (st) { _this.filter = 'P,U'; } 
289                                     _this.grid.footer.onClick('first');
290                                 }
291                             },
292                             toggleGroup : 'pgrp',
293                             pressed : true,
294                             enableToggle : true
295                         },
296                         {
297                             xtype : 'Button',
298                             xns: Roo.Toolbar,
299                             text : "Non-Projects",
300                             listeners : {
301                                 toggle: function (_self, st)
302                                 {
303                                 if (st) { _this.filter = 'N'; } 
304                                     _this.grid.footer.onClick('first');
305                                 }
306                             },
307                             toggleGroup : 'pgrp',
308                             pressed : false,
309                             enableToggle : true
310                         },
311                         {
312                             xtype : 'Button',
313                             xns: Roo.Toolbar,
314                             text : "Closed",
315                             listeners : {
316                                 toggle: function (_self, st)
317                                 {
318                                 if (st) { _this.filter = 'X,C'; } 
319                                     _this.grid.footer.onClick('first');
320                                 }
321                             },
322                             toggleGroup : 'pgrp',
323                             pressed : false,
324                             enableToggle : true
325                         }
326                     ]
327                 },
328                 selModel : {
329                     xtype : 'RowSelectionModel',
330                     xns: Roo.grid,
331                     singleSelect : true
332                 }
333             },
334             region : 'center'
335         });
336
337         
338         
339     }
340 }