mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
1 line
28 KiB
JavaScript
1 line
28 KiB
JavaScript
var id2clientid={};var id2itemid={};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,monitorresize:false,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()})});if(!YAHOO.env.ua.ie){var g=new YAHOO.util.Resize("file-picker-"+o,{handles:["br"],autoRatio:true,proxy:true,status:true,minWidth:680,minHeight:400});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.type=="draft"&&this.env=="filemanager"){continue}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;e.itemid=repository_client.fp[g].itemid;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='<div class="fp-error">'+c.e+"</div>";return}b.fs=c;if(!c){return}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)}}}}}if(c.msg){repository_client.print_msg(c.msg,c.client_id)}}};repository_client.print_msg=function(b,c){var a=new YAHOO.util.Element("panel-"+c);a.get("element").innerHTML='<div class="fp-msg">'+b+"</div>"+a.get("element").innerHTML};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,j){var p=j.login;var a=new YAHOO.util.Element("panel-"+b);var g="login";if(j.login_btn_action){g=j.login_btn_action}var o='<div class="fp-login-form" onkeypress="repository_client.login_keypress(event,\''+g+"')\">";var f=false;this.fp[b].login=p;o+='<table width="100%">';for(var h in p){o+="<tr>";if(p[h].type=="popup"){o+='<td colspan="2"><p class="fp-popup">'+fp_lang.popup+"</p>";o+='<p class="fp-popup"><button onclick="repository_client.popup(\''+b+"', '"+p[h].url+"')\">"+fp_lang.login+"</button>";o+="</p></td>";f=true}else{if(p[h].type=="textarea"){o+='<td colspan="2"><p><textarea id="'+p[h].id+'" name="'+p[h].name+'"></textarea></p></td>'}else{if(p[h].type=="select"){o+='<td align="right"><label>'+p[h].label+':</label></td><td align="left"><select id="'+p[h].id+'" name="'+p[h].name+'">';for(i in p[h].options){o+='<option value="'+p[h].options[i].value+'">'+p[h].options[i].label+"</option>"}o+="</select></td>"}else{var d="";var q="";var s="";if(p[h].id){d=' for="'+p[h].id+'"';q=' id="'+p[h].id+'"'}if(p[h].label){o+='<td align="right" valign="top"><label'+d+">"+p[h].label+"</label> </td>"}else{o+="<td></td>"}if(p[h].value){s=' value="'+p[h].value+'"'}if(p[h].type=="radio"){var n=p[h].value.split("|");var l=p[h].value_label.split("|");o+='<td align="left">';for(var r in n){o+='<input type="'+p[h].type+'" name="'+p[h].name+'"'+q+' value="'+n[r]+'" />'+l[r]+"<br />"}o+="</td>"}else{o+='<td align="left"><input type="'+p[h].type+'" name="'+p[h].name+'"'+s+" "+q+" /></td>"}}}}o+="</tr>"}o+="</table>";var c=j.login_btn_label?j.login_btn_label:fp_lang.submit;if(j.login_btn_action=="search"){o+='<p><input type="button" onclick="repository_client.search(\''+b+"', '"+j.repo_id+'\')" value="'+c+'" /></p>'}else{if(j.login_btn_action=="download"){o+='<p><input type="button" onclick="repository_client.download(\''+b+"', '"+j.repo_id+'\')" value="'+c+'" /></p>'}else{if(!f){o+='<p><input type="button" onclick="repository_client.login(\''+b+"', '"+j.repo_id+'\')" value="'+c+'" /></p>'}}}o+="</div>";try{a.get("element").innerHTML=o}catch(m){alert(m.toString()+fp_lang.xhtml)}cached_id=b;cached_repo_id=j.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{if(c=="download"){repository_client.download(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,c,b){var a=new YAHOO.util.Element("panel-"+g);a.get("element").innerHTML="";var f='<div style="text-align:center">';if(c=="load"){f+='<img src="'+fp_config.icons.loading+'" />';f+="<p>"+fp_lang.loading+"</p>"}else{f+='<img src="'+fp_config.icons.progressbar+'" />';f+="<p>"+fp_lang.copying+" <strong>"+b+"</strong></p>"}f+="</div>";try{a.get("element").innerHTML=f}catch(d){alert(d.toString())}};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){if(repository_client.files[d]==undefined){repository_client.files[d]=0}if(repository_client.files[d]>=repository_client.fp[d].maxfiles&&repository_client.fp[d].maxfiles!=-1){alert("Only "+repository_client.fp[d].maxfiles+" files are allowed!");return false}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);if(o.fs.draftfiles&&!n[k].children){var r=document.createElement("A");r.href="###";r.innerHTML="[X]";r.id="del-id-"+String(m);e.appendChild(r);r.itemid=o.itemid;r.client_id=j;r.title=n[k].title;r.repo_id=o.fs.repo_id;r.onclick=function(){if(confirm("Sure?")){var t=[];t.client_id=this.client_id;t.itemid=this.itemid;t.title=this.title;var s=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=delete",this,repository_client.postdata(t))}};r.success=function(s){repository_client.req(s.responseText,this.repo_id)}}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 s=repository_client.fp[j].fs;var u=[];u.p=this.path;u.env=repository_client.fp[j].env;u.repo_id=s.repo_id;u.ctx_id=fp_config.contextid;u.sesskey=moodle_cfg.sesskey;u.accepted_types=repository_client.fp[j].accepted_types;u.client_id=j;repository_client.loading(j,"load");var t=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=list",repository_client.req_cb,repository_client.postdata(u))}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++}if(n.length==0&&!o.fs.upload){a.innerHTML='<div class="fp-error">'+fp_lang.emptylist+"</div>"}b.appendChild(a);repository_client.print_footer(j)};repository_client.print_footer=function(d){var g=this.fp[d].fs;var a=document.getElementById("panel-"+d);var h=document.createElement("DIV");h.id="fp-footer-"+d;h.innerHTML+=this.create_upload_form(d);h.innerHTML+=this.paging(d,"footer");a.appendChild(h);var b=document.getElementById("repo-tb-"+d);if(this.fp[d].gsearch){this.fp[d].gsearch="";return}if(!g.nosearch){var f=document.createElement("img");f.src=fp_config.icons.search;var m=document.createElement("A");m.href="###";m.appendChild(document.createTextNode(fp_lang.search));b.appendChild(f);b.appendChild(m);m.onclick=function(){repository_client.search_form(d,g.repo_id)}}if(!g.norefresh){var f=document.createElement("img");f.src=fp_config.icons.refresh;var e=document.createElement("A");e.href="###";e.appendChild(document.createTextNode(fp_lang.refresh));b.appendChild(f);b.appendChild(e);e.onclick=function(){var o=[];o.env=g.env;o.sesskey=moodle_cfg.sesskey;o.ctx_id=fp_config.contextid;o.repo_id=g.repo_id;o.client_id=d;repository_client.loading(d,"load");var n=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=ccache",repository_client.req_cb,repository_client.postdata(o))}}if(g.manage){var j=document.createElement("A");j.innerHTML='<img src="'+fp_config.icons.setting+'" /> '+fp_lang.mgr;j.href=g.manage;j.target="_blank";b.appendChild(j)}if(!g.nologin){var l=document.createElement("A");l.href="###";l.innerHTML='<img src="'+fp_config.icons.logout+'" /> '+fp_lang.logout;b.appendChild(l);l.onclick=function(){repository_client.logout(d,g.repo_id)}}if(g.help){var c=document.createElement("A");c.href=g.help;c.target="_blank";c.innerHTML='<img src="'+fp_config.icons.help+'" /> '+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.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.savepath=a.savepath;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}if(repository_client.files[b.client_id]==undefined){repository_client.files[b.client_id]=0}else{repository_client.files[b.client_id]++}repository_client.end(b.client_id,b)}};repository_client.end=function(c,b){var a=repository_client.fp[c];if(repository_client.files[c]==undefined){repository_client.files[c]=0}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()}}b.filepath=a.savepath;b.maxfileslimit=(a.maxfiles!=-1&&repository_client.files[c]>=a.maxfiles);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+='<div class="fp-upload-btn"><a href="###" onclick="return repository_client.upload(\''+d+"');\">"+fp_lang.upload+"</a></div>";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=fp_config.icons.progressbar;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+"&savepath="+g.savepath+"&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){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+"| -"+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 f=repository_client.fp[d.client_id];if(c){c.innerHTML="";c.parentNode.removeChild(c)}var c=document.createElement("DIV");c.id="fp-search-dlg";var h=document.createElement("DIV");h.className="hd";h.innerHTML=fp_lang.searching+'"'+repository_listing[d.client_id][f.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(h);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=f.env;var g=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.destroy()}}]});g.render();g.show()}};repository_client.files={};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()}a.savepath=b.savepath;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="*"}if(!b.maxfiles){b.maxfiles=-1}a.maxfiles=b.maxfiles;return a}function id2_add_clientid(b,a){id2clientid[b]=a}function id2_add_itemid(b,a){id2itemid[b]=a}; |