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