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