MDL-22805, remove debug code
[moodle.git] / files / module.js
1 // File Tree Viewer
2 // Author: Dongsheng Cai <dongsheng@moodle.com>
3 M.core_filetree = {
4     y3: null,
5     api: M.cfg.wwwroot+'/files/files_ajax.php',
6     request: function(url, node, cb) {
7         var api = this.api + '?action=getfiletree';
8         var params = [];
9         params['fileurl'] = url;
10         var scope = this;
11         params['sesskey']=M.cfg.sesskey;
12         var cfg = {
13             method: 'POST',
14             on: {
15                 complete: function(id,o,p) {
16                     try {
17                         var data = this.y3.JSON.parse(o.responseText);
18                     } catch(e) {
19                         alert(e.toString());
20                         return;
21                     }
22                     if (data && data.length==0) {
23                         node.isLeaf = true;
24                     } else {
25                         for (i in data) {
26                             var mynode = {
27                                 label: data[i].filename,
28                                 href: data[i].url
29                             };
30                             var tmp = new YAHOO.widget.TextNode(mynode, node, false);
31                             if (data[i].isdir) {
32                                 tmp.isLeaf = false;
33                             } else {
34                                 tmp.isLeaf = true;
35                                 tmp.target = '_blank';
36                             }
37                         }
38                     }
39                     cb();
40                 }
41             },
42             arguments: {
43                 scope: scope
44             },
45             headers: {
46                 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
47             },
48             data: build_querystring(params),
49             context: this
50         };
51         this.y3.io(api, cfg);
52     },
53     init : function(Y, options){
54         var tree = new YAHOO.widget.TreeView('course-file-tree-view');
55         tree.setDynamicLoad(this.dynload);
56         tree.subscribe("clickEvent", this.onclick);
57         var root = tree.getRoot();
58         var children = root.children;
59         for (i in children) {
60             if (children[i].className == 'file-tree-folder') {
61                 children[i].isLeaf = false;
62             } else {
63                 children[i].isLeaf = true;
64             }
65         }
66         tree.render();
67         this.y3 = Y;
68     }, 
69     dynload: function(node, oncompletecb) {
70         M.core_filetree.request(node.href, node, oncompletecb);
71     },
72     onclick: function(e) {
73         YAHOO.util.Event.preventDefault(e); 
74     }
75 }