Wtf.quizPanel=function(A){Wtf.apply(this,A);this.id=A.id;this.compId=A.compId;Wtf.quizPanel.superclass.constructor.call(this,A)};Wtf.extend(Wtf.quizPanel,Wtf.Panel,{onRender:function(B){var A=this.compId;Wtf.quizPanel.superclass.onRender.call(this,B);this.addEvents({"publishObject":true,"unlockObject":true});this.existingBttn=new Wtf.menu.Item({text:"Select from existing",icon:"images/s.gif",iconCls:"iconclass",scope:this,handler:function(){this.importWin()}});this.randomBttn=new Wtf.menu.Item({text:"Random questions",icon:"images/s.gif",iconCls:"iconclass",scope:this,handler:function(){this.randomWin()}});this.add(this.quizlayout=new Wtf.Panel({id:"pan1"+this.id,layout:"border",border:false,bodyStyle:"background:#dfe8f6;",bbar:[{id:"previewquiz"+this.id,text:"Preview",type:"submit",disabled:true,scope:this,handler:function(){var E=null;var G=null;if(this.nodeidObj){E="tab"+this.nodeidObj;G=this.nodeVno}else{G=0;E=this.id}var F=null;if(this.cid){F=this.cid}else{F=""}var D="0?"+E+"?simp?"+F+"?"+G;var C="";C+=escape(D);window.open("qpreview.html?"+C,"fs","fullscreen=yes","titlebar=no")}},new Wtf.Toolbar.Button({text:"Import Questions",hidden:(this.owner?false:true),menu:{items:[this.existingBttn,this.randomBttn]}}),{id:"publish"+this.id,text:"Publish",hidden:(Wtf.isContentDesigner()||!(this.owner)||(this.nodeidObj?false:true)),scope:this,handler:function(){var C=(this.id).substring(3);this.publish=new Wtf.data.Store({proxy:new Wtf.data.HttpProxy({url:Wtf.req.lms+"metagrid.jsp"}),reader:new Wtf.data.JsonReader({root:"data"},["success"])});this.publish.on("load",this.pubresp,this);this.publish.load({params:{flag:"2",loid:C}})}},{text:"Unlock",hidden:!(this.owner)||(this.nodeidObj?false:true),scope:this,handler:function(){Wtf.Ajax.request({url:Wtf.req.lms+"catalog.jsp",method:"GET",params:({objid:this.nodeidObj,flag:9}),scope:this,success:function(D,C){this.fireEvent("unlockObject");Wtf.MessageBox.show({title:"Success",msg:"Lock successfully released",buttons:Wtf.MessageBox.OK,fn:this.closeTab,scope:this,icon:Wtf.MessageBox.INFO})},failure:function(){Wtf.Msg.alert("Error","Error occurred while connecting to the server")}})}}],items:[{region:"north",split:true,border:false,id:"northpanel"+this.id,height:250,layout:"fit",items:[this.grid=new Wtf.EditorGridComp({id:"gridCompo"+this.id,compId:this.compId,flag:this.flag,combId:this.id,border:false,nodeidObj:this.nodeidObj,innertab:this.innertab,nodeVno:this.nodeVno,stripeRows:true,collapsible:true,animCollapse:false,owner:this.owner})]},{region:"center",layout:"fit",autoScroll:true,bodyStyle:"background:white;",border:false,items:[new Wtf.Panel({id:"inner1"+this.id,border:false,split:true,layout:"fit",autoScroll:true})]}]}));this.mb=new Wtf.Window({height:100,title:"New Tag",modal:true,width:250,scope:this,resizable:false,bodyStyle:"margin: 10px 0 0 10px;float: right;",items:[this.tagField=new Wtf.form.TextField({width:210,scope:this,validator:this.alphaNumCheck,invalidText:"The value in this field is invalid. Only alphabets, numerals and space allowed."})],buttons:[{text:"OK",scope:this,handler:function(C,E){var D=this.tagField.getValue().trim();if(D.length>0&&this.tagField.isValid()){Wtf.Ajax.request({url:Wtf.req.lms+"fetchTags.jsp",method:"GET",params:({tag:D,flag:1}),scope:this,success:function(G,F){this.allResources.reload()},failure:function(){Wtf.Msg.alert("Error","Error occurred while connecting to the server")}});this.mb.close()}}},{text:"Cancel",scope:this,handler:function(){this.mb.close()}}]});this.loadMask=new Wtf.LoadMask(this.el.dom,{msg:"Saving.."});this.loadQuiz=new Wtf.LoadMask(this.el.dom,{msg:"Loading..."});if(Wtf.isIE){this.addListener("activate",this.handleActivate,this)}},handleActivate:function(A){A.doLayout();var B=(Wtf.getCmp("northpanel"+this.id).getSize().height<200)?200:Wtf.getCmp("northpanel"+this.id).getSize().height;Wtf.getCmp("northpanel"+this.id).setHeight(B);A.doLayout()},closeTab:function(){this.ownerCt.remove(this)},showWin:function(A){var B=A.getValue();if(B==1){this.importWin()}else{this.randomWin()}},importWin:function(){this.iwin=new Wtf.Window({title:"Import from Question Bank",width:700,height:500,resizable:false,autoDestroy:true,modal:true,border:false,layout:"border",items:[{region:"north",height:70,border:false,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",html:getHeader("images/createuser.gif","Import from Question Bank","Import one or more questions from the question bank")},{region:"center",layout:"fit",border:false,items:[this.qbGrid=new Wtf.lms.qBankGrid({id:"this"+this.id,flag:1})]}],buttons:[{text:"Import",scope:this,handler:function(){var C=this.qbGrid.getStore();var B=this.qbGrid.getColModel();var G=this.qbGrid.getSelModel();var A=G.getSelections();var E="";var F;for(var D=0;D<A.length;D++){E+=A[D].data["quesid"]+","}if(E.length>0){E=E.substr(0,(E.length-1))}if(this.nodeidObj){F=this.nodeidObj}else{F=(this.id).substring(3)}Wtf.Ajax.request({url:Wtf.req.lms+"importQuestion.jsp",method:"POST",params:({idString:E,id:F}),scope:this,success:function(J,I){var H=this.grid.getStore();H.reload();this.iwin.close()},failure:function(){Wtf.Msg.alert("Error","Error occurred while connecting to the server")}})}},{text:"Cancel",scope:this,handler:function(){this.iwin.close()}}]});this.iwin.show()},randomWin:function(){this.RES=Wtf.data.Record.create([{name:"tagid",type:"string"},{name:"tagname",type:"string"},{name:"check"}]);this.allResources=new Wtf.data.Store({url:Wtf.req.lms+"fetchTags.jsp",reader:new Wtf.data.JsonReader({root:"data",id:"res-reader"},this.RES)});this.MSComboconfig={store:this.allResources,displayField:"tagname",valueField:"tagid",triggerAction:"all",mode:"local"};this.rwin=new Wtf.Window({title:"Random Question",width:500,height:360,resizable:false,autoDestroy:true,modal:true,border:false,items:[{region:"north",height:75,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",border:false,html:getHeader("images/createuser.gif","Random Question","Choose the number of random questions you want to add to the quiz. You can also specify the difficulty range")},{region:"center",border:false,bodyStyle:"background:#f1f1f1;",height:300,items:[this.form1=new Wtf.FormPanel({url:Wtf.req.lms+"randomQuestion.jsp",waitMsgTarget:true,method:"POST",border:false,bodyStyle:"margin-top:20px;margin-left:35px;font-size:10px;",layout:"form",items:[this.nameField=new Wtf.form.NumberField({fieldLabel:"Number of questions*",name:"number",allowBlank:false,emptyText:10,labelWidth:180,scope:this,width:80,maxValue:100}),{xtype:"fieldset",title:"Difficulty",height:100,width:350,items:[this.minField=new Wtf.form.NumberField({fieldLabel:"Minimum*",emptyText:1,labelWidth:120,scope:this,width:80,name:"min",allowDecimals:false,allowNegative:false,allowBlank:false,maxValue:10,validator:function(B){var A=Wtf.getCmp("max").getValue();if(parseInt(B)<A){return true}else{return"Please specify a value less than the maximum value"}}}),this.maxField=new Wtf.form.NumberField({fieldLabel:"Maximum*",id:"max",emptyText:10,labelWidth:120,scope:this,width:80,name:"max",allowDecimals:false,allowNegative:false,allowBlank:false,maxValue:10})]},{layout:"column",border:false,items:[{width:280,border:false,layout:"form",items:[this.multi=new Wtf.common.Select(Wtf.applyIf({multiSelect:true,fieldLabel:"Tags",forceSelection:true},this.MSComboconfig))]},{border:false,layout:"form",items:[{xtype:"button",text:"New Tag",scope:this,handler:function(){this.allResources.load({params:{flag:0}});this.mb.show()}}]}]}]})]}],buttons:[{text:"Import",scope:this,handler:function(){var A;if(this.nodeidObj){A=this.nodeidObj}else{A=this.id.substring(3)}this.form1.form.submit({waitMsg:"Loading...",scope:this,params:{id:A,tags:this.multi.getValue()},failure:function(C,B){Wtf.MessageBox.show({title:"Failure",msg:"Error connecting to server. Please try again.",buttons:Wtf.MessageBox.OK,scope:this,fn:function(){this.rwin.close()},icon:Wtf.MessageBox.INFO})},success:function(D,B){var C=Wtf.decode(B.response.responseText.trim());this.grid.getStore().reload();var E;if(C.number){rmsg=C.number+" Questions imported successfully."}else{if(C.number==0){rmsg="Questions are not available according to this criteria."}else{rmsg="Questions imported successfully."}}Wtf.MessageBox.show({title:"Success",msg:rmsg,buttons:Wtf.MessageBox.OK,scope:this,fn:function(){this.rwin.close()},icon:Wtf.MessageBox.INFO})}})}},{text:"Cancel",scope:this,handler:function(){this.rwin.close()}}]});this.rwin.show();this.allResources.load({params:{flag:0}})},pubresp:function(B,C,A){if(C[0].json.Success=="true"){this.fireEvent("publishObject");Wtf.MessageBox.alert("Status","Object published successfully")}else{if(C[0].json.Success=="false"){msgBoxShow(["Status","There is no change to publish this object."])}else{Wtf.MessageBox.alert("Status","Problem in publishing Object")}}}})