Wtf.randomQuiz=function(A){Wtf.apply(this,A);Wtf.randomQuiz.superclass.constructor.call(this,A);this.save=1};Wtf.extend(Wtf.randomQuiz,Wtf.Panel,{onRender:function(A){Wtf.randomQuiz.superclass.onRender.call(this,A);this.addEvents({"unlockObject":true,"publishRandomQuiz":true});this.dsstore=new Wtf.data.Store({url:Wtf.req.lms+"quiz.jsp",reader:new Wtf.data.JsonReader({root:"data"},["noq","mind","maxd","tags"])});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.add(this.top=new Wtf.Panel({border:false,layout:"border",bodyStyle:"background:transparent;",items:[{region:"north",border:false,height:90,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",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",layout:"fit",border:false,items:[this.form1=new Wtf.FormPanel({url:Wtf.req.lms+"quiz.jsp?flag=6",waitMsgTarget:true,method:"POST",border:false,layout:"fit",bodyStyle:"margin-top:20px;margin-left:35px;font-size:10px;",layout:"form",labelWidth:130,items:[this.nameField=new Wtf.form.NumberField({fieldLabel:"Number of questions*",name:"number",allowBlank:false,scope:this,width:165,maxValue:100}),this.minField=new Wtf.form.NumberField({fieldLabel:"Minimum Difficulty*",scope:this,width:165,name:"min",allowDecimals:false,allowNegative:false,allowBlank:false,maxValue:10}),this.maxField=new Wtf.form.NumberField({fieldLabel:"Maximum Difficulty*",scope:this,width:165,name:"max",allowDecimals:false,allowNegative:false,allowBlank:false,maxValue:10}),{layout:"column",border:false,items:[{columnWidth:1,border:false,layout:"form",items:[this.multi=new Wtf.common.Select(Wtf.applyIf({multiSelect:true,fieldLabel:"Tags",forceSelection:true},this.MSComboconfig))]}]}]})]}],bbar:[{text:"Preview",scope:this,handler:function(){var E=null;var B=null;if(this.cid){E=this.cid}else{E=""}if(this.vid){B=this.vid}else{B=0}var D="0?tab"+this.nodeid+"?rand?"+E+"?"+B;var C="";C+=escape(D);window.open("qpreview.html?"+C,"fs","fullscreen=yes","titlebar=no")}},{id:"publish"+this.id,text:"Publish",hidden:(Wtf.isContentDesigner()||!(this.owner)||(this.nodeidObj?false:true)),scope:this,handler:function(){var B=(this.id).substring(3);this.publish=new Wtf.data.Store({proxy:new Wtf.data.HttpProxy({url:Wtf.req.lms+"catalog.jsp"}),reader:new Wtf.data.JsonReader({root:"data"},["success"])});this.publish.on("load",this.pubresp,this);this.publish.load({params:{flag:"7",loid:B}})}},{text:"Save",scope:this,hidden:!(this.owner)?true:false,handler:function(){this.rquizSave()}},{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.nodeid,flag:9}),scope:this,success:function(C,B){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")}})}}]}));this.allResources.load({params:{flag:0}});if(this.vid){this.dsstore.load({params:{flag:"10",nodeid:this.nodeid,vid:this.vid}})}else{this.dsstore.load({params:{flag:"7",nodeid:this.nodeid,cid:this.cid}})}this.dsstore.on("load",this.loadData,this);this.nameField.on("change",this.valueChange,this);this.minField.on("change",this.valueChange,this);this.maxField.on("change",this.valueChange,this);this.loadMask=new Wtf.LoadMask(this.el.dom,{msg:"Saving.."});this.loadrQuiz=new Wtf.LoadMask(this.el.dom,{msg:"Loading..."})},valueChange:function(){this.save=0},rquizSave:function(){var B=this.minField.getValue();var A=this.maxField.getValue();if(A<B){this.maxField.markInvalid("Please specify value greater than min difficulty")}else{var C;C=this.nodeid;var D=this.nameField.getValue();if(this.form1.form.isValid()){this.form1.form.submit({waitMsg:"Saving...",scope:this,params:{id:C,tags:this.multi.getValue(),min:this.minField.getValue(),max:this.maxField.getValue(),number:D,cid:this.cid},success:function(H,E){this.save=1;var F=Wtf.decode(E.response.responseText);var G;if(F.no<D){G=F.no+" Questions are available according to this criteria"}else{G="Questions are added successfully"}msgBoxShow(["Success",G],Wtf.MessageBox.INFO)},failure:function(F,E){msgBoxShow(["Failure","Error connecting to server. Please try again"],Wtf.MessageBox.INFO)}})}}},closeTab:function(){this.ownerCt.remove(this)},pubresp:function(B,C,A){if(C[0].json.Success=="true"){this.fireEvent("publishRandomQuiz");Wtf.MessageBox.alert("Status","Object published successfully")}else{if(C[0].json.Success=="false"){msgBoxShow(["Warning","There is no change to publish this object."])}else{Wtf.MessageBox.alert("Status","Problem in publishing Object")}}},loadData:function(D,F,B){this.loadrQuiz.hide();var E,H,C;var A=[];E=F[0].data.noq;H=F[0].data.mind;C=F[0].data.maxd;for(var G=1;G<F.length;G++){A.push(F[G].data.tags)}this.nameField.setValue(E);this.minField.setValue(H);this.maxField.setValue(C);this.multi.setValue(A);if(!this.owner){this.nameField.disable();this.minField.disable();this.maxField.disable();this.multi.disable()}}})