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