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