sync
[Pman.Admin] / old / Pman.Tab.ProjectMgr.js
1 //<script type="text/javascript">
2   
3 // tab on left...  
4 Pman.on('beforeload', function()
5 {
6     //                case 1 : Pman.Tab.Projects.add(this.mainLayout, 'west'); break;
7     
8     return;
9     if (!Pman.hasPerm('Core.Projects_All', 'E')) {
10         return;
11     }
12     Pman.register({
13         modKey : '010-pman-tab-projectmgr',
14         module : Pman.Tab.ProjectsMgr,
15         region : 'center',
16         parent : Pman.Tab.Admin,
17         name : "Project Manager"
18     });
19 });
20  
21    
22
23 Pman.Tab.ProjectsMgr = {
24     grid : false,
25     panel : false,
26     disabled:  false,
27     filter : 'P,N,U',
28     searchBox : false,
29     add : function(parentLayout, region) {
30         if (this.disabled) {
31             return;
32         }
33         // add to the menu!!
34         Pman.subMenuItems.push({
35                 seqid : 401,
36                 text: "Add Project",
37                 cls: 'x-btn-text-icon',
38                 icon: Ext.rootURL + 'images/default/dd/drop-add.gif',
39                 
40                 handler : function() {
41                     Pman.Dialog.CoreProject.show( 
42                         { 
43                             id : 0
44                         },
45                         function(data) {
46                             Pman.refreshActivePanel();
47                     }); 
48                 }
49         });
50         Pman.subMenuItems.push( new Roo.menu.Separator({
51             seqid : 402
52         }));
53         
54         
55         if (this.panel) {
56             parentLayout.getRegion(region).showPanel(this.panel);
57             return;
58         }
59      
60         
61         this.innerLayout = new Ext.BorderLayout(
62             parentLayout.getEl().createChild({tag:'div'}),
63             {
64                
65                 center: {
66                     autoScroll:true,
67                     hideTabs: true
68                 }
69             }
70         );
71
72         var _this = this;
73
74         this.tab = parentLayout.add(region,  new Ext.NestedLayoutPanel(
75             this.innerLayout, {title: "Projects", background: true}));
76             
77         this.tab.on('activate', function() {
78            // console.log('activate');
79             _this.delayedCreate();
80             _this.paging.onClick('refresh');
81         });
82     },
83     delayedCreate :  function() 
84     {
85         if (this.grid) {
86             return;
87         }
88         var _this = this;
89         this.innerLayout.beginUpdate();
90         var refreshPager = function() {
91             _this.paging.onClick('refresh');
92         }
93
94         var frm = this.innerLayout.getEl().createChild({tag:'div'});
95         //this.grid = new Ext.grid.EditorGrid(frm,  {
96         this.grid = new Ext.grid.Grid(frm,  {
97                 id: 'grid-projectsmgr',
98                 ds:   new Ext.data.Store({
99                     // load using HTTP
100                     proxy: new Ext.data.HttpProxy({
101                         url: baseURL + '/Roo/core_project.php',
102                         method: 'GET'
103                     }),
104                     remoteSort: true,
105                     reader: Pman.Readers.Projects,
106                      
107                     listeners : {
108                         
109                         beforeload: function(t, o) {
110                             //console.log(o.params);
111                             // teams!?!
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                         },
118                         loadexception : Pman.loadException
119                     
120                     },
121                     sortInfo: {
122                         field: 'code', direction: 'DESC'
123                     }
124                 }),
125                 cm: new Ext.grid.ColumnModel(
126                     [
127                     {
128                     //    id : 'Projects-type',
129                         header : "Type",
130                         dataIndex : 'type',
131                         sortable : true,
132                         width : 130,
133                         renderer : function(v)
134                         {
135                             return _this.typeToString(v)
136                         }
137                     },
138                     
139                     {
140                        // id : 'Projects-code',
141                         header : "Code",
142                         dataIndex : 'code',
143                         sortable : true,
144                         width : 70
145                     }, 
146                     {
147                      //   id : 'Projects-name',
148                         header : "Project Name",
149                         dataIndex : 'name',
150                         sortable : true,
151                         width : 300
152                     },
153                     {
154                      //   id : 'Projects-name',
155                         header : "Client",
156                         dataIndex : 'client_id_name',
157                         sortable : true,
158                         width : 150
159                     },
160                     {
161                      //   id : 'Projects-name',
162                         header : "Team",
163                         dataIndex : 'team_id_name',
164                         sortable : true,
165                         width : 100
166                     },
167                     
168                     
169                     {
170                         id : 'projects-remarks',
171                         header : "Remarks",
172                         dataIndex : 'remarks',
173                         sortable : true,
174                         width : 300
175                     }  ]
176                 ),
177                 autoExpandColumn: 'projects-remarks' , // fixme!!!!
178                 clicksToEdit : 1,
179                 
180                 loadMask: true,
181
182                 listeners: {
183                     
184                     rowdblclick : function(g, ri, e) {
185                         var s = g.getDataSource().getAt(ri).data;
186                       
187                         _dialog.show(s, refreshPager); 
188                     }
189                 }
190                  
191         });
192         this.panel  = this.innerLayout.add('center',  new Ext.GridPanel(this.grid ,
193             { fitToframe: true,fitContainer: true })
194         );
195         this.grid.render();
196         var gridFoot = this.grid.getView().getFooterPanel(true);
197         this.paging = new Ext.PagingToolbar(gridFoot, this.grid.getDataSource(), {
198             pageSize: 25,
199             displayInfo: true,
200             displayMsg: "",
201             emptyMsg: ""
202         });
203         var grid = this.grid;
204  
205         var gridHead = this.grid.getView().getHeaderPanel(true);
206         var tb = new Ext.Toolbar(gridHead);
207         
208        
209         this.searchBox = new Ext.form.TextField({
210             name: 'search',
211             width:135,
212             listeners : {
213                 specialkey : function(f,e)
214                 {
215                     
216                     if (e.getKey() == 13) {
217                         
218                         refreshPager();
219                     } 
220                    
221                 
222                 }
223             }
224          
225         });
226     
227        
228         var _dialog = Pman.Dialog.CoreProject;
229         tb.add(
230             {
231                 text: "Add",
232                 cls: 'x-btn-text-icon',
233                 icon: Ext.rootURL + 'images/default/dd/drop-add.gif',
234                 handler : function(){
235                     _dialog.show( { id: 0 }, refreshPager); 
236                 }
237             }, 
238             {
239                 text: "Edit",
240                 cls: 'x-btn-text-icon',
241                 icon: Ext.rootURL + 'images/default/tree/leaf.gif',
242                    
243                 handler : function(){
244                     var s = grid.getSelectionModel().getSelections();
245                     if (!s.length || (s.length > 1))  {
246                         Ext.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
247                         return;
248                     }
249                     _dialog.show(s[0].data, refreshPager); 
250                 }
251             }, '-',
252             'Search: ',
253             this.searchBox,
254             {
255                 
256                
257                 icon: rootURL + '/Pman/templates/images/search.gif', // icons can also be specified inline
258                 cls: 'x-btn-icon',
259                 qtip: "Search",
260                 handler : function () {
261                     //_this.grid.getSelectionModel().clearSelections();
262                     refreshPager();
263                 }
264             },   
265              {
266                 
267                
268                 icon: rootURL + '/Pman/templates/images/edit-clear.gif', // icons can also be specified inline
269                 cls: 'x-btn-icon',
270                 qtip: "Reset Search",
271                 handler : function () {
272                     _this.searchBox.setValue('');
273                     //_this.grid.getSelectionModel().clearSelections();
274                     refreshPager();
275                 }
276             },
277             '-',
278             'Show : ',
279             {
280                 text: "All",
281                 toggleGroup : 'pgrp',
282                 pressed : true,
283                 enableToggle: true,
284                 toggleHandler : function(b, st) { if (st) { _this.filter = 'P,N,U'; } refreshPager();}
285             },
286             {
287                 text: "Projects",
288                 toggleGroup : 'pgrp',
289                 pressed : false,
290                 enableToggle: true,
291                 toggleHandler : function(b, st) { if (st) { _this.filter = 'P,U'; } refreshPager();}
292             },
293             {
294                 text: "Non-Projects",
295                 toggleGroup : 'pgrp',
296                 pressed : false,
297                 enableToggle: true,
298                 toggleHandler : function(b, st) { if (st) { _this.filter = 'N'; } refreshPager();}
299             },
300             {
301                 text: "Closed",
302                 toggleGroup : 'pgrp',
303                 pressed : false,
304                 enableToggle: true,
305                 toggleHandler : function(b, st) { if (st) { _this.filter = 'X,C'; } refreshPager();}
306             }
307              
308         );
309         
310             
311         //this.toolbar = tb;
312         // add stuff to toolbar?
313         this.innerLayout.endUpdate();
314         
315          // _this.paging.onClick('refresh');
316         
317     },
318     show: function (parentLayout, region)
319     {
320         this.add(parentLayout, region);
321         this.grid.getDataSource().load({
322             params: {
323                 start:0, 
324                 limit:25
325             }
326         });
327
328     },
329     
330     getTypes: function()
331     {
332         //return Pman.Dialog.Projects.getTypes();
333         // we need to decide where this list goes.. 
334         return [
335             [  'U' , "Project (Unconfirmed)" ],
336             [  'P' , "Project" ],
337             [  'C' , "Project (Closed)" ],
338             [  'N' , "Non-Project" ],
339             [  'X' , "Non-Project (Closed)" ]
340         
341         ];
342     },
343     typeToString : function(v)
344     {
345         var ar = this.getTypes();
346         var ret = '';
347         Ext.each(ar, function(a) {
348             if (a[0] == v) {
349                 ret = a[1];
350                 return false;
351             }
352         });
353         return ret;
354     }
355     
356     
357     
358 };   
359