2 // Author: Dongsheng Cai <dongsheng@moodle.com>
5 api: M.cfg.wwwroot+'/files/filebrowser_ajax.php',
6 request: function(url, node, cb) {
7 var api = this.api + '?action=getfiletree';
9 params['contextid'] = this.get_param(url, 'contextid', -1);
10 params['component'] = this.get_param(url, 'component', null);
11 params['filearea'] = this.get_param(url, 'filearea', null);
12 params['itemid'] = this.get_param(url, 'itemid', -1);
13 params['filepath'] = this.get_param(url, 'filepath', null);
14 params['filename'] = this.get_param(url, 'filename', null);
16 params['sesskey']=M.cfg.sesskey;
20 complete: function(id,o,p) {
22 var data = this.y3.JSON.parse(o.responseText);
27 if (data && data.length==0) {
31 var tmp = new YAHOO.widget.HTMLNode('<div>'+data[i].icon+' <a href="'+data[i].url+'">'+data[i].filename+'</a></div>', node, false);
48 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
50 data: build_querystring(params),
56 var tree = new YAHOO.widget.TreeView('course-file-tree-view');
57 tree.setDynamicLoad(this.dynload);
58 tree.subscribe("clickEvent", this.onclick);
59 var root = tree.getRoot();
60 var children = root.children;
62 if (children[i].className == 'file-tree-folder') {
63 children[i].isLeaf = false;
64 children[i].isDir = true;
66 children[i].isLeaf = true;
67 children[i].isFile = true;
73 dynload: function(node, oncompletecb) {
74 var tmp = document.createElement('p');
75 tmp.innerHTML = node.html;
76 var links = tmp.getElementsByTagName('a');
77 var link = links[0].href;
78 M.core_filetree.request(link, node, oncompletecb);
80 onclick: function(e) {
81 YAHOO.util.Event.preventDefault(e);
83 var tmp = document.createElement('p');
84 tmp.innerHTML = e.node.html;
85 var links = tmp.getElementsByTagName('a');
86 var link = links[0].href;
87 window.location = link;
90 get_param: function(url, name, val) {
91 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
92 var regexS = "[\\?&]"+name+"=([^&#]*)";
93 var regex = new RegExp( regexS );
94 var results = regex.exec(url);
95 if( results == null ) {
98 return unescape(results[1]);