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