109b6cf7b2c4aff115b98600b80f808f5859066f
[Pman.BAdmin] / Pman.Dialog.BAdminStaffGroups.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.Dialog');
6
7 Pman.Dialog.BAdminStaffGroups= function() {}
8 Roo.apply(Pman.Dialog.BAdminStaffGroups.prototype, {
9
10  _strings : {
11   '4910043d0b2c8c864a0e8672716fee94' :"Is a Member",
12   '566a352f95c879ff26e50bad767a28dc' :"Group Membership",
13   '6b79852e4370cae80ee551e0671616bb' :"Manage Users Group",
14   '28974c2c793e780427dfb571b26443e6' :"Group Name",
15   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
16   'c9cc8cce247e49bae79f15173ce97354' :"Save"
17  },
18
19  dialog : false,
20  callback:  false,
21
22  show : function(data, cb)
23  {
24   if (!this.dialog) {
25    this.create();
26   }
27
28   this.callback = cb;
29   this.data = data;
30   this.dialog.show.apply(this.dialog,  Array.prototype.slice.call(arguments).slice(2));
31   if (this.form) {
32    this.form.reset();
33    this.form.setValues(data);
34    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
35   }
36
37  },
38
39  create : function()
40  {
41   var _this = this;
42   this.dialog = Roo.factory({
43     xtype : 'Modal',
44     cls : 'add-user-dialog',
45     fit_content : true,
46     title : _this._strings['6b79852e4370cae80ee551e0671616bb'] /* Manage Users Group */,
47     listeners : {
48      render : function (_self)
49       {
50           _this.dialog = this;
51       },
52      show : function (_self)
53       {
54           this.setTitle("Manage Membership for " + _this.data.name);
55       }
56     },
57     xns : Roo.bootstrap,
58     '|xns' : 'Roo.bootstrap',
59     buttons : [
60      {
61       xtype : 'Button',
62       html : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
63       listeners : {
64        click : function (_self, e)
65         {
66             _this.dialog.hide(); 
67         }
68       },
69       xns : Roo.bootstrap,
70       '|xns' : 'Roo.bootstrap'
71      },
72      {
73       xtype : 'Button',
74       html : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
75       weight : 'primary',
76       listeners : {
77        click : function (_self, e)
78         {
79             if(!_this.form.isValid()){
80                 //Roo.bootstrap.MessageBox.alert('Error', 'Please Correct all the errors in red');
81                 return;
82             }
83             
84             var myID = _this.form.findField('id').getValue() * 1;
85             var myName = _this.form.findField('name').getValue();
86         
87             if (_this.form.findField('company_id') && !_this.form.findField('company_id').getValue()) {
88                 Roo.bootstrap.MessageBox.alert("Error", "Select a Company");
89                 return;
90             }
91                 
92                // validate password match (only needed if we are not using generated one..
93             if (_this.form.findField('passwd1') 
94                     && _this.form.findField('passwd1').getValue().length > 0 
95                     && _this.form.findField('passwd1').inputEl().dom.type == "password") {
96                     
97                 var p1 = _this.form.findField('passwd1').getValue();
98                 var p2 = _this.form.findField('passwd2').getValue();
99                     
100                     
101                 if (Pman.Login.authUser.id < 0 && !p1.length) {
102                     Roo.bootstrap.MessageBox.alert("Error", "You must create a password for the admin account");
103                     return;
104                 }
105                     
106                     
107                 if (p1.length || p2.length) {
108                     if (p1 != p2) {
109                         Roo.bootstrap.MessageBox.alert("Error", "Passwords do not match");
110                         return;
111                     }
112                 }
113                     
114                 
115             }
116             
117             // get the list of record with tick
118             
119             _this.form.doAction("submit");
120             
121             return;
122         
123         }
124       },
125       xns : Roo.bootstrap,
126       '|xns' : 'Roo.bootstrap'
127      }
128     ],
129     items  : [
130      {
131       xtype : 'Border',
132       listeners : {
133        render : function (_self)
134         {
135             _this.layout = _self;
136         }
137       },
138       xns : Roo.bootstrap.layout,
139       '|xns' : 'Roo.bootstrap.layout',
140       center : {
141        xtype : 'Region',
142        alwaysShowTabs : true,
143        tabPosition : 'top',
144        xns : Roo.bootstrap.layout,
145        '|xns' : 'Roo.bootstrap.layout'
146       },
147       items  : [
148        {
149         xtype : 'Grid',
150         background : false,
151         fitContainer : true,
152         fitToFrame : true,
153         region : 'center',
154         title : _this._strings['566a352f95c879ff26e50bad767a28dc'] /* Group Membership */,
155         listeners : {
156          activate : function (_self)
157           {
158               if(_this.option_grid){
159                   _this.option_grid.store.load({});
160               }
161               
162           },
163          render : function (_self)
164           {
165               _this.option_panel = this;
166               
167               
168           }
169         },
170         xns : Roo.bootstrap.panel,
171         '|xns' : 'Roo.bootstrap.panel',
172         grid : {
173          xtype : 'Table',
174          cellSelection : true,
175          cls : 'table-fixed',
176          condensed : true,
177          footerShow : false,
178          loadMask : true,
179          rowSelection : false,
180          listeners : {
181           cellclick : function (_self, el, rowIndex, columnIndex, e)
182            {
183                var di = _this.option_grid.colModel.getDataIndex(columnIndex);
184                
185                /*
186                if (di != 'is_in_group') {
187                    return;
188                }
189                 */
190                var rec = _this.option_grid.store.getAt(rowIndex);
191                
192                if(rec.data.name == 'Administrators' && _this.data.id == Pman.Login.authUser.id){
193                    Roo.bootstrap.MessageBox.alert('Error', 'You can not remove yourself from Administrators group');
194                    return;
195                }
196                
197                rec.set('is_in_group', rec.data.is_in_group * 1 == 1 ? 0 : 1);
198                rec.commit();
199            
200            },
201           render : function (_self)
202            {
203                _this.option_grid = this;
204                
205                this.store.load({})
206            }
207          },
208          xns : Roo.bootstrap,
209          '|xns' : 'Roo.bootstrap',
210          store : {
211           xtype : 'Store',
212           remoteSort : true,
213           sortInfo : { direction : 'ASC', field: 'id' },
214           listeners : {
215            beforeload : function (_self, options)
216             { 
217                 options.params = options.params || {};
218                 
219                 if(_this.data.id * 1 < 1){
220                     _this.option_grid.el.mask('Please save the member first');
221                     this.removeAll();
222                     return false;
223                 }
224                 options.params.limit = 200;
225                 options.params._is_in_group = _this.data.id;
226             
227             },
228            update : function (_self, record, operation)
229             {
230                 if (operation != 'commit') {
231                     return;
232                 }
233                 
234                 var params = {
235                     user_ids : _this.data.id,
236                     _action : (record.data.is_in_group * 1 == 0) ? 'sub' : 'add',
237                     group_id : record.data.id
238                 };
239                 
240                 new Pman.Request({
241                     url : baseURL + '/Roo/Core_group',
242                     method : 'POST',
243                     params : params,
244                     success : function() { 
245                         //_this.option_grid.ds.load({});
246                     }
247               });
248             }
249           },
250           xns : Roo.data,
251           '|xns' : 'Roo.data',
252           proxy : {
253            xtype : 'HttpProxy',
254            method : 'GET',
255            url : baseURL + '/Roo/core_group',
256            xns : Roo.data,
257            '|xns' : 'Roo.data'
258           },
259           reader : {
260            xtype : 'JsonReader',
261            fields : [
262                {
263                    'name': 'id',
264                    'type': 'int'
265                },
266                {
267                    'name': 'name',
268                    'type': 'string'
269                },
270                {
271                    'name': 'display_name',
272                    'type': 'string'
273                },
274                {
275                    'name': 'is_in_group',
276                    'type': 'int'
277                }
278            ],
279            id : 'id',
280            root : 'data',
281            xns : Roo.data,
282            '|xns' : 'Roo.data'
283           }
284          },
285          sm : {
286           xtype : 'RowSelectionModel',
287           singleSelect : true,
288           xns : Roo.bootstrap.Table,
289           '|xns' : 'Roo.bootstrap.Table'
290          },
291          cm : [
292           {
293            xtype : 'ColumnModel',
294            align : 'center',
295            cursor : 'pointer',
296            dataIndex : 'is_in_group',
297            header : _this._strings['4910043d0b2c8c864a0e8672716fee94'] /* Is a Member */,
298            renderer : function(v) {  
299            
300                var state = v > 0 ?  'check-' : '';
301                var cls = v > 0 ? 'text-primary' : '';
302                
303                return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
304                     
305             },
306            sortable : false,
307            xs : 3,
308            xns : Roo.grid,
309            '|xns' : 'Roo.grid'
310           },
311           {
312            xtype : 'ColumnModel',
313            cursor : 'pointer',
314            dataIndex : 'display_name',
315            header : _this._strings['28974c2c793e780427dfb571b26443e6'] /* Group Name */,
316            renderer : function(v,x,r) 
317            {
318                var vv = v.length ? v : r.data.name;
319                
320                return String.format('{0}', vv);
321            },
322            sortable : true,
323            xs : 9,
324            xns : Roo.grid,
325            '|xns' : 'Roo.grid'
326           }
327          ]
328         }
329        }
330       ]
331      }
332     ]
333    }  );
334  }
335 });
336 Roo.apply(Pman.Dialog.BAdminStaffGroups, Pman.Dialog.BAdminStaffGroups.prototype);