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