old/Pman.Tab.AdminPermManager.bjs
[Pman.Admin] / old / Pman.Tab.AdminPermManager.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Tab');
6
7 Pman.Tab.AdminPermManager = new Roo.XComponent({
8
9  _strings : {
10   'a37ede293936e29279ed543129451ec3' :"Groups",
11   'ec211f7c20af43e742bf2570c3cb84f9' :"Add",
12   '7dce122004969d56ae2e0245cb754d35' :"Edit",
13   '911051bc8a5abedcc127334f0f70b78a' :"Permission Manager",
14   '4d1c8263ba1036754f8db14a98f9f006' :"Reload",
15   'f2a6c498fb90ee345d997f888fce3b18' :"Delete",
16   '49ee3087348e8d44e1feda1917443987' :"Name",
17   'aba9f7d7443652e858969bfc280690b1' :"Manage Groups"
18  },
19
20   part     :  ["old", "AdminPermManager" ],
21   order    : '700-Pman.Tab.AdminPermManager',
22   region   : 'center',
23   parent   : 'Pman.Tab.Admin',
24   name     : "Pman.Tab.AdminPermManager",
25   disabled : false, 
26   permname : 'Core.Groups', 
27   _tree : function()
28   {
29    var _this = this;
30    var MODULE = this;
31    return {
32    layout : {
33     center : {
34      '|xns' : 'Roo',
35      tabPosition : 'top',
36      xns : Roo,
37      xtype : 'LayoutRegion'
38     },
39     west : {
40      '|xns' : 'Roo',
41      width : 200,
42      xns : Roo,
43      xtype : 'LayoutRegion'
44     },
45     '|xns' : 'Roo',
46     xns : Roo,
47     xtype : 'BorderLayout',
48     items : [
49      {
50       grid : {
51        dataSource : {
52         proxy : {
53          '|xns' : 'Roo.data',
54          method : 'GET',
55          url : baseURL + '/Roo/Groups.php',
56          xns : Roo.data,
57          xtype : 'HttpProxy'
58         },
59         reader : {
60          '|xns' : 'Roo.data',
61          fields : [
62              {
63                  'name': 'id',
64                  'type': 'int'
65              },
66              {
67                  'name': 'name',
68                  'type': 'string'
69              },
70              {
71                  'name': 'type',
72                  'type': 'int'
73              },
74              {
75                  'name': 'leader',
76                  'type': 'int'
77              },
78              {
79                  'name': 'leader_id',
80                  'type': 'int'
81              },
82              {
83                  'name': 'leader_office_id',
84                  'type': 'int'
85              },
86              {
87                  'name': 'leader_name',
88                  'type': 'string'
89              },
90              {
91                  'name': 'leader_phone',
92                  'type': 'string'
93              },
94              {
95                  'name': 'leader_fax',
96                  'type': 'string'
97              },
98              {
99                  'name': 'leader_email',
100                  'type': 'string'
101              },
102              {
103                  'name': 'leader_company_id',
104                  'type': 'int'
105              },
106              {
107                  'name': 'leader_role',
108                  'type': 'string'
109              },
110              {
111                  'name': 'leader_active',
112                  'type': 'int'
113              },
114              {
115                  'name': 'leader_remarks',
116                  'type': 'string'
117              },
118              {
119                  'name': 'leader_passwd',
120                  'type': 'string'
121              },
122              {
123                  'name': 'leader_owner_id',
124                  'type': 'int'
125              },
126              {
127                  'name': 'leader_lang',
128                  'type': 'string'
129              },
130              {
131                  'name': 'leader_no_reset_sent',
132                  'type': 'int'
133              },
134              {
135                  'name': 'leader_action_type',
136                  'type': 'string'
137              },
138              {
139                  'name': 'leader_project_id',
140                  'type': 'int'
141              }
142          ],
143          id : 'id',
144          root : 'data',
145          totalProperty : 'total',
146          xns : Roo.data,
147          xtype : 'JsonReader'
148         },
149         '|xns' : 'Roo.data',
150         remoteSort : true,
151         sortInfo : { field : 'name', direction: 'ASC' },
152         xns : Roo.data,
153         xtype : 'Store',
154         listeners : {
155          beforeload : function (_self, o)
156           {
157               o.params = o.params || {};
158               o.params.type =0;
159           },
160          load : function (_self, records, options)
161           {
162               var sm = _this.grid.getSelectionModel();
163               if (!sm.getSelections().length) {
164                   sm.selectFirstRow();
165               }
166               // should refresh righthand side grid..
167                //   Pman.Tab.AdminContacts.grid.footer.onClick('first');
168           }
169         },
170         items : [
171
172         ]
173
174        },
175        toolbar : {
176         '|xns' : 'Roo',
177         xns : Roo,
178         xtype : 'Toolbar',
179         items : [
180          {
181           menu : {
182            '|xns' : 'Roo.menu',
183            xns : Roo.menu,
184            xtype : 'Menu',
185            items : [
186             {
187              '|xns' : 'Roo.menu',
188              cls : 'x-btn-text-icon',
189              icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
190              text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'],
191              xns : Roo.menu,
192              xtype : 'Item',
193              listeners : {
194               click : function()
195                {
196                    if (!_this.dialog) return;
197                    _this.dialog.show( { id : 0,  type: 0 } , function() {
198                         _this.grid.ds.load({});
199                   }); 
200                }
201              }
202             },
203             {
204              '|xns' : 'Roo.menu',
205              cls : 'x-btn-text-icon',
206              icon : Roo.rootURL + 'images/default/tree/leaf.gif',
207              text : _this._strings['7dce122004969d56ae2e0245cb754d35'],
208              xns : Roo.menu,
209              xtype : 'Item',
210              listeners : {
211               click : function()
212                {
213                    var s = _this.grid.getSelectionModel().getSelections();
214                    if (!s.length || (s.length > 1))  {
215                        Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
216                        return;
217                    }
218                    if (s[0].data.id < 1 ) {
219                        return;
220                    }
221                    if (!_this.dialog) return;
222                    _this.dialog.show(s[0].data, function() {
223                         _this.grid.ds.load({});
224                    }); 
225                    
226                }
227              }
228             },
229             {
230              '|xns' : 'Roo.menu',
231              cls : 'x-btn-text-icon',
232              icon : rootURL + '/Pman/templates/images/trash.gif',
233              text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'],
234              xns : Roo.menu,
235              xtype : 'Item',
236              listeners : {
237               click : function()
238                {
239                     Pman.genericDelete(_this, 'Groups'); 
240                }
241              }
242             },
243             {
244              '|xns' : 'Roo.menu',
245              xns : Roo.menu,
246              xtype : 'Separator'
247             },
248             {
249              '|xns' : 'Roo.menu',
250              text : _this._strings['4d1c8263ba1036754f8db14a98f9f006'],
251              xns : Roo.menu,
252              xtype : 'Item',
253              listeners : {
254               click : function (_self, e)
255                {
256                  _this.grid.ds.load({});
257                }
258              }
259             }
260            ]
261
262           },
263           '|xns' : 'Roo.Toolbar',
264           text : _this._strings['aba9f7d7443652e858969bfc280690b1'],
265           xns : Roo.Toolbar,
266           xtype : 'Button',
267           items : [
268
269           ]
270
271          }
272         ]
273
274        },
275        sm : {
276         '|xns' : 'Roo.grid',
277         singleSelect : true,
278         xns : Roo.grid,
279         xtype : 'RowSelectionModel',
280         listeners : {
281          afterselectionchange : function (_self)
282           {
283               Pman.Tab.AdminPermMembers.grid.footer.onClick('first');
284           }
285         }
286        },
287        dropTarget : {
288         '|xns' : 'Roo.dd',
289         ddGroup : 'groupDD',
290         xns : Roo.dd,
291         xtype : 'DropTarget',
292         listeners : {
293          drop : function (source, e, data)
294           {
295               // Roo.log("DROP");
296               var t = Roo.lib.Event.getTarget(e); 
297               var ri = _this.grid.view.findRowIndex(t);
298               var rid  = false;
299               if (ri !== false) {
300                   rid = _this.grid.getDataSource().getAt(ri).data;
301               }
302               var s = _this.grid.getSelectionModel().getSelections();
303                 
304               //console.log(data);
305               var isFromGroup = s.length ? s[0].data.id > 0 : false;
306           
307               var isToGroup = rid && rid.id > 0;
308               this.success = false;
309               if (isFromGroup && isToGroup) {
310                   return;
311               }
312               if (!isFromGroup && !isToGroup) {
313                   return;
314               }
315               var action = 'add';
316               if (isFromGroup && !isToGroup) {
317                   action = 'sub';
318                   //return 'x-dd-drop-ok-sub'; 
319               }
320               // build a list of selections.
321               var sels = [];
322               for (var i=0; i < data.selections.length; i++) {
323                   sels.push(data.selections[i].data.id);
324               }
325           
326               Pman.request({
327                   url: baseURL + '/Core/GroupMembers.php',
328                   params: {
329                       action : action,
330                       group_id: action =='add' ? rid.id : s[0].data.id,
331                       type: _this.type,
332                       user_ids : sels.join(',')
333                       
334                   },  
335                   method: 'POST',  
336                   success : function(data) {
337                       //refreshPager();
338                       // 
339                       // do we need to do anything??
340                       if (isFromGroup) {
341                           Pman.Tab.AdminPermMembers.grid.footer.onClick('refresh');
342                       }
343                   }, 
344                   
345                   failure: function() {
346                       //Ext.get(document.body).unmask();
347                       //if (cb) {
348                       //    cb.call(false);
349                       //}
350                        
351                   }
352               });
353           
354               this.success = true;
355           
356               //if (!isFromGroup && isToGroup) {
357                   //return 'x-dd-drop-ok-add'; 
358               return;
359               //}
360           },
361          over : function (source, e, data)
362           {
363               // Roo.log("dragover");
364                
365               //Roo.log(e);
366               var t = Roo.lib.Event.getTarget(e); 
367                  //  Roo.log(t);
368               var ri = _this.grid.view.findRowIndex(t);
369                 //            Roo.log(ri);
370               
371               var rid  = false;
372               if (ri !== false) {
373                   rid = _this.grid.getDataSource().getAt(ri).data;
374               }
375               
376               var s = _this.grid.getSelectionModel().getSelections();
377               
378               var isFromGroup = s.length ? s[0].data.id > 0 : false;
379               
380               var isToGroup = rid && rid.id > 0;
381               
382           //    Roo.log("isToGroup:"  + isToGroup + ", isFromGroup" + isFromGroup);
383                
384               if (isFromGroup && isToGroup) {
385                   this.valid = false;
386           //        Roo.log('not valid');
387                   return;
388               }
389               if (!isFromGroup && !isToGroup) {
390                   this.valid = false;
391           //        Roo.log('not valid');
392                   return  
393               }
394               if (isFromGroup && !isToGroup) {
395                   this.valid = 'ok-sub'; 
396                   return;
397               } 
398               //if (!isFromGroup && isToGroup) {
399               this.valid = 'ok-add';
400           //    Roo.log('add'); 
401               //}
402           }
403         }
404        },
405        '|xns' : 'Roo.grid',
406        autoExpandColumn : 'name',
407        ddGroup : 'groupDD',
408        enableDrop : true,
409        loadMask : true,
410        xns : Roo.grid,
411        xtype : 'Grid',
412        colModel : [
413          {
414           '|xns' : 'Roo.grid',
415           dataIndex : 'name',
416           header : _this._strings['49ee3087348e8d44e1feda1917443987'],
417           renderer : function(v,x,r) { 
418               if (r.data.id == -1) {
419                   return '<b>' + "Not in a Group" + '</b>';
420               }
421               if ((r.data.id == 0) && (_this.type == 0)) {
422                   return '<b>' + "All Staff (Default Permissions)" + '</b>';
423               }
424               if ((r.data.id == 0) && (_this.type == 2)) {
425                   return '<b>' + "Everybody" + '</b>';
426               }
427               if (r.data.id == 0) {
428                   return '<b>' + "All Staff" + '</b>';
429               }
430               if (v == 'Administrators') {
431                   return '<b>' + "Adminstrators" + '</b>';
432               }
433               if (r.data.leader) {
434                   return v + ' (' + r.data.leader_name + ')';
435               }
436               
437               return v;
438           },
439           width : 200,
440           xns : Roo.grid,
441           xtype : 'ColumnModel'
442          }
443        ],
444        listeners : {
445         render : function() 
446          {
447              _this.grid = this; 
448              _this.dialog = Pman.Dialog.Groups;
449              if (_this.panel.active) {
450                  _this.grid.ds.load({});
451              }
452          },
453         rowdblclick : function (_self, rowIndex, e)
454          {
455              if (!_this.dialog) return;
456              var s = this.getDataSource().getAt(rowIndex);
457              if (s.data.id < 1 ) {
458                  return;
459              }
460              _this.dialog.show( s.data, function() {
461                  _this.ds.load({});
462              }); 
463          }
464        },
465        items : [
466
467        ]
468
469       },
470       '|xns' : 'Roo',
471       background : true,
472       fitContainer : true,
473       fitToframe : true,
474       region : 'west',
475       tableName : 'Groups',
476       title : _this._strings['a37ede293936e29279ed543129451ec3'],
477       xns : Roo,
478       xtype : 'GridPanel',
479       listeners : {
480        activate : function() {
481             _this.panel = this;
482             if (_this.grid) {
483                 _this.grid.ds.load({});
484             }
485         }
486       },
487       items : [
488
489       ]
490
491      }
492     ]
493
494    },
495    '|xns' : 'Roo',
496    background : true,
497    region : 'center',
498    title : _this._strings['911051bc8a5abedcc127334f0f70b78a'],
499    xns : Roo,
500    xtype : 'NestedLayoutPanel',
501    items : [
502
503    ]
504
505   };  }
506 });