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    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['aba9f7d7443652e858969bfc280690b1'] /* 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          load : function (_self, records, options)
207           {
208               var sm = _this.grid.getSelectionModel();
209               if (!sm.getSelections().length) {
210                   sm.selectFirstRow();
211               }
212               // should refresh righthand side grid..
213                //   Pman.Tab.AdminContacts.grid.footer.onClick('first');
214           }
215         },
216         xns : Roo.data,
217         '|xns' : 'Roo.data',
218         proxy : {
219          xtype : 'HttpProxy',
220          method : 'GET',
221          url : baseURL + '/Roo/Groups.php',
222          xns : Roo.data,
223          '|xns' : 'Roo.data'
224         },
225         reader : {
226          xtype : 'JsonReader',
227          fields : [
228              {
229                  'name': 'id',
230                  'type': 'int'
231              },
232              {
233                  'name': 'name',
234                  'type': 'string'
235              },
236              {
237                  'name': 'type',
238                  'type': 'int'
239              },
240              {
241                  'name': 'leader',
242                  'type': 'int'
243              },
244              {
245                  'name': 'leader_id',
246                  'type': 'int'
247              },
248              {
249                  'name': 'leader_office_id',
250                  'type': 'int'
251              },
252              {
253                  'name': 'leader_name',
254                  'type': 'string'
255              },
256              {
257                  'name': 'leader_phone',
258                  'type': 'string'
259              },
260              {
261                  'name': 'leader_fax',
262                  'type': 'string'
263              },
264              {
265                  'name': 'leader_email',
266                  'type': 'string'
267              },
268              {
269                  'name': 'leader_company_id',
270                  'type': 'int'
271              },
272              {
273                  'name': 'leader_role',
274                  'type': 'string'
275              },
276              {
277                  'name': 'leader_active',
278                  'type': 'int'
279              },
280              {
281                  'name': 'leader_remarks',
282                  'type': 'string'
283              },
284              {
285                  'name': 'leader_passwd',
286                  'type': 'string'
287              },
288              {
289                  'name': 'leader_owner_id',
290                  'type': 'int'
291              },
292              {
293                  'name': 'leader_lang',
294                  'type': 'string'
295              },
296              {
297                  'name': 'leader_no_reset_sent',
298                  'type': 'int'
299              },
300              {
301                  'name': 'leader_action_type',
302                  'type': 'string'
303              },
304              {
305                  'name': 'leader_project_id',
306                  'type': 'int'
307              }
308          ],
309          id : 'id',
310          root : 'data',
311          totalProperty : 'total',
312          xns : Roo.data,
313          '|xns' : 'Roo.data'
314         }
315        },
316        dropTarget : {
317         xtype : 'DropTarget',
318         ddGroup : 'groupDD',
319         listeners : {
320          drop : function (source, e, data)
321           {
322               // Roo.log("DROP");
323               var t = Roo.lib.Event.getTarget(e); 
324               var ri = _this.grid.view.findRowIndex(t);
325               var rid  = false;
326               if (ri !== false) {
327                   rid = _this.grid.getDataSource().getAt(ri).data;
328               }
329               var s = _this.grid.getSelectionModel().getSelections();
330                 
331               //console.log(data);
332               var isFromGroup = s.length ? s[0].data.id > 0 : false;
333           
334               var isToGroup = rid && rid.id > 0;
335               this.success = false;
336               if (isFromGroup && isToGroup) {
337                   return;
338               }
339               if (!isFromGroup && !isToGroup) {
340                   return;
341               }
342               var action = 'add';
343               if (isFromGroup && !isToGroup) {
344                   action = 'sub';
345                   //return 'x-dd-drop-ok-sub'; 
346               }
347               // build a list of selections.
348               var sels = [];
349               for (var i=0; i < data.selections.length; i++) {
350                   sels.push(data.selections[i].data.id);
351               }
352           
353               Pman.request({
354                   url: baseURL + '/Core/GroupMembers.php',
355                   params: {
356                       action : action,
357                       group_id: action =='add' ? rid.id : s[0].data.id,
358                       type: _this.type,
359                       user_ids : sels.join(',')
360                       
361                   },  
362                   method: 'POST',  
363                   success : function(data) {
364                       //refreshPager();
365                       // 
366                       // do we need to do anything??
367                       if (isFromGroup) {
368                           Pman.Tab.AdminPermMembers.grid.footer.onClick('refresh');
369                       }
370                   }, 
371                   
372                   failure: function() {
373                       //Ext.get(document.body).unmask();
374                       //if (cb) {
375                       //    cb.call(false);
376                       //}
377                        
378                   }
379               });
380           
381               this.success = true;
382           
383               //if (!isFromGroup && isToGroup) {
384                   //return 'x-dd-drop-ok-add'; 
385               return;
386               //}
387           },
388          over : function (source, e, data)
389           {
390               // Roo.log("dragover");
391                
392               //Roo.log(e);
393               var t = Roo.lib.Event.getTarget(e); 
394                  //  Roo.log(t);
395               var ri = _this.grid.view.findRowIndex(t);
396                 //            Roo.log(ri);
397               
398               var rid  = false;
399               if (ri !== false) {
400                   rid = _this.grid.getDataSource().getAt(ri).data;
401               }
402               
403               var s = _this.grid.getSelectionModel().getSelections();
404               
405               var isFromGroup = s.length ? s[0].data.id > 0 : false;
406               
407               var isToGroup = rid && rid.id > 0;
408               
409           //    Roo.log("isToGroup:"  + isToGroup + ", isFromGroup" + isFromGroup);
410                
411               if (isFromGroup && isToGroup) {
412                   this.valid = false;
413           //        Roo.log('not valid');
414                   return;
415               }
416               if (!isFromGroup && !isToGroup) {
417                   this.valid = false;
418           //        Roo.log('not valid');
419                   return  
420               }
421               if (isFromGroup && !isToGroup) {
422                   this.valid = 'ok-sub'; 
423                   return;
424               } 
425               //if (!isFromGroup && isToGroup) {
426               this.valid = 'ok-add';
427           //    Roo.log('add'); 
428               //}
429           }
430         },
431         xns : Roo.dd,
432         '|xns' : 'Roo.dd'
433        },
434        sm : {
435         xtype : 'RowSelectionModel',
436         singleSelect : true,
437         listeners : {
438          afterselectionchange : function (_self)
439           {
440               Pman.Tab.AdminPermMembers.grid.footer.onClick('first');
441           }
442         },
443         xns : Roo.grid,
444         '|xns' : 'Roo.grid'
445        },
446        colModel : [
447         {
448          xtype : 'ColumnModel',
449          dataIndex : 'name',
450          header : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
451          renderer : function(v,x,r) { 
452              if (r.data.id == -1) {
453                  return '<b>' + "Not in a Group" + '</b>';
454              }
455              if ((r.data.id == 0) && (_this.type == 0)) {
456                  return '<b>' + "All Staff (Default Permissions)" + '</b>';
457              }
458              if ((r.data.id == 0) && (_this.type == 2)) {
459                  return '<b>' + "Everybody" + '</b>';
460              }
461              if (r.data.id == 0) {
462                  return '<b>' + "All Staff" + '</b>';
463              }
464              if (v == 'Administrators') {
465                  return '<b>' + "Adminstrators" + '</b>';
466              }
467              if (r.data.leader) {
468                  return v + ' (' + r.data.leader_name + ')';
469              }
470              
471              return v;
472          },
473          width : 200,
474          xns : Roo.grid,
475          '|xns' : 'Roo.grid'
476         }
477        ]
478       }
479      }
480     ]
481    }
482   };  }
483 });