Ext.namespace("GO.groups");GO.groups.MainPanel=function(a){if(!a){a={}}this.storeAllGroups=new GO.data.JsonStore({url:GO.settings.modules.groups.url+"non_admin_json.php",baseParams:{task:"groups"},root:"results",id:"id",totalProperty:"total",fields:["id","name","user_id","user_name"],remoteSort:true});var b=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:GO.groups.lang.groups,dataIndex:"name",width:300},{header:GO.groups.lang.owner,dataIndex:"user_name"}]});var c=new Ext.Toolbar({cls:"go-head-tb",items:[{iconCls:"btn-add",text:GO.lang.cmdAdd,cls:"x-btn-text-icon",handler:function(){this.showGroupDialog(0)},scope:this},{iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.deleteSelected()},scope:this}]});a.layout="fit";a.id="groups-grid-overview-groups";a.store=this.storeAllGroups;a.cm=b;a.sm=new Ext.grid.RowSelectionModel({singleSelect:false});a.tbar=c;a.paging=true;a.viewConfig={autoFill:true,forceFit:true};GO.groups.MainPanel.superclass.constructor.call(this,a)};Ext.extend(GO.groups.MainPanel,GO.grid.GridPanel,{afterRender:function(){GO.groups.MainPanel.superclass.afterRender.call(this);this.on("rowdblclick",this.rowDoubleClick,this);this.storeAllGroups.load()},rowDoubleClick:function(a){this.showGroupDialog(a.selModel.selections.items[0].data)},showGroupDialog:function(d){if(!this.new_dialog){this.userStore=new GO.data.JsonStore({url:GO.settings.modules.groups.url+"json.php",baseParams:{action:"users_in_group"},root:"results",id:"id",fields:["id","user_id","name","email"],remoteSort:true});var b=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:GO.lang.strUsername,dataIndex:"name"},{header:GO.lang.strEmail,dataIndex:"email"}]});this.userGrid=new GO.grid.GridPanel({region:"center",ds:this.userStore,cm:b,sm:new Ext.grid.RowSelectionModel({singleSelect:false}),autoScroll:true,border:false,viewConfig:{forceFit:true,autoFill:true},tbar:[{iconCls:"btn-add",text:GO.lang.cmdAdd,cls:"x-btn-text-icon",handler:function(){if(!this.addUsersDialog){this.addUsersDialog=new GO.dialog.SelectUsers({handler:function(e){if(e.selModel.selections.keys.length>0){this.userStore.baseParams.add_users=Ext.encode(e.selModel.selections.keys);this.userStore.reload();delete this.userStore.baseParams.add_users}},scope:this})}this.addUsersDialog.show()},scope:this},{iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.userGrid.deleteSelected()},scope:this}]});this.newFormPanel=new Ext.FormPanel({region:"north",height:30,waitMsgTarget:true,labelWidth:85,defaultType:"textfield",cls:"go-form-panel",border:false,items:[{fieldLabel:GO.groups.lang.lblNew,name:"name",anchor:"100%",allowBlank:false}]});var c=[{text:GO.lang.cmdOk,handler:function(){this.saveNewGroup(true)},scope:this},{text:GO.lang.cmdApply,handler:function(){this.saveNewGroup()},scope:this},{text:GO.lang.cmdClose,handler:function(){this.new_dialog.hide()},scope:this}];var a=function(){this.newFormPanel.items.items[0].focus()};this.new_dialog=new Ext.Window({layout:"border",modal:false,shadow:false,height:400,width:500,plain:true,closeAction:"hide",title:GO.groups.lang.group,items:[this.newFormPanel,this.userGrid],buttons:c,focus:a.createDelegate(this)})}this.new_dialog.show();this.setGroup(d)},setGroup:function(a){this.group_id=this.userStore.baseParams.group_id=a.id;if(this.group_id>0){this.userGrid.setDisabled(false);this.userStore.load({callback:function(){this.newFormPanel.form.findField("name").focus()},scope:this});if(a&&a.name){this.newFormPanel.form.findField("name").setValue(a.name)}}else{this.userGrid.setDisabled(true);this.userStore.loadData({total:0,results:[]});this.newFormPanel.form.findField("name").setRawValue("")}},saveNewGroup:function(a){this.newFormPanel.form.submit({waitMsg:GO.lang.waitMsgSave,url:GO.settings.modules.groups.url+"action.php",params:{action:"save_group",group_id:this.group_id},success:function(b,c){var d={id:c.result.group_id};this.setGroup(d);this.storeAllGroups.reload();if(a){this.new_dialog.hide()}},failure:function(b,c){if(c.failureType!="client"){Ext.MessageBox.alert(GO.lang.strError,c.result.feedback)}else{Ext.MessageBox.alert(GO.lang.strError,"Errors in form")}},scope:this})}});GO.moduleManager.addModule("groups",GO.groups.MainPanel,{title:GO.groups.lang.groups,iconCls:"go-tab-icon-groups",admin:true});