Wtf.deferSession=function(A){Wtf.apply(this,A);this.obj=A.obj;this.flag=A.flag;this.moduleid=A.moduleid;if(Wtf.realroles.indexOf("46")>-1){this.title1="Approve/Reject request for deferment";this.btntxt="Approve"}else{this.title1="Send request for deferment";this.btntxt="Request"}Wtf.ux.comboBoxRenderer=function(B){return function(D){var C=B.store.find(B.valueField,D);if(C==-1){return""}var E=B.store.getAt(C);return E.get(B.displayField)}};this.sdate=new Wtf.form.DateField({fieldLabel:"Start Date*",allowBlank:false,width:140,format:Wtf.getDateFormat()});this.edate=new Wtf.form.DateField({fieldLabel:"End Date*",width:140,allowBlank:false,format:Wtf.getDateFormat()});this.NP_store=new Wtf.data.SimpleStore({fields:["no","method"],data:[["0","Short"],["1","Long"]]});this.ComboSessionType=new Wtf.form.ComboBox({fieldLabel:"Session Type",width:140,id:"CmbStype"+this.id,mode:"local",triggerAction:"all",typeAhead:true,editable:false,store:this.NP_store,displayField:"method",valueField:"no",hiddenName:"sessiontype",value:null});this.venueRecord=Wtf.data.Record.create([{name:"vname",type:"string"},{name:"id",type:"string"},{name:"timezone"}]);this.venueReader=new Wtf.data.JsonReader({root:"data"},this.venueRecord);this.venueStore=new Wtf.data.Store({proxy:new Wtf.data.HttpProxy({url:"jspfiles/newClass.jsp"}),reader:this.venueReader});this.facRecord=Wtf.data.Record.create([{name:"username",type:"string"},{name:"id",type:"string"}]);this.facReader=new Wtf.data.KwlJsonReader({root:"data"},this.facRecord);this.facStore=new Wtf.data.Store({proxy:new Wtf.data.HttpProxy({url:"jspfiles/newClass.jsp"}),reader:this.facReader});this.groupRec=Wtf.data.Record.create([{name:"groupid"},{name:"groupname"}]);this.groupBookStore=new Wtf.data.Store({url:"jspfiles/admin/LacaStructure.jsp",baseParams:{flag:65},reader:new Wtf.data.KwlJsonReader({root:"data"},this.groupRec)});this.resourceBookStore=new Wtf.data.Store({url:"jspfiles/admin/LacaStructure.jsp",baseParams:{flag:68},reader:new Wtf.data.KwlJsonReader({root:"data"},["resourceid","resourcename"])});this.bookTypeStore=new Wtf.data.SimpleStore({fields:["type"],data:[["Individual"],["Group"]]});this.nameField=new Wtf.form.TextField({maxLength:100,allowBlank:false,blankText:"Please enter a class name"});this.venueCombo=new Wtf.form.ComboBox({id:"venue"+this.id,store:this.venueStore,displayField:"vname",valueField:"id",mode:"local",editable:false,typeAhead:true,name:"venueid",triggerAction:"all",allowBlank:false});this.facultyCombo=new Wtf.form.ComboBox({id:"faculty"+this.id,store:this.facStore,displayField:"username",valueField:"id",mode:"local",editable:false,triggerAction:"all",allowBlank:false,blankText:"Please select a trainer",emptyText:"Select a Venue and then select a trainer"});this.dateField=new Wtf.form.DateField({allowBlank:false,blankText:"Please select a date"});this.stimeField=new Wtf.form.TimeField({id:"schstarttime",format:"H:i:s",allowBlank:false,scope:this,blankText:"Please select start time"});this.etimeField=new Wtf.form.TimeField({id:"schendtime",format:"H:i:s",allowBlank:false,scope:this,blankText:"Please select end time"});this.bookedGroupCmb=new Wtf.common.Select(Wtf.applyIf({multiSelect:true,forceSelection:true},{editable:false,emptyText:"Select a group...",valueField:"groupid",displayField:"groupname",mode:"local",store:this.groupBookStore,triggerAction:"all"}));this.bookedEntityCmb=new Wtf.common.Select(Wtf.applyIf({multiSelect:true,forceSelection:true},{editable:false,emptyText:"Select a facility name...",triggerAction:"all",valueField:"resourceid",displayField:"resourcename",mode:"local",store:this.resourceBookStore,triggerAction:"all"}));this.bookTypeCombo=new Wtf.form.ComboBox({allowBlank:false,editable:false,typeAhead:true,triggerAction:"all",displayField:"type",valueField:"type",mode:"local",store:this.bookTypeStore,value:"0"});this.cmodel1=new Wtf.grid.ColumnModel([new Wtf.grid.RowNumberer(),{header:"Class Name",width:120,dataIndex:"name",editor:this.nameField},{header:"Venue",width:120,dataIndex:"venueid",editor:this.venueCombo,renderer:Wtf.ux.comboBoxRenderer(this.venueCombo)},{header:"Trainer",width:100,dataIndex:"faculty",editor:this.facultyCombo,renderer:Wtf.ux.comboBoxRenderer(this.facultyCombo)},{header:"Facility Booking Type",width:150,dataIndex:"bookingtype",editor:this.bookTypeCombo,renderer:Wtf.ux.comboBoxRenderer(this.bookTypeCombo)},{header:"Group Name",width:100,dataIndex:"groupid",editor:this.bookedGroupCmb,renderer:this.comboBoxRenderer(this.bookedGroupCmb)},{header:"Facility Name",width:100,dataIndex:"facilityid",editor:this.bookedEntityCmb,renderer:this.comboBoxRenderer(this.bookedEntityCmb)},{header:"Date",width:100,dataIndex:"date",editor:this.dateField},{header:"Start Time",width:100,dataIndex:"stime",editor:this.stimeField},{header:"End Time",width:100,dataIndex:"etime",editor:this.etimeField}]);this.cmodel1.defaultSortable=true;this.sectionRecord=Wtf.data.Record.create([{name:"name",type:"string"},{name:"venue",type:"string"},{name:"date",type:"string"},{name:"stime",type:"string"},{name:"etime",type:"string"},{name:"stype",type:"string"},{name:"id",type:"string"},{name:"min",type:"string"},{name:"max",type:"string"},{name:"alloc",type:"string"},{name:"closedate",type:"string"},{name:"regExp",type:"string"},{name:"recc",type:"string"},{name:"recdate",type:"string"},{name:"venueid",type:"string"},{name:"faculty",type:"string"},{name:"timezone"},{name:"tname"},{name:"bookingtype",type:"string"},{name:"groupid",type:"string"},{name:"facilityid",type:"string"}]);this.sectionReader=new Wtf.data.KwlJsonReader({root:"data",totalProperty:"count"},this.sectionRecord);this.sectionStore=new Wtf.data.GroupingStore({proxy:new Wtf.data.HttpProxy({url:"jspfiles/newClass.jsp"}),reader:this.sectionReader,sortInfo:{field:"name",direction:"DESC"}});this.grid1=new Wtf.grid.EditorGridPanel({ds:this.sectionStore,cm:this.cmodel1,border:false,clicksToEdit:1,loadMask:{msg:"Loading Class Schedules..."},viewConfig:{forceFit:true}});this.grid1.on("beforeedit",this.handleBeforeEdit,this);this.grid1.on("afteredit",this.handleAfterEdit,this);Wtf.deferSession.superclass.constructor.call(this,{modal:true,border:false,title:"Defer Training Session",modal:true,resizable:false,width:940,height:500,layout:"border",buttons:[{text:this.btntxt,scope:this,handler:this.handleDeferValidate},{text:"Reject",scope:this,hidden:(Wtf.realroles.indexOf("46")>-1)?false:true,handler:function(){this.rejectReq()}},{text:"Cancel",scope:this,handler:function(){this.close()}}],items:[{region:"north",height:75,border:false,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",html:getHeader("images/ack40.gif","Defer Session",this.title1)},{region:"center",bodyStyle:"background:#f1f1f1;font-size:10px;padding:15px 10px 10px 20px;",height:100,border:false,layout:"fit",items:[{border:false,bodyStyle:"background:transparent;",layout:"fit",items:[this.deferSession=new Wtf.FormPanel({border:false,method:"POST",autoScroll:true,waitMsgTarget:true,url:(Wtf.realroles.indexOf("46")>-1)?"jspfiles/admin/LacaStructure.jsp?flag=88&type=1":"jspfiles/admin/LacaStructure.jsp?flag=87",labelWidth:140,id:"centerDeferSessionWindow",layout:"column",columnWidth:1,items:[{columnWidth:0.5,layout:"form",border:false,items:[new Wtf.form.Hidden({name:"pid",value:this.pid}),this.sname=new Wtf.form.TextField({fieldLabel:"Training Session Name*",width:150,allowBlank:false,name:"sesname"}),this.sdate=new Wtf.form.DateField({fieldLabel:"Start Date*",allowBlank:false,width:150,format:Wtf.getDateFormat()}),this.edate=new Wtf.form.DateField({fieldLabel:"End Date*",allowBlank:false,width:150,format:Wtf.getDateFormat()})]},{columnWidth:0.5,layout:"form",border:false,items:[this.scode=new Wtf.form.TextField({fieldLabel:"Training Session Code*",width:150,allowBlank:false,name:"sescode"}),this.min=new Wtf.form.NumberField({allowDecimals:false,allowNegative:false,fieldLabel:"Minimum Capacity*",name:"min",id:"numField333",scope:this,minValue:1,width:150,allowBlank:false,blankText:"Please specify minimum capacity"}),this.max=new Wtf.form.NumberField({allowDecimals:false,allowNegative:false,fieldLabel:"Maximum Capacity*",name:"max",width:150,id:"numField1444",allowBlank:false,scope:this,validator:this.validateNum,blankText:"Please specify maximum capacity"})]}]})]}]},{region:"south",height:250,border:false,layout:"fit",items:[this.grid1]}]})};Wtf.extend(Wtf.deferSession,Wtf.Window,{initComponent:function(A){Wtf.deferSession.superclass.initComponent.call(this,A)},onRender:function(A){Wtf.deferSession.superclass.onRender.call(this,A);Wtf.getCmp("centerDeferSessionWindow").doLayout();this.venueStore.load({params:{type:"venue"}});this.facStore.removeAll();this.facStore.load({params:{type:"facclass",moduleid:this.moduleid}});this.groupBookStore.load({});this.resourceBookStore.load({params:{groupid:""}});this.sectionStore.load({params:{classid:this.sessionid,type:(Wtf.realroles.indexOf("46")>-1)?"deferapprove":"sectiondefer"}})},handleDeferValidate:function(){var A=this.sdate.getRawValue();A=Wtf.modifyDateFmt(A,Wtf.getDateFormat(),"m/d/y");var B=this.edate.getRawValue();B=Wtf.modifyDateFmt(B,Wtf.getDateFormat(),"m/d/y");this.max.validate();this.min.validate();this.bookTypeCombo.validate();if(!this.sname.isValid()||!this.scode.isValid()||!this.max.isValid()||!this.min.isValid()||!this.bookTypeCombo.isValid()){msgBoxShow(["Session Deferment","Please make sure that all necessary fields are filled"],Wtf.MessageBox.INFO);return }if(Date.parseDate(A,"m/d/y")<Date.parseDate(B,"m/d/y")){Wtf.Msg.show({title:"Defer Session",msg:"Are you sure you want to defer the training session?",buttons:Wtf.Msg.YESNO,fn:function(M){if(M=="yes"){var H="{tableinfo:[";var N;var G=new Array();var E=this.sdate.getValue().format("Y-m-d");var K=this.edate.getValue().format("Y-m-d");var O;var L;if(Wtf.realroles.indexOf("46")>-1){G=this.sectionStore.getCount();if(G>0){for(var J=0;J<G;J++){O=new Date(this.sectionStore.getAt(J).get("date"));if(O!="Invalid Date"){L=O.format("Y-m-d")}else{L=this.sectionStore.getAt(J).get("date")}if(this.sectionStore.getAt(J).get("bookingtype")==""){msgBoxShow(["Session Deferment","Please ensure that all booking details are filled correctly"],Wtf.MessageBox.INFO);return }else{if(L<E||L>K){msgBoxShow(["Session Deferment","Please ensure that class dates fall between start and end dates of the session"],Wtf.MessageBox.INFO);return }else{if(this.sectionStore.getAt(J).get("stime")>this.sectionStore.getAt(J).get("etime")){msgBoxShow(["Session Deferment","Start time of a class cannot be greater than end time"],Wtf.MessageBox.INFO);return }else{var I=new Array();I[0]="name";I[1]="venueid";I[2]="faculty";I[3]="date";I[4]="stime";I[5]="etime";I[6]="id";I[7]="bookingtype";I[8]="groupid";I[9]="facilityid";var D=new Array();D[0]=this.sectionStore.getAt(J).get("name");D[1]=this.sectionStore.getAt(J).get("venueid");D[2]=this.sectionStore.getAt(J).get("faculty");D[3]=L;D[4]=this.sectionStore.getAt(J).get("stime");D[5]=this.sectionStore.getAt(J).get("etime");D[6]=this.sectionStore.getAt(J).get("id");D[7]=this.sectionStore.getAt(J).get("bookingtype");D[8]=this.sectionStore.getAt(J).get("groupid");D[9]=this.sectionStore.getAt(J).get("facilityid");N=Wtf.common.getJsonObjectForAccounting(I,D);H+=N}}}}H=Wtf.common.CreateJsonEnd(H)}else{H=H+"]}"}}else{G=this.sectionStore.getModifiedRecords();if(G.length>0){for(J=0;J<G.length;J++){O=new Date(G[J].data["date"]);if(O!="Invalid Date"){L=O.format("Y-m-d")}else{L=G[J].data["date"]}if(G[J].data["bookingtype"]==""){msgBoxShow(["Session Deferment","Please ensure that all booking details are filled correctly"],Wtf.MessageBox.INFO);return }else{if(L<E||L>K){msgBoxShow(["Session Deferment","Please ensure that class dates fall between start and end dates of the session"],Wtf.MessageBox.INFO);return }else{if(G[J].data["stime"]>G[J].data["etime"]){msgBoxShow(["Session Deferment","Start time of a class cannot be greater than end time"],Wtf.MessageBox.INFO);return }else{var C=new Array();C[0]="name";C[1]="venueid";C[2]="faculty";C[3]="date";C[4]="stime";C[5]="etime";C[6]="id";C[7]="bookingtype";C[8]="groupid";C[9]="facilityid";var F=new Array();F[0]=G[J].data["name"];F[1]=G[J].data["venueid"];F[2]=G[J].data["faculty"];F[3]=L;F[4]=G[J].data["stime"];F[5]=G[J].data["etime"];F[6]=G[J].data["id"];F[7]=G[J].data["bookingtype"];F[8]=G[J].data["groupid"];F[9]=G[J].data["facilityid"];N=Wtf.common.getJsonObjectForAccounting(C,F);H+=N}}}}H=Wtf.common.CreateJsonEnd(H)}else{H=H+"]}"}}this.handleDeferSubmit(K,E,H)}},scope:this,animEl:"elId",icon:Wtf.MessageBox.QUESTION})}else{this.edate.markInvalid("Start Date should be less than End Date")}},handleDeferSubmit:function(C,A,D,B){if(!B){B={};B["queue"]=false;B["holiday"]=false}this.deferSession.form.submit({params:{sessionid:this.sessionid,edate:C,sdate:A,moduleid:this.basemoduleid,tabledata:D,queue:B["queue"],holiday:B["holiday"]},scope:this,success:function(F,G){var E=Wtf.decode(G.response.responseText);if(E.success=="true"){this.close();msgBoxShow(["Success","The operation was completed successfully"],Wtf.MessageBox.INFO);this.obj.classStore.load({params:{start:0,limit:10}})}else{Wtf.MessageBox.show({title:"ERROR!!!",msg:E.msg,buttons:Wtf.MessageBox.OK,animEl:"upwin",icon:Wtf.MessageBox.ERROR,scope:this,fn:this.closeWindow})}},failure:function(G,H){var F=Wtf.decode(H.response.responseText);if(F.data[0].success=="false"&&F.data[0].flag=="venue"){Wtf.Msg.alert("Schedule Clash","Class "+F.data[0].name+" has already been scheduled at same venue and time.")}else{if(F.data[0].success=="false"&&F.data[0].flag=="faculty"){var E=F.data[0];var K=[E.facultyid,E.facultyname,"",E.subclassdate];showConflictMsgBox("faculty","Faculty Clash","Faculty "+E.facultyname+" has already been scheduled at same time for the class "+E.name+".",K)}else{if(F.data[0].success=="false"&&(F.data[0].flag=="facility")){var E=F.data[0];var K=[E.facilityid,E.fname,E.descr,E.viewdate,this,"defer",C,A,D,B];showConflictMsgBox("facility","Facility Schedule Conflict",E.msg+" Do you want to queue your booking?",K)}else{if(F.data[0].success=="false"&&(F.data[0].flag=="holiday")){var J="Facility Schedule Conflict";var I=F.data[0].msg+" Do you want to queue your booking?";B["queue"]=true;B["holiday"]=false;if(F.data[0].flag=="holiday"){J="Holiday Conflict";I=F.data[0].msg+" Do you want to continue with the booking of class "+F.data[0].name+"?";B["queue"]=false;B["holiday"]=true}Wtf.Msg.show({title:J,msg:I,buttons:Wtf.Msg.YESNO,fn:function(L){if(L=="yes"){this.handleDeferSubmit(C,A,D,B)}else{return }},scope:this,animEl:"elId",icon:Wtf.MessageBox.QUESTION})}else{this.close();this.obj.classStore.load({params:{start:0,limit:15}})}}}}}})},handleBeforeEdit:function(A){if((A.column==5||A.column==6)&&this.sectionStore.getAt(A.row).get("bookingtype")==""){msgBoxShow(["Session Deferment","First select a facility booking type"],Wtf.MessageBox.INFO);return }else{if(A.column==6&&this.sectionStore.getAt(A.row).get("bookingtype")=="Group"){var B=A.value.split(",");if(B.length>0){B="";this.sectionStore.getAt(A.row).set("facilityid",B)}A.cancel=true}else{if(A.column==6&&this.sectionStore.getAt(A.row).get("bookingtype")=="Individual"){this.resourceBookStore.load({params:{groupid:this.sectionStore.getAt(A.row).get("groupid")}})}}}},handleAfterEdit:function(E){if(E.column==4&&E.value=="Group"){this.sectionStore.getAt(E.row).set("facilityid","")}else{if(E.column==4&&E.value=="Individual"){var D=this.sectionStore.getAt(E.row).get("groupid");if(D.length>1){msgBoxShow(["Session Deferment",'You cannot select multiple groups when facility booking type is "Individual"'],Wtf.MessageBox.INFO);D=D[0];this.sectionStore.getAt(E.row).set("groupid",D)}this.resourceBookStore.removeAll();this.sectionStore.getAt(E.row).set("facilityid","");this.resourceBookStore.load({params:{groupid:this.sectionStore.getAt(E.row).get("groupid")}});return }else{if(E.column==5&&this.sectionStore.getAt(E.row).get("bookingtype")=="Individual"){D=E.value.split(",");if(D.length>1){msgBoxShow(["Session Deferment",'You cannot select multiple groups when facility booking type is "Individual"'],Wtf.MessageBox.INFO);D=D[0];this.sectionStore.getAt(E.row).set("groupid",D)}this.resourceBookStore.removeAll();this.sectionStore.getAt(E.row).set("facilityid","");this.resourceBookStore.load({params:{groupid:this.sectionStore.getAt(E.row).get("groupid")}});return }else{if(E.column==7){var B=E.value.format("Y-m-d");var A=this.sdate.getValue().format("Y-m-d");var C=this.edate.getValue().format("Y-m-d");if(B<A||B>C){msgBoxShow(["Session Deferment","The date for a class should be within the session period"],Wtf.MessageBox.INFO);this.sectionStore.getAt(E.row).set("date","");return }}else{if(E.column==8){if(E.value>this.sectionStore.getAt(E.row).get("etime")){msgBoxShow(["Session Deferment","Start time cannot be greater than end time"],Wtf.MessageBox.INFO);this.sectionStore.getAt(E.row).set("stime","");return }}else{if(E.column==9){if(E.value<this.sectionStore.getAt(E.row).get("stime")){msgBoxShow(["Session Deferment","End time cannot be less than start time"],Wtf.MessageBox.INFO);this.sectionStore.getAt(E.row).set("etime","");return }}}}}}}},comboBoxRenderer:function(A){return function(J,K,D,L,C,I){if(J){var F=J.split(",");var G="";if(F.length>0){for(var B=0;B<F.length;B++){var H=A.store.find(A.valueField,F[B]);if(H==-1){continue}var E=A.store.getAt(H);if(B<(F.length-1)){G+=E.get(A.displayField)+","}else{G+=E.get(A.displayField)}}return G}else{return""}}else{return""}}},rejectReq:function(){Wtf.Msg.show({title:"Reject Request",msg:"Are you sure want to reject request?",buttons:Wtf.Msg.YESNO,fn:function(bttn){if(bttn=="yes"){Wtf.Ajax.requestEx({method:"POST",url:"jspfiles/admin/LacaStructure.jsp",params:{flag:89,moduleid:this.moduleid,sessionid:this.sessionid,type:2}},this,function(resp,req){var respobj=eval("("+resp+")");if(respobj.success!=null){if(respobj.success){msgBoxShow(["Success","Request for deferment was rejected."],Wtf.MessageBox.INFO);this.obj.classStore.load({params:{start:0,limit:15}});this.close()}else{if(!respobj.success){if(respobj.msg!=null){msgBoxShow(["Failure",respobj.msg],Wtf.MessageBox.ERROR)}else{msgBoxShow(["Failure","Error occured while connecting to the server"],Wtf.MessageBox.ERROR)}}}}},function(resp,req){})}},scope:this,animEl:"elId",icon:Wtf.MessageBox.QUESTION})},closeWindow:function(A){if(A=="OK"){this.close()}},validateNum:function(){if(Wtf.getCmp("numField333").getValue()>Wtf.getCmp("numField1444").getValue()){return"Minimum value is greater than maximum value"}else{return true}}})