Pman.Dialog.AdminCoreEnum.bjs
[Pman.Admin] / Pman.Tab.AdminCountries.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Tab.AdminCountries = new Roo.XComponent({
6     part     :  ["Admin","Countries"],
7     order    : '001-Pman.Tab.AdminCountries',
8     region   : 'center',
9     parent   : 'Pman.Tab.AdminContactsManager',
10     name     : "Pman.Tab.AdminCountries",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'GridPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function (_self)
22                 {
23                     _this.panel = this;
24                     if (_this.grid){
25                         _this.grid.ds.load({});
26                     }
27                 }
28             },
29             background : true,
30             fitContainer : true,
31             fitToFrame : true,
32             region : 'west',
33             tableName : 'Person',
34             title : "Countries",
35             grid : {
36                 xtype: 'Grid',
37                 xns: Roo.grid,
38                 listeners : {
39                     render : function() 
40                     {
41                         _this.grid = this; 
42                         //_this.dialog = Pman.Dialog.Groups;
43                         if (_this.panel.active) {
44                             _this.grid.ds.load({});
45                         }
46                     },
47                     rowdblclick : function (_self, rowIndex, e)
48                     {
49                         if (!_this.dialog) return;
50                         var s = this.getDataSource().getAt(rowIndex);
51                         if (s.data.id < 1 ) {
52                             return;
53                         }
54                         _this.dialog.show( s.data, function() {
55                             _this.ds.load({});
56                         }); 
57                     }
58                 },
59                 autoExpandColumn : 'country',
60                 ddGroup : 'groupDD',
61                 enableDrop : true,
62                 loadMask : true,
63                 dataSource : {
64                     xtype: 'Store',
65                     xns: Roo.data,
66                     listeners : {
67                         beforeload : function (_self, o)
68                         {
69                             o.params = o.params || {};
70                             o.params._distinct = 'country';
71                             o.params._columns = 'country,country_tr';
72                             o.params.limit = 9999;
73                             o.params._hideEmptyCountry = 1;
74                         },
75                         load : function (_self, records, options)
76                         {
77                             var sm = _this.grid.getSelectionModel();
78                                 if (!sm.getSelections().length) {
79                                     sm.selectFirstRow();
80                                 }
81                                 Pman.Tab.AdminContacts.grid.footer.onClick('first');
82                         }
83                     },
84                     remoteSort : true,
85                     sortInfo : { field : 'country_tr', direction: 'ASC' },
86                     proxy : {
87                         xtype: 'HttpProxy',
88                         xns: Roo.data,
89                         method : 'GET',
90                         url : baseURL + '/Roo/Clipping.php'
91                     },
92                     reader : {
93                         xtype: 'JsonReader',
94                         xns: Roo.data,
95                         totalProperty : 'total',
96                         root : 'data',
97                         id : 'id',
98                         fields : [
99                             {
100                                 'name': 'id',
101                                 'type': 'int'
102                             },
103                             {
104                                 'name': 'name',
105                                 'type': 'string'
106                             },
107                             {
108                                 'name': 'type',
109                                 'type': 'int'
110                             },
111                             {
112                                 'name': 'leader',
113                                 'type': 'int'
114                             },
115                             {
116                                 'name': 'leader_id',
117                                 'type': 'int'
118                             },
119                             {
120                                 'name': 'leader_office_id',
121                                 'type': 'int'
122                             },
123                             {
124                                 'name': 'leader_name',
125                                 'type': 'string'
126                             },
127                             {
128                                 'name': 'leader_phone',
129                                 'type': 'string'
130                             },
131                             {
132                                 'name': 'leader_fax',
133                                 'type': 'string'
134                             },
135                             {
136                                 'name': 'leader_email',
137                                 'type': 'string'
138                             },
139                             {
140                                 'name': 'leader_company_id',
141                                 'type': 'int'
142                             },
143                             {
144                                 'name': 'leader_role',
145                                 'type': 'string'
146                             },
147                             {
148                                 'name': 'leader_active',
149                                 'type': 'int'
150                             },
151                             {
152                                 'name': 'leader_remarks',
153                                 'type': 'string'
154                             },
155                             {
156                                 'name': 'leader_passwd',
157                                 'type': 'string'
158                             },
159                             {
160                                 'name': 'leader_owner_id',
161                                 'type': 'int'
162                             },
163                             {
164                                 'name': 'leader_lang',
165                                 'type': 'string'
166                             },
167                             {
168                                 'name': 'leader_no_reset_sent',
169                                 'type': 'int'
170                             },
171                             {
172                                 'name': 'leader_action_type',
173                                 'type': 'string'
174                             },
175                             {
176                                 'name': 'leader_project_id',
177                                 'type': 'int'
178                             }
179                         ]
180                     }
181                 },
182                 colModel : [
183                     {
184                         xtype: 'ColumnModel',
185                         xns: Roo.grid,
186                         dataIndex : 'country',
187                         header : 'Country',
188                         width : 200,
189                         renderer : function(v,x,r)
190                         {
191                             if(v*1 == -1){
192                                 return String.format('<b>{0}</b>', r.data.country_tr);
193                             }
194                             
195                             return String.format('{0}', r.data.country_tr);
196                         }
197                     }
198                 ],
199                 sm : {
200                     xtype: 'RowSelectionModel',
201                     xns: Roo.grid,
202                     listeners : {
203                         afterselectionchange : function (_self)
204                         {
205                         //    Pman.Tab.AdminContacts.grid.footer.onClick('first');
206                             var c = Pman.Tab.AdminContactsManager.layout.getRegion('center');
207                             c.getActivePanel().grid.footer.onClick('first');
208                             
209                         }
210                     },
211                     singleSelect : true
212                 },
213                 dropTarget : {
214                     xtype: 'DropTarget',
215                     xns: Roo.dd,
216                     listeners : {
217                         drop : function (source, e, data)
218                         {
219                             //Roo.log("DROP");
220                             
221                             var t = Roo.lib.Event.getTarget(e); 
222                             var ri = _this.grid.view.findRowIndex(t);
223                             var rid  = false;
224                             if (ri !== false) {
225                                 rid = _this.grid.getDataSource().getAt(ri).data;
226                             }
227                             //var s = _this.grid.getSelectionModel().getSelections();
228                               
229                             //console.log(data);
230                             var isFromGroup = _this.grid.getSelectionModel().isSelected(ri);;
231                         
232                             //var isToGroup = rid && rid.id > 0;
233                             this.success = false;
234                             
235                             if (isFromGroup){
236                                 return;
237                             }
238                             var targetCountry = rid.country;
239                             var action = 'add';
240                             
241                             if (targetCountry*1 == -1) {
242                                 action = 'sub';
243                                 //return 'x-dd-drop-ok-sub'; 
244                             }
245                             // build a list of selections.
246                             var sels = [];
247                             
248                             for (var i=0; i < data.selections.length; i++){
249                                 var c = data.selections[i].data.countries.split(',');
250                                 if(c.indexOf(targetCountry) > -1){
251                                     //Roo.log("skipped : "+data.selections[i].data.id);
252                                     continue;
253                                 }
254                                 //Roo.log(data.selections[i].data);
255                                 sels.push(data.selections[i].data.id);
256                             }
257                             
258                             if(sels.length < 1){
259                                 Roo.MessageBox.alert('Error', 'No person add to group');
260                                 return;
261                             }
262                             
263                             new Pman.Request({
264                                 url: baseURL + '/Core/GroupCountries.php',
265                                 params: {
266                                     action : action,
267                                     country: (targetCountry != -1) ? targetCountry : _this.grid.getSelectionModel().getSelected().data.country,
268                                     user_ids : sels.join(',')
269                                 },
270                                 method: 'POST',  
271                                 success : function(res) {
272                                     Pman.Tab.AdminContacts.grid.footer.onClick('refresh');
273                                     //var data = res.data
274                                     //refreshPager();
275                                     // 
276                                     // do we need to do anything??
277                                     //if (isFromGroup) {
278                                     //    Pman.Tab.AdminContacts.grid.footer.onClick('refresh');
279                                     //}
280                                 }, 
281                                 
282                                 failure: function() {
283                                     //Ext.get(document.body).unmask();
284                                     //if (cb) {
285                                     //    cb.call(false);
286                                     //}
287                                      
288                                 }
289                             });
290                         
291                             this.success = true;
292                             return;
293                         
294                         },
295                         over : function (source, e, data)
296                         {
297                             //Roo.log("dragover");
298                             
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                             
306                             var isFromGroup = _this.grid.getSelectionModel().isSelected(ri);
307                             
308                             //Roo.log(", isFromGroup:" + isFromGroup);
309                              
310                             if (isFromGroup) {
311                                 this.valid = false;
312                                 return;
313                             }
314                             
315                             if(rid.country*1 == -1) {
316                                 this.valid = 'ok-sub'; 
317                                 return;
318                             } 
319                             
320                             this.valid = 'ok-add';
321                         }
322                     },
323                     ddGroup : 'groupDD'
324                 }
325             }
326         };
327     }
328 });