YUI.add('moodle-core_filepicker',function(Y){Y.Node.prototype.getStylePx=function(attr){var style=this.getStyle(attr);if(''+style=='0'||''+style=='0px'){return 0}
var matches=style.match(/^([\d\.]+)px$/)
if(matches&&parseFloat(matches[1])){return parseFloat(matches[1])}
return null}
Y.Node.prototype.addClassIf=function(className,condition){if(condition){this.addClass(className)}else{this.removeClass(className)}
return this}
Y.Node.prototype.setStyleAdv=function(stylename,value){var stylenameCap=stylename.substr(0,1).toUpperCase()+stylename.substr(1,stylename.length-1).toLowerCase();this.setStyle(stylename,''+Math.max(value,this.getStylePx('min'+stylenameCap))+'px')
return this}
Y.Node.prototype.setImgSrc=function(src,realsrc,lazyloading){if(realsrc){if(M.core_filepicker.loadedpreviews[realsrc]){this.set('src',realsrc).addClass('realpreview');return this}else{if(!this.get('id')){this.generateID()}
lazyloading[this.get('id')]=realsrc}}
this.set('src',src);return this}
Y.Node.prototype.setImgRealSrc=function(lazyloading){if(this.get('id')&&lazyloading[this.get('id')]){var newsrc=lazyloading[this.get('id')];M.core_filepicker.loadedpreviews[newsrc]=!0;this.set('src',newsrc).addClass('realpreview');delete lazyloading[this.get('id')];var treenode=this.ancestor('.fp-treeview')
if(treenode&&treenode.get('parentNode').treeview){treenode.get('parentNode').treeview.getRoot().refreshPreviews(this.get('id'),newsrc)}}
return this}
Y.YUI2.widget.Node.prototype.refreshPreviews=function(imgid,newsrc,regex){if(!regex){regex=new RegExp("
]*id=\""+imgid+"\"[^>]*?(/?)>","im")}
if(this.expanded||this.isLeaf){var html=this.getContentHtml();if(html&&this.setHtml&®ex.test(html)){var newhtml=this.html.replace(regex,"
",html);this.setHtml(newhtml);return!0}
if(!this.isLeaf&&this.children){for(var c in this.children){if(this.children[c].refreshPreviews(imgid,newsrc,regex)){return!0}}}}
return!1}
Y.Node.prototype.fp_display_filelist=function(options,fileslist,lazyloading){var viewmodeclassnames={1:'fp-iconview',2:'fp-treeview',3:'fp-tableview'};var classname=viewmodeclassnames[options.viewmode];var scope=this;var file_is_folder=function(node){if(node.children){return!0}
if(node.type&&node.type=='folder'){return!0}
return!1};var file_get_filename=function(node){return node.title?node.title:node.fullname};var file_get_displayname=function(node){var displayname=node.shorttitle?node.shorttitle:file_get_filename(node);return Y.Escape.html(displayname)};var file_get_description=function(node){var description='';if(node.description){description=node.description}else if(node.thumbnail_title){description=node.thumbnail_title}else{description=file_get_filename(node)}
return Y.Escape.html(description)};var build_tree=function(node,level){var el=Y.Node.create('
');el.appendChild(options.filenode.cloneNode(!0));el.one('.fp-filename').setContent(file_get_displayname(node));var tmpnodedata={className:options.classnamecallback(node)};el.get('children').addClass(tmpnodedata.className);if(node.icon){el.one('.fp-icon').appendChild(Y.Node.create('
'));el.one('.fp-icon img').setImgSrc(node.icon,node.realicon,lazyloading)}
tmpnodedata.html=el.getContent();var tmpNode=new Y.YUI2.widget.HTMLNode(tmpnodedata,level,!1);if(node.dynamicLoadComplete){tmpNode.dynamicLoadComplete=!0}
tmpNode.fileinfo=node;tmpNode.isLeaf=!file_is_folder(node);if(!tmpNode.isLeaf){if(node.expanded){tmpNode.expand()}
tmpNode.path=node.path?node.path:(node.filepath?node.filepath:'');for(var c in node.children){build_tree(node.children[c],tmpNode)}}};var initialize_tree_view=function(){var parentid=scope.one('.'+classname).get('id');scope.treeview=new Y.YUI2.widget.TreeView(parentid);if(options.dynload){scope.treeview.setDynamicLoad(Y.bind(options.treeview_dynload,options.callbackcontext),1)}
scope.treeview.singleNodeHighlight=!0;if(options.filepath&&options.filepath.length){var mytree={};var mytreeel=null;for(var i in options.filepath){if(mytreeel==null){mytreeel=mytree}else{mytreeel.children=[{}];mytreeel=mytreeel.children[0]}
var pathelement=options.filepath[i];mytreeel.path=pathelement.path;mytreeel.title=pathelement.name;mytreeel.icon=pathelement.icon;mytreeel.dynamicLoadComplete=!0;mytreeel.expanded=!0}
mytreeel.children=fileslist;build_tree(mytree,scope.treeview.getRoot());if(options.dynload){var root=scope.treeview.getRoot();var isSearchResult=typeof options.callbackcontext.active_repo!=='undefined'&&options.callbackcontext.active_repo.issearchresult;while(root&&root.children&&root.children.length){root=root.children[0];if(root.path==mytreeel.path){root.origpath=options.filepath;root.origlist=fileslist}else if(!root.isLeaf&&root.expanded&&!isSearchResult){Y.bind(options.treeview_dynload,options.callbackcontext)(root,null)}}}}else{for(k in fileslist){build_tree(fileslist[k],scope.treeview.getRoot())}}
scope.treeview.subscribe('clickEvent',function(e){e.node.highlight(!1);var callback=options.callback;if(options.rightclickcallback&&e.event.target&&Y.Node(e.event.target).ancestor('.fp-treeview .fp-contextmenu',!0)){callback=options.rightclickcallback}
Y.bind(callback,options.callbackcontext)(e,e.node.fileinfo);Y.YUI2.util.Event.stopEvent(e.event)});scope.treeview.subscribe('enterKeyPressed',function(node){if(node.children.length===0){Y.one(node.getContentEl()).one('a').simulate('click')}});scope.treeview.draw()};var formatValue=function(o){if(o.data[''+o.column.key+'_f_s']){return o.data[''+o.column.key+'_f_s']}else if(o.data[''+o.column.key+'_f']){return o.data[''+o.column.key+'_f']}else if(o.value){return o.value}else{return''}};var formatTitle=function(o){var el=Y.Node.create('');el.appendChild(options.filenode.cloneNode(!0));el.get('children').addClass(o.data.classname);el.one('.fp-filename').setContent(o.value);if(o.data.icon){el.one('.fp-icon').appendChild(Y.Node.create('
'));el.one('.fp-icon img').setImgSrc(o.data.icon,o.data.realicon,lazyloading)}
if(options.rightclickcallback){el.get('children').addClass('fp-hascontextmenu')}
return el.getContent()}
var formatCheckbox=function(o){var el=Y.Node.create('');var checkbox=Y.Node.create('').setAttribute('type','checkbox').setAttribute('data-fieldtype','checkbox').setAttribute('data-fullname',o.data.fullname).setAttribute('data-action','toggle').setAttribute('data-toggle','slave').setAttribute('data-togglegroup','file-selections').setAttribute('data-toggle-selectall',M.util.get_string('selectall','moodle')).setAttribute('data-toggle-deselectall',M.util.get_string('deselectall','moodle'));var checkboxLabel=Y.Node.create('