Ext.namespace("PMS.FNTabUSERS"); PMS.FNTabUSERS= function(myTabName, TabText){ function GetGroupCombo(mytype, idGroupName){ var myhand = function(f,f1,f2){}; if(idGroupName=="") idGroupName = 'UserGroup'+rand(0); if(mytype==1){ idGroupName = 'UserGroup123456789'; myhand = function(f,f1,f2){ Ext.getCmp('listusers').getStore().baseParams['Group'] = f1.get("id"); Ext.getCmp('listusers').getStore().load(); } } var MyStore = new Ext.data.JsonStore({url: 'modules/main/js/getgrouptocombo.php', baseParams:{mtype:mytype}, root: 'groups', fields: ['id', 'name']}); var myusers = new Ext.form.ComboBox({ fieldLabel: 'Group', hiddenName:'UserGroupID', id:idGroupName, store: MyStore, editable:false, valueField:'id', displayField:'name', readOnly:true, mode: 'local', width: 130, listWidth:200, maxHeight:200, triggerAction: 'all', emptyText:'Select group', listeners:{select:myhand} }); MyStore.load(); return myusers; }; function WindowNewUser(){ var myformpanelwindows12 = new Ext.FormPanel({ frame:true, labelAlign: 'right', bodyStyle:'padding:5px', width: 390, height:'auto', waitMsgTarget: true, layout: 'form', items: [ {name: 'username', xtype:'textfield', fieldLabel: 'User Name',width: 210}, {name: 'firstname', xtype:'textfield', fieldLabel: 'First Name',width: 210 }, {name: 'lastname', xtype:'textfield', fieldLabel: 'Last Name',width: 210}, new Ext.form.ComboBox({ fieldLabel: 'Group', hiddenName:'UserGroupID', store: new Ext.data.SimpleStore({ fields: ['id', 'groupname'], data : Ext.Users.Groups}), valueField:'id', displayField:'groupname', readOnly:true, mode: 'local', triggerAction: 'all', emptyText:'Select access value ...', selectOnFocus:true, width: 210, listWidth:210 }), new Ext.form.Checkbox({ fieldLabel: 'User is active', name:'useractive'}) ] }); // Create Window Property of User var myfunction = function(){ myformpanelwindows12.form.submit({ url:'modules/main/js/users-add-newuser.php', waitMsg:'Saving ...', success: function (form, action) { win2.close(); Ext.getCmp("listusers").getStore().load();}, failure:function(form, action) { var SucParams = Ext.decode(action.response.responseText); Ext.MessageBox.alert('ERRORS', SucParams['errors']['strmsg']); } });}; var win2 = new Ext.Window({ width:400, height:'auto', autoCreate : true, title:"New User ", resizable:false, constrain:true, constrainHeader:true, minimizable : false, maximizable : false, stateful: false, shim:true, buttonAlign: 'center', autoScrool:true, modal:true, plain:true, footer:true, closable:true, items: myformpanelwindows12, iconCls:'nav', buttons: [{ text:'Add user',handler: myfunction }, { text: 'Cancel', handler: function(){ win2.hide();} }] }); win2.show(this); }; // Function for double click Users grid rows function WindowUser(grid, rowIndex, columnIndex, e){ var SelectedRecord = grid.getStore().getAt(rowIndex); var SelectedUserID = SelectedRecord.get("id"); // Create Form of property of User for window var myformpanelwindows = new Ext.FormPanel({ frame:true, labelAlign: 'right', bodyStyle:'padding:5px', width: 515, height:'auto', waitMsgTarget: true, baseParams:{userid: SelectedUserID}, items: [{ layout:'column', border:false, resizable:false, width: 480, height:'auto', items:[{ layout: 'form', columnWidth:.5, border:false, items: [ {name: 'userid', xtype:'textfield', fieldLabel: 'ID', readOnly:true}, {name: 'username', xtype:'textfield', fieldLabel: 'User Name'} ] },{ columnWidth:.5, layout: 'form', border:false, items: [ {name: 'firstname', xtype:'textfield', fieldLabel: 'First Name'}, {name: 'lastname', xtype:'textfield', fieldLabel: 'Last Name'} ] }] },{ xtype:'tabpanel', plain:true, activeTab: 0, height:220, width: 480, deferredRender:false, items:[{ title:' Details ', layout:'form', defaults: {width: 230}, defaultType: 'textfield', frame:true, border:false, iconCls:'nav', labelWidth:150, items: [ new Ext.form.Checkbox({ fieldLabel: 'User active', name:'useractive'}), new Ext.form.ComboBox({ fieldLabel: 'Group', hiddenName:'UserGroupID', store: new Ext.data.SimpleStore({ fields: ['idUserGroupID', 'groupname'], data : Ext.Users.Groups}), valueField:'idUserGroupID', displayField:'groupname', readOnly:true, mode: 'local', triggerAction: 'all', emptyText:'Select access value ...', selectOnFocus:true, listWidth:230 }), new Ext.form.DateField({ fieldLabel: 'Birth Date', name: 'userbdate', format: 'Y-m-d', disabledDaysText: 'Plants are not available on the weekends' }), {fieldLabel: 'Registration date', name: 'usercdate', readOnly:true }, {fieldLabel: 'Author', name: 'usercaut', readOnly:true }, {fieldLabel: 'Last Update', name: 'userudate', readOnly:true }, {fieldLabel: 'Update author', name: 'useruaut', readOnly:true } ] },{ title:' Contacts ', layout:'form', defaults: {width: 230}, defaultType: 'textfield', frame:true, border:false, iconCls:'nav', labelWidth:150, items: [ {fieldLabel: 'E-mail', name: 'useremail', vtype:'email' }, {fieldLabel: 'ICQ', name: 'usericq', maxLength: 10, maskRe : /^\d+$/}, {fieldLabel: 'Phone', name: 'userphone', maxLength: 16, maskRe : /^\d+$/}, {fieldLabel: 'Mobile', name: 'usermobile', maxLength: 16, maskRe : /^\d+$/} ] },{ title:' Change Password ', layout:'form', defaults: {width: 230}, defaultType: 'textfield', frame:true, border:false, iconCls:'nav', labelWidth:150, items: [ {fieldLabel: 'Old Password', name: 'userpassword', inputType:'password' }, {fieldLabel: 'Password', name: 'newuserpassword', inputType:'password' }, {fieldLabel: 'Retype password', name: 'newuserpassword1', inputType:'password'} ] },{ title:'Description', layout:'fit', frame:true, border:false, iconCls:'nav', items: { xtype:'textarea', name:'usercomments', fieldLabel:'Description'} }] }] }); var FNCSaveUser = function(){ myformpanelwindows.form.submit({ url:'modules/main/js/users-save-user.php', // PHP waitMsg:'Saving Data...', success: function (form, action) { win.close(); Ext.getCmp("listusers").getStore().load();}, failure:function(form, action) { var SucParams = Ext.decode(action.response.responseText); Ext.MessageBox.alert('ERRORS', SucParams['errors']['strmsg']); } }); }; // Create Window Property of User var win = new Ext.Window({ width:540, height:'auto', autoCreate : true, title:"User Property ", resizable:false, constrain:true, constrainHeader:true, minimizable : false, maximizable : false, stateful: false, shim:true, buttonAlign:"center", autoScrool:true, modal:true, plain:true, footer:true, closable:true, items: myformpanelwindows, iconCls:'nav', buttons: [ { text:'Save', handler: FNCSaveUser }, { text: 'Close', handler: function(){ win.hide();} }], buttonAlign: 'center' }); win.show(this); myformpanelwindows.getForm().load({url:'modules/main/js/users-get-user.php', waitMsg:'Loading ... ', success:function(form, action) { }, failure:function(form, action) { Ext.MessageBox.alert('Message', action.response.responseText); win.hide(); } }); }; function DelUser(idUser){ var RegCheck2 = new Ext.data.JsonStore({ url: 'modules/main/js/users-rem-users.php', baseParams: { selUsers: idUser}, root: 'data', totalProperty: 'count', fields: ['suscess', 'text'] }); RegCheck2.on('load', function(){ if (RegCheck2.getTotalCount()>0) { var rres=RegCheck2.getAt(0).get('suscess'); if (rres=='rok') { Ext.MessageBox.show({ title: 'WARNING', msg: RegCheck2.getAt(0).get('text'), buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.WARNING}); } Ext.getCmp('listusers').getStore().load(); } }); RegCheck2.load(); }; var MyNewStore = new Ext.data.Store({ url: 'modules/main/js/users-get-users.php', baseParams:{Section:""}, remoteSort: true, reader: new Ext.data.JsonReader({ root: 'users', totalProperty: 'totalCount', fields: ['id', 'username', 'firstname', 'lastname', 'active', 'usergroup', 'status','lastlogin' ]}) }); MyNewStore.setDefaultSort('id', 'asc'); function onItemToggleInActive(item, pressed){ if(pressed){ Ext.getCmp('idToggleActive').toggle(false); Ext.getCmp('listusers').getStore().baseParams['Inactive'] = 1; }else{ Ext.getCmp('listusers').getStore().baseParams['Inactive'] = 0; } Ext.getCmp('listusers').getStore().load(); } function onItemToggleActive(item, pressed){ if(pressed){ Ext.getCmp('idToggleInActive').toggle(false); Ext.getCmp('listusers').getStore().baseParams['Active'] = 1; }else{ Ext.getCmp('listusers').getStore().baseParams['Active'] = 0; } Ext.getCmp('listusers').getStore().load(); } t = new Ext.Panel({ id: myTabName, title: ' ' + TabText, autoScroll:true, listeners: { activate: handleActivate }, closable:true, layout:'fit', iconCls:'nav', items: [{ xtype:'grid', id: 'listusers', store: MyNewStore, cm: new Ext.grid.ColumnModel([ new Ext.grid.CheckboxSelectionModel(), {id:'id',header: "ID", width: 40, sortable: true, dataIndex: 'id'}, {header: "User Name", width: 80, sortable: true, dataIndex: 'username'}, {header: "First Name", width: 80, sortable: true, dataIndex: 'firstname'}, {header: "Last Name", width: 80, sortable: true, dataIndex: 'lastname'}, {header: "Last Login", width: 80, sortable: true, dataIndex: 'lastlogin'}, {header: "Status", width: 80, sortable: true, dataIndex: 'status'}, {header: "Group", width: 80, dataIndex: 'usergroup'} ]), sm: new Ext.grid.CheckboxSelectionModel(), viewConfig: { forceFit:true}, width: 'auto', loadMask: {msg: 'Loading Users'}, bbar: new Ext.PagingToolbar({ pageSize: 15, store: MyNewStore, displayInfo: true }), tbar:[ { text:'Add', tooltip:'Add a new user', iconCls:'people_add', handler: WindowNewUser}, '-', { text:'Edit', tooltip:'Edit the selected user', iconCls:'people_edit', handler: function(){ var mygrid = Ext.getCmp('listusers'); if(mygrid.getSelectionModel().hasSelection()){ var selectionsList = mygrid.getSelectionModel().getSelections(); var selectedURecord = selectionsList[0]; selectedUsersId = selectedURecord.get('id'); myrowIndex = mygrid.getStore().indexOf(selectedURecord); mygrid.getSelectionModel().clearSelections(); mygrid.getSelectionModel().selectRow(myrowIndex); mygrid.fireEvent("celldblclick", mygrid, myrowIndex,0,null); }else{ Ext.MessageBox.show({ title: 'TITLE', msg: "No selected item", buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.INFO}); } }},'-', { text:'Delete', tooltip:'Delete the selected users', iconCls:'people_del', handler: function(){ var gridCmpSel = Ext.getCmp('listusers'); if(gridCmpSel.getSelectionModel().hasSelection()){ var selectionsList = gridCmpSel.getSelectionModel().getSelections(); var selectedUserdId = ""; var selectedUserText = ""; for(var i = 0;i"; GridToPrintPS({ListStore: MyNewStore, TitleText: str, TableText:'List Users ',idGrid:'listusers', Summ:{fff:true}}); } } ], listeners: { celldblclick: WindowUser } }] }); var CenterTabPanel = Ext.getCmp("CentralTabPanel"); CenterTabPanel.add(t); CenterTabPanel.activate(myTabName); MyNewStore.load(); };