mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
c28bf5c9f8
Also, some related JavaScript cleanup. More to follow.
1 line
26 KiB
JavaScript
1 line
26 KiB
JavaScript
var repository_listing={};var cached_client_id={};var file_extensions={};var new_filename="";var cached_id;var cached_repo_id;var repository_client=(function(){var a="2.0";var d=(10*2);function b(){alert(a)}function c(h,f){if(YAHOO.env.ua.ie==6){var g=document.getElementById("file-picker-"+h);g.style.width=f}}function e(){this.create_filepicker=function(o){var m=(YAHOO.env.ua.ie&&document.compatMode=="BackCompat");var j=(YAHOO.env.ua.ie==6||(YAHOO.env.ua.ie==7&&m));var n={label:fp_lang.listview,value:"l",onclick:{fn:repository_client.view_as_list,obj:o}};var f={label:fp_lang.thumbview,value:"t",onclick:{fn:repository_client.view_as_icons,obj:o}};var h=document.createElement("DIV");h.id="file-picker-"+o;h.className="file-picker";this.client_id=o;document.body.appendChild(h);this.filepicker=new YAHOO.widget.Panel("file-picker-"+o,{draggable:true,close:true,underlay:"none",zindex:666666,xy:[50,YAHOO.util.Dom.getDocumentScrollTop()+20]});var l="";this.filepicker.client_id=o;this.filepicker.setHeader(fp_lang.title);this.filepicker.setBody('<div id="layout-'+o+'"></div>');this.filepicker.beforeRenderEvent.subscribe(function(){YAHOO.util.Event.onAvailable("layout-"+o,function(){l=new YAHOO.widget.Layout("layout-"+o,{height:480,width:700,units:[{position:"top",height:32,resize:false,body:'<div class="yui-buttongroup fp-viewbar" id="repo-viewbar-'+o+'"></div><div class="fp-searchbar" id="search-div-'+o+'"></div>',gutter:"2"},{position:"left",width:200,resize:true,scroll:true,body:'<ul class="fp-list" id="repo-list-'+o+'"></ul>',gutter:"0 5 0 2",minWidth:150,maxWidth:300},{position:"center",body:'<div class="fp-panel" id="panel-'+o+'"></div>',scroll:true,gutter:"0 2 0 0"}]});l.render()})});var g=new YAHOO.util.Resize("file-picker-"+o,{handles:["br"],autoRatio:true,status:true,minWidth:680,minHeight:400});c(o,"680px");g.on("resize",function(q){var r=q.height;var p=this.header.offsetHeight;var t=(r-p);var s=(m)?t:t-d;YAHOO.util.Dom.setStyle(this.body,"height",s+"px");c(this.client_id,"680px");if(j){this.sizeUnderlay();this.syncIframe()}l.set("height",s);l.set("width",(q.width-d));l.resize()},this.filepicker,true);repository_client.fp[o].viewbar=new YAHOO.widget.ButtonGroup({id:"btngroup-"+o,name:"buttons",disabled:true,container:"repo-viewbar-"+o});repository_client.fp[o].viewbar.addButtons([f,n]);this.print_listing();this.filepicker.render()};this.init_search=function(){var f=document.getElementById("search-div-"+this.client_id);f.innerHTML='<input id="search-input-'+this.client_id+'" /><button id="search-btn-'+this.client_id+'">'+fp_lang.federatedsearch+"</button>";var g=new YAHOO.util.Element("search-btn-"+this.client_id);g.client_id=this.client_id;var h=new YAHOO.util.Element("search-input-"+this.client_id);h.client_id=this.client_id;g.fnSearch=function(o){var m=new YAHOO.util.Element("search-input-"+this.client_id);var j=m.get("value");var n=repository_client.fp[this.client_id];var p=[];p.s=j;p.env=n.env;p.accepted_types=n.accepted_types;p.sesskey=moodle_cfg.sesskey;p.ctx_id=fp_config.contextid;p.client_id=this.client_id;repository_client.loading(this.client_id,"load");var l=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=gsearch",this.search_cb,repository_client.postdata(p))};g.on("contentReady",function(){g.on("click",this.fnSearch,this.input_keyword)});g.search_cb={success:function(p){var n=repository_client.parse_json(p.responseText,"global_search_cb");var j=new YAHOO.util.Element("panel-"+n.client_id);if(!n.list||n.list.length<1){j.get("element").innerHTML=fp_lang.noresult;return}var m=repository_client.fp[n.client_id];m.view_staus=0;m.fs=n.list;if(n.gsearch){m.gsearch=true}if(m.view_staus){repository_client.view_as_list(n.client_id,n.list)}else{repository_client.view_as_icons(n.client_id,n.list)}var l=new YAHOO.util.Element("search-input-"+n.client_id);l.set("value","")}};h.on("contentReady",function(){var j=document.getElementById("search-input-"+this.client_id);var l=new YAHOO.util.KeyListener(j,{keys:13},{fn:function(){this.fnSearch()},scope:g,correctScope:true});l.enable()})};this.print_listing=function(){var f=new YAHOO.util.Element("repo-list-"+this.client_id);f.set("innerHTML","");f.on("contentReady",function(){this.init_search();for(var m in repository_listing[this.client_id]){var l=repository_listing[this.client_id][m];var o=false;if(this.env=="editor"&&this.accepted_types!="*"){if(l.supported_types!="*"){for(var h in l.supported_types){if(mdl_in_array(l.supported_types[h],this.accepted_types)){o=true}}}}else{o=true}if(l.supported_types=="*"||o){var g=document.createElement("li");g.id="repo-"+this.client_id+"-"+l.id;var n=document.createElement("img");n.src=l.icon;n.width="16";n.height="16";var p=document.createElement("a");p.href="###";p.id="repo-call-"+this.client_id+"-"+l.id;p.appendChild(n);p.className="fp-repo-name";p.innerHTML+=" "+l.name;p.onclick=function(){var s=new RegExp("repo-call-(\\w+)-(\\d+)","i");var j=this.id.match(s);var v=j[1];var r=j[2];for(var u in repository_listing[v]){var t="repo-call-"+v+"-"+u;var q=document.getElementById(t);if(q){q.style.background="transparent"}}this.style.background="#CCC";repository_client.req(v,r,"")};g.appendChild(p);f.appendChild(g);l=null}}},this,true)};this.show=function(){this.print_listing();var f=new YAHOO.util.Element("panel-"+this.filepicker.client_id);f.get("element").innerHTML="";this.filepicker.show()};this.hide=function(){this.filepicker.hide()}}e.fp={};return e})();repository_client.req=function(g,f,d,c){repository_client.loading(g,"load");this.fp[g].viewbar.set("disabled",false);var b=repository_client.fp[g];var e=[];e.p=d;e.env=b.env;e.sesskey=moodle_cfg.sesskey;e.ctx_id=fp_config.contextid;e.client_id=g;e.repo_id=f;if(!!c){e.page=c}e.accepted_types=b.accepted_types;var a=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=list",this.req_cb,this.postdata(e))};repository_client.req_cb={success:function(d){var c=repository_client.parse_json(d.responseText,"req_cb");var b=repository_client.fp[c.client_id];b.viewbar.set("disabled",false);var a=new YAHOO.util.Element("panel-"+c.client_id);if(c&&c.e){a.get("element").innerHTML=c.e;return}b.fs=c;if(!c){return}else{if(c.msg){repository_client.print_msg(c.msg)}else{if(c.iframe){repository_client.view_iframe(c.client_id)}else{if(c.login){b.viewbar.set("disabled",true);repository_client.print_login(c.client_id,c)}else{if(c.list){if(b.view_status){repository_client.view_as_list(c.client_id,c.list)}else{repository_client.view_as_icons(c.client_id,c.list)}}}}}}}};repository_client.view_iframe=function(c){var a=repository_client.fp[c].fs;var b=new YAHOO.util.Element("panel-"+c);b.get("element").innerHTML='<iframe frameborder="0" width="98%" height="400px" src="'+a.iframe+'" />'};repository_client.req_search_results=function(g,f,d,c){repository_client.loading(g,"load");this.fp[g].viewbar.set("disabled",false);var b=repository_client.fp[g];var e=[];e.p=d;e.env=b.env;e.sesskey=moodle_cfg.sesskey;e.ctx_id=fp_config.contextid;e.client_id=g;e.search_paging="true";e.repo_id=f;if(!!c){e.page=c}e.accepted_types=b.accepted_types;var a=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=search",this.req_cb,this.postdata(e))};repository_client.print_login=function(b,h){var n=h.login;var a=new YAHOO.util.Element("panel-"+b);var f="login";if(h.login_search_form){f="search"}var m='<div class="fp-login-form" onkeypress="repository_client.login_keypress(event,\''+f+"')\">";var e=false;this.fp[b].login=n;m+='<table width="100%">';for(var g in n){m+="<tr>";if(n[g].type=="popup"){m+='<td colspan="2"><p class="fp-popup">'+fp_lang.popup+"</p>";m+='<p class="fp-popup"><button onclick="repository_client.popup(\''+b+"', '"+n[g].url+"')\">"+fp_lang.login+"</button>";m+="</p></td>";e=true}else{if(n[g].type=="textarea"){m+='<td colspan="2"><p><textarea id="'+n[g].id+'" name="'+n[g].name+'"></textarea></p></td>'}else{var d="";var o="";var q="";if(n[g].id){d=' for="'+n[g].id+'"';o=' id="'+n[g].id+'"'}if(n[g].label){m+='<td align="right"><label'+d+">"+n[g].label+"</label> </td>"}if(n[g].value){q=' value="'+n[g].value+'"'}if(n[g].type=="radio"){var l=n[g].value.split("|");var j=n[g].value_label.split("|");m+='<td align="left">';for(var p in l){m+='<input type="'+n[g].type+'" name="'+n[g].name+'"'+o+' value="'+l[p]+'" />'+j[p]+"<br />"}m+="</td>"}else{m+='<td align="left"><input type="'+n[g].type+'" name="'+n[g].name+'"'+q+" /></td>"}}}m+="</tr>"}m+="</table>";var c=h.login_btn_label?h.login_btn_label:fp_lang.submit;if(h.login_search_form){m+='<p><input type="button" onclick="repository_client.search(\''+b+"', '"+h.repo_id+'\')" value="'+c+'" /></p>'}else{if(!e){m+='<p><input type="button" onclick="repository_client.login(\''+b+"', '"+h.repo_id+'\')" value="'+c+'" /></p>'}}m+="</div>";a.get("element").innerHTML=m;cached_id=b;cached_repo_id=h.repo_id};repository_client.login=function(g,d){var f=[];var e=this.fp[g].login;for(var a in e){if(e[a].type!="popup"){var c=document.getElementsByName(e[a].name)[0];f[e[a].name]="";if(c.type=="checkbox"){f[e[a].name]=c.checked}else{f[e[a].name]=c.value}}}f.env=this.fp[g].env;f.repo_id=d;f.client_id=g;f.ctx_id=fp_config.contextid;f.sesskey=moodle_cfg.sesskey;f.accepted_types=this.fp[g].accepted_types;this.loading(g,"load");var b=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=sign",this.req_cb,this.postdata(f))};repository_client.login_keypress=function(a,c){a=(a)?a:((window.event)?window.event:"");var b=a.keyCode?a.keyCode:a.which;if(b==13||b==10){if(c=="search"){repository_client.search(cached_id,cached_repo_id)}else{repository_client.login(cached_id,cached_repo_id)}}};repository_client.search=function(a,h){var c=[];var e=this.fp[a].login;for(var d in e){if(e[d].type!="popup"){var b=document.getElementsByName(e[d].name)[0];c[e[d].name]="";if(b.type=="checkbox"){c[e[d].name]=b.checked}else{if(b.type=="radio"){var f=document.getElementsByName(e[d].name);for(var g in f){if(f[g].checked){c[e[d].name]=f[g].value}}}else{c[e[d].name]=b.value}}}}c.env=this.fp[a].env;c.repo_id=h;c.client_id=a;c.ctx_id=fp_config.contextid;c.sesskey=moodle_cfg.sesskey;c.accepted_types=this.fp[a].accepted_types;this.loading(a,"load");var j=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=search",this.req_cb,this.postdata(c))};repository_client.loading=function(g,e,d){var b=new YAHOO.util.Element("panel-"+g);b.get("element").innerHTML="";var f=document.createElement("div");f.style.textAlign="center";var a=document.createElement("P");var c=document.createElement("IMG");if(e=="load"){c.src=moodle_cfg.pixpath+"/i/loading.gif";a.innerHTML=fp_lang.loading}else{c.src=moodle_cfg.pixpath+"/i/progressbar.gif";a.innerHTML=fp_lang.copying+" <strong>"+d+"</strong>"}f.appendChild(a);f.appendChild(c);b.get("element").appendChild(f)};repository_client.view_as_list=function(e,d){if(typeof e=="object"){e=d;list=repository_client.fp[e].fs.list}else{if(!d){list=repository_client.fp[e].fs.list}else{list=d}}var b=new YAHOO.util.Element("panel-"+e);var c=repository_client.fp[e];c.view_status=1;c.viewbar.check(1);repository_client.print_header(e);b.get("element").innerHTML+='<div id="treediv-'+e+'"></div>';var a=new YAHOO.widget.TreeView("treediv-"+e);a.dynload=function(j,f){var m={success:function(p){var n=repository_client.parse_json(p.responseText,"dynload");for(k in n.list){repository_client.buildtree(n.client_id,n.list[k],j)}p.argument.fnLoadComplete()},failure:function(n){alert(fp_lang.error+" - |dynload| -");n.argument.fnLoadComplete()},argument:{node:j,fnLoadComplete:f}};var g=repository_client.fp[j.client_id];var l=[];l.p=j.path;l.env=g.env;l.sesskey=moodle_cfg.sesskey;l.ctx_id=fp_config.contextid;l.repo_id=g.fs.repo_id;l.client_id=j.client_id;l.accepted_types=g.accepted_types;var h=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=list",m,repository_client.postdata(l))};a.dynload.client_id=e;if(c.fs.dynload){a.setDynamicLoad(a.dynload,1)}else{}for(k in list){repository_client.buildtree(e,list[k],a.getRoot())}a.draw();a.subscribe("clickEvent",function(f){if(f.node.isLeaf){repository_client.select_file(f.node.data.filename,f.node.data.value,f.node.data.icon,e,f.node.repo_id)}});repository_client.print_footer(e)};repository_client.buildtree=function(j,d,h){var a=repository_client.fp[j].fs;if(d.children){d.title="<i><u>"+d.title+"</u></i>"}var f={label:d.title,title:fp_lang.date+" "+d.date+fp_lang.size+" "+d.size,filename:d.title,value:d.source,icon:d.thumbnail,path:d.path};var b=new YAHOO.widget.TextNode(f,h,false);var e=new YAHOO.widget.Tooltip(b.labelElId,{context:b.labelElId,text:f.title});if(d.repo_id){b.repo_id=d.repo_id}else{b.repo_id=a.repo_id}if(d.children){if(d.expanded){b.expand()}b.isLeaf=false;b.client_id=j;if(d.path){b.path=d.path}else{b.path=""}for(var g in d.children){this.buildtree(j,d.children[g],b)}}else{b.isLeaf=true}};repository_client.select_file=function(h,c,g,d,m){var b=document.getElementById("fp-grid-panel-"+d);if(b){b.style.display="none"}var f=document.getElementById("fp-header-"+d);f.style.display="none";var j=document.getElementById("fp-footer-"+d);j.style.display="none";var l=document.getElementById("path-"+d);if(l){l.style.display="none"}var a=new YAHOO.util.Element("panel-"+d);var e='<div class="fp-rename-form">';e+='<p><img src="'+g+'" /></p>';e+='<p><label for="newname-'+d+'">'+fp_lang.saveas+"</label>";e+='<input type="text" id="newname-'+d+'" value="" /></p>';e+='<p><input type="hidden" id="fileurl-'+d+'" value="'+c+'" />';e+='<input type="button" onclick="repository_client.download(\''+d+"', '"+m+'\')" value="'+fp_lang.downbtn+'" />';e+='<input type="button" onclick="repository_client.viewfiles(\''+d+'\')" value="'+fp_lang.cancel+'" /></p>';e+="</div>";a.get("element").innerHTML+=e;document.getElementById("newname-"+d).value=h;var n=document.getElementById("treediv-"+d);if(n){n.style.display="none"}};repository_client.paging=function(d,a){var g="";this.fp[d].view_staus=0;var e=this.fp[d].fs;if(e.pages){g+='<div class="fp-paging" id="paging-'+a+'-"'+d+">";if(!e.search_result){var b="req"}else{var b="req_search_results"}g+=this.get_page_btn(d,b,1)+"1</a> ";var j=5;var f=(j-1)/2;if(e.page+f>=e.pages){var h=e.pages}else{if(e.page<j){var h=j}else{var h=e.page+f}}if(e.page>=j){g+=" ... ";for(var c=e.page-f;c<h;c++){g+=this.get_page_btn(d,b,c);g+=String(c);g+="</a> "}}else{for(var c=2;c<h;c++){g+=this.get_page_btn(d,b,c);g+=String(c);g+="</a> "}}if(h==e.pages){g+=this.get_page_btn(d,b,e.pages)+e.pages+"</a>"}else{g+=repository_client.get_page_btn(d,b,h)+h+"</a>";g+=" ... "+repository_client.get_page_btn(d,b,e.pages)+e.pages+"</a>"}g+="</div>"}return g};repository_client.get_page_btn=function(e,c,d){var a=this.fp[e].fs;var b="";if(d==a.page){b='class="cur_page"'}str="<a "+b+' onclick="repository_client.'+c+"('"+e+"',"+a.repo_id+", "+d+", "+d+')" href="###">';return str};repository_client.path=function(h){var a=this.fp[h].fs;if(this.fp[h].view_status==1){return}var b=new YAHOO.util.Element("panel-"+h);var g=a.path;if(g&&g.length!=0){var d=document.createElement("DIV");d.id="path-"+h;d.className="fp-pathbar";b.get("element").appendChild(d);for(var e=0;e<a.path.length;e++){var f=document.createElement("A");f.href="###";f.innerHTML=a.path[e].name;f.id="path-"+h+"-"+a.repo_id;f.path=a.path[e].path;f.onclick=function(){var m=new RegExp("path-(\\w+)-(\\d+)","i");var j=this.id.match(m);var n=j[1];var l=j[2];repository_client.req(n,l,this.path)};var c=document.createElement("SPAN");c.innerHTML="/";d.appendChild(f);d.appendChild(c)}}};repository_client.print_header=function(c){var a=new YAHOO.util.Element("panel-"+c);var b='<div id="fp-header-'+c+'">';b+='<div class="fp-toolbar" id="repo-tb-'+c+'"></div>';if(this.fp[c].fs.pages<8){b+=this.paging(c,"header")}b+="</div>";a.set("innerHTML",b);this.path(c)};repository_client.view_as_icons=function(j,l){var n=null;if(typeof j=="object"){j=l;n=repository_client.fp[j].fs.list}else{if(!l){n=repository_client.fp[j].fs.list}else{n=l}}var o=repository_client.fp[j];o.view_status=0;o.viewbar.check(0);var b=document.getElementById("panel-"+j);var a=document.createElement("DIV");a.id="fp-grid-panel-"+j;repository_client.print_header(j);var m=0;for(k in n){var e=document.createElement("div");e.className="fp-grid";var q=document.createElement("div");q.id="grid-title-"+String(m);q.className="label";if(n[k].shorttitle){n[k].title=n[k].shorttitle}q.innerHTML+='<a href="###"><span>'+n[k].title+"</span></a>";if(n[k].thumbnail_width){e.style.width=n[k].thumbnail_width+"px";q.style.width=(n[k].thumbnail_width-10)+"px"}else{e.style.width=q.style.width="80px"}var d=document.createElement("DIV");d.style.textAlign="center";if(n[k].thumbnail_height){d.style.height=n[k].thumbnail_height+"px"}var h=document.createElement("img");h.src=n[k].thumbnail;if(n[k].thumbnail_alt){h.alt=n[k].thumbnail_alt}if(n[k].thumbnail_title){h.title=n[k].thumbnail_title}var p=document.createElement("A");p.href="###";p.id="img-id-"+String(m);if(n[k].url){e.innerHTML+='<p><a target="_blank" href="'+n[k].url+'">'+fp_lang.preview+"</a></p>"}p.appendChild(h);d.appendChild(p);e.appendChild(d);e.appendChild(q);a.appendChild(e);if(n[k].children){var c=new YAHOO.util.Element(p.id);c.path=n[k].path;var g=new YAHOO.util.Element(q.id);c.fs=n[k].children;c.on("contentReady",function(){this.on("click",function(){if(o.fs.dynload){var r=repository_client.fp[j].fs;var t=[];t.p=this.path;t.env=repository_client.fp[j].env;t.repo_id=r.repo_id;t.ctx_id=fp_config.contextid;t.sesskey=moodle_cfg.sesskey;t.accepted_types=repository_client.fp[j].accepted_types;t.client_id=j;repository_client.loading(j,"load");var s=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=list",repository_client.req_cb,repository_client.postdata(t))}else{repository_client.view_as_icons(j,this.fs)}})});g.on("contentReady",function(){this.on("click",function(){c.fireEvent("click")})})}else{var g=new YAHOO.util.Element(q.id);var f=new YAHOO.util.Element(p.id);g.filename=f.filename=n[k].title;g.value=f.value=n[k].source;g.icon=f.icon=n[k].thumbnail;if(o.fs.repo_id){g.repo_id=f.repo_id=o.fs.repo_id}else{if(n[k].repo_id){g.repo_id=f.repo_id=n[k].repo_id}else{g.repo_id=f.repo_id=""}}f.on("contentReady",function(){this.on("click",function(){repository_client.select_file(this.filename,this.value,this.icon,j,this.repo_id)})});g.on("contentReady",function(){this.on("click",function(){repository_client.select_file(this.filename,this.value,this.icon,j,this.repo_id)})})}m++}b.appendChild(a);repository_client.print_footer(j)};repository_client.print_footer=function(d){var f=this.fp[d].fs;var a=document.getElementById("panel-"+d);var g=document.createElement("DIV");g.id="fp-footer-"+d;g.innerHTML+=this.create_upload_form(d);g.innerHTML+=this.paging(d,"footer");a.appendChild(g);var b=document.getElementById("repo-tb-"+d);if(this.fp[d].gsearch){this.fp[d].gsearch="";return}if(!f.nosearch){var l=document.createElement("A");l.href="###";l.innerHTML='<img src="'+moodle_cfg.pixpath+'/a/search.png" /> '+fp_lang.search;b.appendChild(l);l.onclick=function(){repository_client.search_form(d,f.repo_id)}}if(!f.norefresh){var e=document.createElement("A");e.href="###";e.innerHTML='<img src="'+moodle_cfg.pixpath+'/a/refresh.png" /> '+fp_lang.refresh;b.appendChild(e);e.onclick=function(){var n=[];n.env=f.env;n.sesskey=moodle_cfg.sesskey;n.ctx_id=fp_config.contextid;n.repo_id=f.repo_id;n.client_id=d;repository_client.loading(d,"load");var m=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=ccache",repository_client.req_cb,repository_client.postdata(n))}}if(f.manage){var h=document.createElement("A");h.innerHTML='<img src="'+moodle_cfg.pixpath+'/a/setting.png" /> '+fp_lang.mgr;h.href=f.manage;h.target="_blank";b.appendChild(h)}if(!f.nologin){var j=document.createElement("A");j.href="###";j.innerHTML='<img src="'+moodle_cfg.pixpath+'/a/logout.png" /> '+fp_lang.logout;b.appendChild(j);j.onclick=function(){repository_client.logout(d,f.repo_id)}}if(f.help){var c=document.createElement("A");c.href=f.help;c.target="_blank";c.innerHTML='<img src="'+moodle_cfg.pixpath+'/a/help.png" /> '+fp_lang.help;b.appendChild(c)}};repository_client.postdata=function(a){var b="";for(k in a){if(a[k] instanceof Array){for(i in a[k]){b+=(encodeURIComponent(k)+"[]="+encodeURIComponent(a[k][i]));b+="&"}}else{b+=encodeURIComponent(k)+"="+encodeURIComponent(a[k]);b+="&"}}return b};repository_client.stripHTML=function(c){var b=/<\S[^><]*>/g;var a=c.replace(b,"");return a};repository_client.popup=function(b,a){window.open(a,"repo_auth","location=0,status=0,scrollbars=0,width=500,height=300");cached_client_id=b;return true};function repository_callback(a){repository_client.req(cached_client_id,a,"")}repository_client.logout=function(d,b){var c=[];c.repo_id=b;c.client_id=d;var a=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=logout",repository_client.req_cb,repository_client.postdata(c))};repository_client.download=function(g,d){var a=repository_client.fp[g];var f=document.getElementById("newname-"+g).value;new_filename=f;var c=document.getElementById("fileurl-"+g).value;repository_client.loading(g,"download",f);var e=[];if(a.itemid){e.itemid=a.itemid}e.env=a.env;e.file=c;e.title=f;e.sesskey=moodle_cfg.sesskey;e.ctx_id=fp_config.contextid;e.repo_id=d;e.client_id=g;var b=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=download",repository_client.download_cb,repository_client.postdata(e))};repository_client.download_cb={success:function(c){var b=repository_client.parse_json(c.responseText,"download_cb");var a=new YAHOO.util.Element("panel-"+b.client_id);if(b&&b.e){a.get("element").innerHTML=b.e;return}repository_client.end(b.client_id,b)}};repository_client.end=function(c,b){var a=repository_client.fp[c];if(a.env=="filepicker"){a.target.value=b.id}else{if(a.env=="editor"){if(b.type=="link"){a.target.value=b.url+"#"+new_filename}else{a.target.value=b.url}a.target.onchange()}}a.formcallback(b);a.hide();repository_client.viewfiles(c)};repository_client.viewfiles=function(b){var a=repository_client.fp[b];if(a.view_status){repository_client.view_as_list(b)}else{repository_client.view_as_icons(b)}};repository_client.create_upload_form=function(d){var b="";var a=repository_client.fp[d].fs;if(a.upload){var c=a.upload.id+"_"+d;b+='<div id="'+c+'_div" class="fp-upload-form">';b+='<form id="'+c+'" onsubmit="return false">';b+='<label for="'+c+'_file">'+a.upload.label+": </label>";b+='<input type="file" id="'+c+'_file" name="repo_upload_file" />';b+='<p class="fp-upload-btn"><a href="###" onclick="return repository_client.upload(\''+d+"');\">"+fp_lang.upload+"</a></p>";b+="</form>";b+="</div>"}return b};repository_client.upload=function(e){var g=repository_client.fp[e];var l=repository_client.fp[e].fs;var b=l.upload.id+"_"+e;var h=document.getElementById(b);var j=document.getElementById(b+"_div");var f=document.getElementById(b+"_file");if(f.value!=""&&f.value!=null){var a=document.createElement("DIV");a.id=b+"_loading";a.style.textAlign="center";var c=document.createElement("IMG");c.src=moodle_cfg.pixpath+"/i/progressbar.gif";var n=document.createElement("p");n.innerHTML=fp_lang.uploading;a.appendChild(n);a.appendChild(c);j.appendChild(a);YAHOO.util.Connect.setForm(h,true,true);var m=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=upload&itemid="+g.itemid+"&sesskey="+moodle_cfg.sesskey+"&ctx_id="+fp_config.contextid+"&repo_id="+l.repo_id+"&client_id="+e,repository_client.upload_cb)}else{alert(fp_lang.filenotnull)}};repository_client.upload_cb={upload:function(c){var b=repository_client.parse_json(c.responseText,"upload");client_id=b.client_id;if(b&&b.e){var a=new YAHOO.util.Element("panel-"+client_id);a.get("element").innerHTML=b.e;return}if(b){alert(fp_lang.saved);repository_client.end(client_id,b)}}};repository_client.parse_json=function(a,c){try{var b=YAHOO.lang.JSON.parse(a)}catch(d){alert(fp_lang.invalidjson+" - |"+c+"| -"+this.stripHTML(a))}return b};repository_client.search_form=function(e,d){var a=repository_client.fp[e];var c=[];c.env=a.env;c.sesskey=moodle_cfg.sesskey;c.client_id=e;c.ctx_id=fp_config.contextid;c.repo_id=d;var b=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=searchform",repository_client.search_form_cb,repository_client.postdata(c))};repository_client.search_form_cb={success:function(b){var d=repository_client.parse_json(b.responseText,"search_form_cb");var c=document.getElementById("fp-search-dlg");var g=repository_client.fp[d.client_id];if(c){c.innerHTML=""}else{var c=document.createElement("DIV");c.id="fp-search-dlg"}var f=document.createElement("DIV");f.className="hd";f.innerHTML=fp_lang.searching+'"'+repository_listing[d.client_id][g.fs.repo_id].name+'"';var e=document.createElement("DIV");e.className="bd";var a=document.createElement("FORM");a.method="POST";a.id="fp-search-form";a.action=moodle_cfg.wwwroot+"/repository/ws.php?action=search";a.innerHTML=d.form;e.appendChild(a);c.appendChild(f);c.appendChild(e);document.body.appendChild(c);var j=function(){var n=j.client_id;repository_client.fp[n].viewbar.set("disabled",false);repository_client.loading(n,"load");YAHOO.util.Connect.setForm("fp-search-form",false,false);this.cancel();var l=moodle_cfg.wwwroot+"/repository/ws.php?action=search&env="+j.env+"&client_id="+n;var m=YAHOO.util.Connect.asyncRequest("POST",l,repository_client.req_cb)};j.client_id=d.client_id;j.env=g.env;var h=new YAHOO.widget.Dialog("fp-search-dlg",{postmethod:"async",draggable:true,width:"30em",fixedcenter:true,zindex:766667,visible:false,constraintoviewport:true,buttons:[{text:fp_lang.submit,handler:j,isDefault:true},{text:fp_lang.cancel,handler:function(){this.cancel()}}]});h.render();h.show()}};var mdl_in_array=function(d,a){for(var c=0,b=a.length;c<b;c++){if(a[c]==d){return true}}return false};function open_filepicker(c,b){var a=repository_client.fp[c];if(!a){a=new repository_client();a.env=b.env;a.target=b.target;if(b.itemid){a.itemid=b.itemid}else{if(tinyMCE&&id2itemid[tinyMCE.selectedInstance.editorId]){a.itemid=id2itemid[tinyMCE.selectedInstance.editorId]}}if(b.callback){a.formcallback=b.callback}else{a.formcallback=function(){}}repository_client.fp[c]=a;a.create_filepicker(c)}else{a.target=b.target;a.show()}if(b.filetype){if(b.filetype=="image"){a.accepted_types=file_extensions.image}else{if(b.filetype=="video"||b.filetype=="media"){a.accepted_types=file_extensions.media}else{if(b.filetype=="file"){a.accepted_types="*"}}}}else{a.accepted_types="*"}return a}; |