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