Wtf.userAttendance=function(A){Wtf.apply(this,A);this.moduleid=A.moduleid;this.attnsm=new Wtf.grid.CheckboxSelectionModel({});this.userAttencm=new Wtf.grid.ColumnModel([this.attnsm,{header:"Employee Name",dataIndex:"name"},{header:"Employee Id",dataIndex:"username"},{header:"Attendance",dataIndex:"attendance",renderer:function(B){if(B==1){return"Pass"}else{if(B==0){return"Fail"}}}},{header:"Status",dataIndex:"status",renderer:function(B){if(B==1){return"Training History Updated"}else{if(B==0){return"Training History not Updated"}}}}]);this.attenStore=new Wtf.data.Store({url:"jspfiles/admin/acastructure.jsp",reader:new Wtf.data.KwlJsonReader({root:"data",totalProperty:"count"},["userid","username","name","status","attendance"]),baseParams:{type:"118",moduleid:this.moduleid}});this.attenStore.load({params:{start:0,limit:15}});Wtf.userAttendance.superclass.constructor.call(this,{border:false,store:this.attenStore,cm:this.userAttencm,sm:this.attnsm,singleSelect:true,viewConfig:{forceFit:true,autoFill:true},loadMask:{msg:"Loading Courses..."},tbar:[{id:"updatethistory",text:"Update Training History",handler:this.updatethistory,disabled:true,scope:this}],bbar:new Wtf.PagingToolbar({pageSize:15,store:this.attenStore,displayInfo:true,displayMsg:"Displaying results {0} - {1} of {2}",emptyMsg:"No topics to results",plugins:new Wtf.common.pPageSize({id:"pPageSize_"+this.id})})});this.colModel.setEditable(0,false);this.colModel.setEditable(1,false);this.attnsm.on("selectionchange",this.selectionchanged,this)};Wtf.extend(Wtf.userAttendance,Wtf.grid.EditorGridPanel,{selectionchanged:function(){var A=true;var B=this.attnsm.getSelections();for(var C=0;C<B.length;C++){if(B[C].get("status")==0){A=false}else{A=true;break}}Wtf.getCmp("updatethistory").setDisabled(A)},updatethistory:function(){var userids="";var status="";var selected=this.attnsm.getSelections();for(var ctr=0;ctr<selected.length;ctr++){userids+=selected[ctr].get("userid")+",";status+=selected[ctr].get("attendance")+","}userids=userids.substring(0,userids.length-1);status=status.substring(0,status.length-1);Wtf.Ajax.requestEx({url:"jspfiles/admin/acastructure.jsp",params:{type:119,statusstr:status,userids:userids,moduleid:this.moduleid},method:"POST"},this,function(result,option){var resp=eval("("+result+")");if(resp.success!=null){if(resp.success){msgBoxShow(["Success","Training History Updated Successfully"],Wtf.MessageBox.INFO);this.attenStore.load({params:{start:0,limit:15}})}else{if(!resp.success){msgBoxShow(["Error","Error Occured at Server"],Wtf.MessageBox.ERROR)}}}},function(result,option){})},returnTime:function(D){var C=D%60;var B=Math.floor(D/60)%60;var A=Math.floor(D/3600);if(B%60==0){B=0}if(C<10){C="0"+C}if(B<10){B="0"+B}if(A<10){A="0"+A}var E=A+":"+B+":"+C;return E}});Wtf.teamMgmt=function(A){Wtf.apply(this,A);this.border=false;this.bodyStyle="background:none;";this.title=(this.faculty?"Manage Teams":"My Teams");this.teamReader=new Wtf.data.JsonReader({root:"data",totalProperty:"totalCount",fields:[{name:"teamid"},{name:"moduleid"},{name:"name"},{name:"description"},{name:"timestamp"}]});this.teamStore=new Wtf.data.Store({id:this.id+"_teamStore",baseParams:{start:0,limit:15},reader:this.teamReader,url:"jspfiles/admin/manageTeams.jsp",method:"GET"});this.teamStore.load({params:{action:0,moduleid:this.moduleid}});this.teamSM=new Wtf.grid.CheckboxSelectionModel({width:25,singleSelect:true});this.teamSM.id=this.id+"_teamSM";this.teamCM=new Wtf.grid.ColumnModel([this.teamSM,{header:"Team Name",autoWidth:true,sortable:true,dataIndex:"name"},{header:"Description",autoSize:true,sortable:true,dataIndex:"description"}]);this.teamGrid=new Wtf.grid.GridPanel({id:this.id+"_teamGrid",store:this.teamStore,cm:this.teamCM,sm:this.teamSM,border:false,loadMask:true,viewConfig:{forceFit:true}});this.memberReader=new Wtf.data.JsonReader({root:"data",totalProperty:"totalCount",fields:[{name:"userid"},{name:"username"},{name:"checked"}]});this.memberStore=new Wtf.data.Store({id:this.id+"_memberStore",reader:this.memberReader,url:"jspfiles/admin/manageTeams.jsp",method:"GET"});this.memberSM=new Wtf.grid.CheckboxSelectionModel({width:25});this.memberSM.id=this.id+"_memberSM";this.memberCM=new Wtf.grid.ColumnModel([this.memberSM,{header:"Member Name",autoWidth:true,sortable:true,dataIndex:"username"}]);this.memberGrid=new Wtf.grid.GridPanel({id:this.id+"_memberGrid",store:this.memberStore,cm:this.memberCM,sm:this.memberSM,border:false,loadMask:true,viewConfig:{forceFit:true}});this.items=new Wtf.Panel({layout:"border",border:false,items:[this.upperPanel=new Wtf.Panel({region:"north",title:"Team(s)",split:true,height:350,layout:"fit",border:false,tbar:["Quick Search: ",this.quickPanelSearch1=new Wtf.KWLQuickSearch({width:200,field:"name"}),"-",this.newBtn=new Wtf.Toolbar.Button({text:"New",iconCls:"pwnd newcal",tooltip:"Create New Team",scope:this,handler:this.newTeam}),this.editBtn=new Wtf.Toolbar.Button({text:"Edit",iconCls:"pwnd editicon",tooltip:"Edit Team Information",scope:this,handler:this.editTeam}),this.delBtn=new Wtf.Toolbar.Button({text:"Delete",iconCls:"pwnd deliconwt",tooltip:"Delete Team(s)",scope:this,handler:this.delTeam})],bbar:new Wtf.PagingToolbar({id:this.id+"_pgTbar1",pageSize:5,store:this.teamStore,displayInfo:true,displayMsg:"Displaying records {0} - {1} of {2}",emptyMsg:"No results to display",plugins:new Wtf.common.pPageSize({})}),items:[this.teamGrid]}),this.lowerPanel=new Wtf.Panel({teamid:null,region:"center",title:"Team Member(s)",split:true,layout:"fit",border:false,tbar:["Quick Search: ",this.quickPanelSearch2=new Wtf.KWLQuickSearch({width:200,field:"username"}),this.updateBtn=new Wtf.Toolbar.Button({text:"Update Team",iconCls:"pwnd editiconwt",tooltip:"Update Team Member(s) List",scope:this,handler:this.insertUpdateMembers})],items:[this.memberGrid]})]});this.items.on("resize",function(D,B,C){this.upperPanel.setHeight(C/2);this.doLayout()},this);this.teamStore.on("load",function(){this.quickPanelSearch1.StorageChanged(this.teamStore)},this);this.memberStore.on("load",function(F,E,D){this.quickPanelSearch2.StorageChanged(this.memberStore);var G=[];var B=0;for(var C=0;C<E.length;C++){if(E[C].data["checked"]=="1"){G[B++]=C}}this.memberSM.selectRows(G)},this);if(!this.faculty){this.newBtn.hide();this.editBtn.hide();this.delBtn.hide();this.updateBtn.hide()}this.teamGrid.addListener("rowclick",this.teamGridRowClick,this);Wtf.teamMgmt.superclass.constructor.call(this)};Wtf.extend(Wtf.teamMgmt,Wtf.Panel,{initComponent:function(A){Wtf.teamMgmt.superclass.initComponent.call(this,A)},onRender:function(B,A){Wtf.teamMgmt.superclass.onRender.call(this,B,A);this.on("refereshteamgrid",function(){this.teamStore.reload()})},teamGridRowClick:function(E,B,D){var F=this.teamStore.getAt(B);var A=F.data["teamid"];var C=F.data["name"];this.lowerPanel.teamid=A;this.lowerPanel.setTitle("Team Member(s) of "+C);this.memberStore.load({params:{action:1,teamid:A,moduleid:this.moduleid}})},newTeam:function(){this.showTeamWindow(null)},editTeam:function(){if(this.teamSM.getCount()==1){var A=this.teamSM.getSelected();this.showTeamWindow(A.get("teamid"),A.get("name"),A.get("description"))}else{Wtf.Msg.alert("Invalid Selection","Please select a single record to edit!");return false}},delTeam:function(){if(this.teamSM.getCount()>0){Wtf.MessageBox.confirm("Confirm","Are you sure you want to delete the selected team(s)?",function(C){if(C=="yes"){var D=this.teamSM.getSelections();var A="";for(var B=0;B<D.length;B++){A+=D[B].data["teamid"];if((B+1)!=D.length){A+=","}}this.deleteRequest(A)}},this)}else{Wtf.Msg.alert("Invalid Selection","Please select a single record to delete!");return false}},insertUpdateMembers:function(){if(this.memberSM.getCount()>0){var C=this.memberSM.getSelections();var B="";for(var A=0;A<C.length;A++){B+=C[A].data["userid"];if((A+1)!=C.length){B+=","}}this.membersRequest(B,this.lowerPanel.teamid)}else{Wtf.Msg.alert("Invalid Selection","Please select a single record to update!");return false}},membersRequest:function(members,teamid){Wtf.Ajax.request({method:"POST",url:"jspfiles/admin/manageTeams.jsp",params:({action:5,teamid:teamid,userids:members,moduleid:this.moduleid}),scope:this,success:function(result,req){var nodeobj=eval("("+result.responseText.trim()+")");if(nodeobj.success=="false"){Wtf.Msg.alert("Status","Update operation failed!")}else{if(nodeobj.success=="true"){Wtf.Msg.alert("Status","Record(s) saved successfully!",function(btn){if(btn=="ok"){}},this)}else{Wtf.Msg.alert("Status","The following students are already assigned to a team: -<br />"+nodeobj.success);this.memberStore.reload()}}},failure:function(result,req){Wtf.Msg.alert("Error","Error in Connection")}})},deleteRequest:function(teamids){Wtf.Ajax.request({method:"POST",url:"jspfiles/admin/manageTeams.jsp",params:({action:4,teamids:teamids}),scope:this,success:function(result,req){var nodeobj=eval("("+result.responseText.trim()+")");if(nodeobj.success=="false"){Wtf.Msg.alert("Status","Team doesn't exist or already has been deleted!")}else{if(nodeobj.success=="true"){Wtf.Msg.alert("Status","Record(s) deleted successfully!",function(btn){if(btn=="ok"){this.teamStore.reload()}},this)}}},failure:function(result,req){Wtf.Msg.alert("Error","Error in Connection")}})},insertUpdateTeam:function(){if(this.teamName.getValue()==""||this.teamName.getValue()==null){Wtf.Msg.alert("Invalid Name","Please enter a valid Team Name!",function(btn){if(btn=="ok"){return false}},this)}else{var action=2;if(this.teamWin.teamid){action=3}Wtf.Ajax.request({method:"POST",url:"jspfiles/admin/manageTeams.jsp",params:({action:action,moduleid:this.moduleid,name:this.teamName.getValue(),description:this.teamDesc.getValue(),teamid:this.teamWin.teamid}),scope:this,success:function(result,req){var nodeobj=eval("("+result.responseText.trim()+")");if(nodeobj.success=="false"){Wtf.Msg.alert("Status","Save operation failed!",function(btn){if(btn=="ok"){this.teamWin.hide()}},this)}else{if(nodeobj.success=="true"){Wtf.Msg.alert("Status","Record saved successfully!",function(btn){if(btn=="ok"){this.teamWin.hide();this.teamStore.reload()}},this)}}},failure:function(result,req){Wtf.Msg.alert("Error","Error in Connection",function(btn){if(btn=="ok"){this.teamWin.hide()}},this)}})}},showTeamWindow:function(B,C,A){if(!this.teamWin){this.formPanel=new Wtf.FormPanel({labelWidth:70,labelAlign:"left",border:false,bodyStyle:"padding:5px 5px 0",layout:"form",anchor:"100%",defaultType:"textfield",buttonAlign:"right",items:[this.teamName=new Wtf.form.TextField({fieldLabel:"Name*",anchor:"99%",allowBlank:false}),this.teamDesc=new Wtf.form.TextArea({fieldLabel:"Description",width:"95.5%"})]});this.teamWin=new Wtf.Window({id:this.id+"_newTeamWin",width:400,teamid:null,resizable:false,closeAction:"hide",modal:true,title:"Team Details",buttons:[{anchor:"90%",id:this.id+"_saveBtn",text:"Save",handler:this.insertUpdateTeam,scope:this},{anchor:"90%",id:this.id+"_cancelBtn",text:"Cancel",handler:function(){this.teamName.setValue("");this.teamDesc.setValue("");this.teamWin.hide()},scope:this}],items:[this.formPanel]})}this.teamName.setValue("");this.teamDesc.setValue("");this.teamWin.teamid=B;if(B){this.teamName.setValue(C);this.teamDesc.setValue(A)}this.teamWin.show()}})