MDL-22982, fixed file browser renderer component
authorDongsheng Cai <unoter@gmail.com>
Wed, 7 Jul 2010 08:18:41 +0000 (08:18 +0000)
committerDongsheng Cai <unoter@gmail.com>
Wed, 7 Jul 2010 08:18:41 +0000 (08:18 +0000)
files/filebrowser_ajax.php
files/module.js

index 8e82d8b..659568c 100755 (executable)
@@ -34,7 +34,6 @@ $action = optional_param('action', 'list', PARAM_ALPHA);
 require_login();
 
 $err = new stdclass;
-
 if (isguestuser()) {
     $err->error = get_string('noguest');
     die(json_encode($err));
@@ -43,7 +42,6 @@ if (isguestuser()) {
 switch ($action) {
     // used by course file tree viewer
     case 'getfiletree':
-
         $contextid  = required_param('contextid', PARAM_INT);
         $component  = required_param('component', PARAM_ALPHAEXT);
         $filearea   = required_param('filearea', PARAM_ALPHAEXT);
@@ -51,13 +49,6 @@ switch ($action) {
         $filepath   = required_param('filepath', PARAM_PATH);
 
         $browser = get_file_browser();
-        $params = $url->params();
-        // fix empty value
-        foreach ($params as $key=>$value) {
-            if ($value==='') {
-                $params[$key] = null;
-            }
-        }
         $fileinfo = $browser->get_file_info(get_context_instance_by_id($contextid), $component, $filearea, $itemid, $filepath);
         $children = $fileinfo->get_children();
         $tree = array();
@@ -75,14 +66,13 @@ switch ($action) {
                     );
             if ($child->is_directory()) {
                 $fileitem['isdir'] = true;
-                $fileitem['url'] = $url->out();
+                $fileitem['url'] = $url->out(false);
             } else {
                 $fileitem['url'] = $child->get_url();
             }
             $tree[] = $fileitem;
         }
         echo json_encode($tree);
-
         break;
 
     default:
index 2665405..6338053 100644 (file)
@@ -6,7 +6,12 @@ M.core_filetree = {
     request: function(url, node, cb) {
         var api = this.api + '?action=getfiletree';
         var params = [];
-        params['fileurl'] = url;
+        params['contextid'] = this.get_param(url, 'contextid', -1);
+        params['component'] = this.get_param(url, 'component', null);
+        params['filearea'] = this.get_param(url, 'filearea', null);
+        params['itemid'] = this.get_param(url, 'itemid', -1);
+        params['filepath'] = this.get_param(url, 'filepath', null);
+        params['filename'] = this.get_param(url, 'filename', null);
         var scope = this;
         params['sesskey']=M.cfg.sesskey;
         var cfg = {
@@ -50,7 +55,7 @@ M.core_filetree = {
         };
         this.y3.io(api, cfg);
     },
-    init : function(Y, options){
+    init : function(Y){
         var tree = new YAHOO.widget.TreeView('course-file-tree-view');
         tree.setDynamicLoad(this.dynload);
         tree.subscribe("clickEvent", this.onclick);
@@ -71,5 +76,16 @@ M.core_filetree = {
     },
     onclick: function(e) {
         YAHOO.util.Event.preventDefault(e); 
+    },
+    get_param: function(url, name, val) {
+        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
+        var regexS = "[\\?&]"+name+"=([^&#]*)";
+        var regex = new RegExp( regexS );
+        var results = regex.exec(url);
+        if( results == null ) {
+            return val;
+        } else {
+            return unescape(results[1]);
+        }
     }
 }