MDL-27919 Fixes 'undefined' message and similar problems when selecting a
authorJamie Pratt <me@jamiep.org>
Sun, 18 Sep 2011 06:22:35 +0000 (13:22 +0700)
committerJamie Pratt <me@jamiep.org>
Sun, 18 Sep 2011 06:22:35 +0000 (13:22 +0700)
recent file, server file or when renaming a file being uploaded with the same
name as a previous one.

repository/filepicker.js
repository/repository_ajax.php

index a5cfc3d..cf18f7f 100644 (file)
@@ -222,14 +222,16 @@ M.core_filepicker.init = function(Y, options) {
                 }
                 this.cancel();
                 scope.hide();
-                data.client_id = client_id;
                 var formcallback_scope = null;
                 if (scope.options.magicscope) {
                     formcallback_scope = scope.options.magicscope;
                 } else {
                     formcallback_scope = scope;
                 }
-                scope.options.formcallback.apply(formcallback_scope, [data]);
+                var fileinfo = {'client_id':client_id,
+                                'url':data.newfile.url,
+                                'file':data.newfile.filename};
+                scope.options.formcallback.apply(formcallback_scope, [fileinfo]);
             }
             var handleCancel = function() {
                 // Delete tmp file
index a954ee6..6dc6247 100644 (file)
@@ -195,7 +195,7 @@ switch ($action) {
             // use external link
             $link = $repo->get_link($source);
             $info = array();
-            $info['filename'] = $saveas_filename;
+            $info['file'] = $saveas_filename;
             $info['type'] = 'link';
             $info['url'] = $link;
             echo json_encode($info);
@@ -206,6 +206,9 @@ switch ($action) {
             // (local, user, coursefiles, recent)
             if ($repo->has_moodle_files()) {
                 $fileinfo = $repo->copy_to_area($source, $itemid, $saveas_path, $saveas_filename);
+                if (!isset($fileinfo['event'])) {
+                    $fileinfo['file'] = $fileinfo['title'];
+                }
                 echo json_encode($fileinfo);
                 die;
             }
@@ -261,7 +264,8 @@ switch ($action) {
         $newfilepath = required_param('newfilepath', PARAM_PATH);
         $newfilename = required_param('newfilename', PARAM_FILE);
 
-        echo json_encode(repository::overwrite_existing_draftfile($itemid, $filepath, $filename, $newfilepath, $newfilename));
+        $info = repository::overwrite_existing_draftfile($itemid, $filepath, $filename, $newfilepath, $newfilename);
+        echo json_encode($info);
         break;
 
     case 'deletetmpfile':