YUI.add("moodle-core-chooserdialogue",function(s,e){var t=function(){t.superclass.constructor.apply(this,arguments)};s.extend(t,s.Base,{panel:null,submitbutton:null,container:null,listenevents:[],bodycontent:null,headercontent:null,instanceconfig:null,hiddenRadioValue:null,setup_chooser_dialogue:function(e,t,i){this.bodycontent=e,this.headercontent=t,this.instanceconfig=i},prepare_chooser:function(){if(!this.panel){s.one(s.config.doc.body).addClass("jschooser");var e,t={bodyContent:this.bodycontent.get("innerHTML"),headerContent:this.headercontent.get("innerHTML"),width:"540px",draggable:!0,visible:!1,zindex:100,modal:!0,shim:!0,closeButtonTitle:this.get("closeButtonTitle"),focusOnPreviousTargetAfterHide:!0,render:!1,extraClasses:this._getClassNames()};for(e in this.instanceconfig)t[e]=this.instanceconfig[e];this.panel=new M.core.dialogue(t),this.bodycontent.remove(),this.headercontent.remove(),this.panel.hide(),this.panel.render(),this.container=this.panel.get("boundingBox").one(".choosercontainer"),this.options=this.container.all(".option input[type=radio]"),this.hiddenRadioValue=s.Node.create('<input type="hidden" value="" />'),this.container.one("form").appendChild(this.hiddenRadioValue),this.panel.get("boundingBox").addClass("chooserdialogue")}},display_chooser:function(e){var t,i,n;this.prepare_chooser(),e.preventDefault(),t=this.panel.get("boundingBox"),i=this.container.one(".alloptions"),n=s.one("document").on("orientationchange",function(){this.center_dialogue(i)},this),this.listenevents.push(n),n=s.one("window").on("resize",function(){this.center_dialogue(i)},this),this.listenevents.push(n),n=this.container.on("click",this.check_options,this),this.listenevents.push(n),n=this.container.on("key_up",this.check_options,this),this.listenevents.push(n),n=this.container.on("dblclick",function(e){e.target.ancestor("div.option")&&(this.check_options(),this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents(),this.container.one("form").submit())},this),this.listenevents.push(n),this.container.one("form").on("submit",function(){this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents()},this),n=this.container.one(".addcancel").on("click",this.cancel_popup,this),this.listenevents.push(n),n=t.one("button.closebutton").on("click",this.cancel_popup,this),this.listenevents.push(n),n=s.one("document").on("keydown",this.handle_key_press,this),this.listenevents.push(n),this.submitbutton=this.container.one(".submitbutton"),this.submitbutton.set("disabled","true"),this.options.removeAttribute("disabled"),this.panel.show(e),this.center_dialogue(i),this.container.one(".option input[type=radio]").focus(),this.check_options()},cancel_listenevents:function(){for(;this.listenevents.length;)this.listenevents.shift().detach()},center_dialogue:function(e){var t,i=this.panel.get("boundingBox"),n=i.get("winHeight");if(this.panel.shouldResizeFullscreen())return e.setStyle("maxHeight","100%"),e.setStyle("height","auto"),void this.panel.makeResponsive();(t=n<=(t=this.get("maxheight"))?n<=this.get("minheight")?this.get("minheight"):n:t)>this.get("minheight")?this.panel.lockScroll&&!this.panel.lockScroll.isActive()&&this.panel.lockScroll.enableScrollLock(!0):this.panel.lockScroll&&this.panel.lockScroll.isActive()&&this.panel.lockScroll.disableScrollLock(),n=t,e.setStyle("maxHeight",(t-=156)+"px"),(t=(t=i.getStyle("height")).match(/.*px$/)?t.replace(/px$/,""):n)<this.get("baseheight")?(t=this.get("baseheight"),e.setStyle("height",t+"px")):e.setStyle("height","auto"),this.panel.centerDialogue()},handle_key_press:function(e){27===e.keyCode&&this.cancel_popup(e)},cancel_popup:function(e){e.preventDefault(),this.hide()},hide:function(){this.cancel_listenevents(),this.container.detachAll(),this.panel.hide()},check_options:function(){this.options.each(function(e){var t=e.get("parentNode").get("parentNode");e.get("checked")?(t.addClass("selected"),this.option_selected(e),this.submitbutton.removeAttribute("disabled"),e.focus()):t.removeClass("selected")},this)},option_selected:function(e){this.hiddenRadioValue.setAttrs({value:e.get("value"),name:e.get("name")})},_getClassNames:function(e){var t,i="chooserdialogue-"+this.name,n=[];if(n.push(i.toLowerCase()),e)for(t in e)n.push((i+"-"+t).toLowerCase());return n}},{NAME:"moodle-core-chooserdialogue",ATTRS:{minheight:{value:300},baseheight:{value:400},maxheight:{value:660},closeButtonTitle:{validator:s.Lang.isString,value:"Close"}}}),M.core=M.core||{},M.core.chooserdialogue=t},"@VERSION@",{requires:["base","panel","moodle-core-notification"]});