Merge branch 'MDL-27919' of git://github.com/jamiepratt/moodle
authorSam Hemelryk <sam@moodle.com>
Mon, 31 Oct 2011 04:18:13 +0000 (17:18 +1300)
committerSam Hemelryk <sam@moodle.com>
Mon, 31 Oct 2011 04:18:13 +0000 (17:18 +1300)
repository/filepicker.js
repository/repository_ajax.php

index a5cfc3d..82f60b7 100644 (file)
@@ -211,6 +211,11 @@ M.core_filepicker.init = function(Y, options) {
                         if (scope.options.editor_target && scope.options.env == 'editor') {
                             scope.options.editor_target.value = data.existingfile.url;
                             scope.options.editor_target.onchange();
+                        } else if (scope.options.env === 'filepicker') {
+                            var fileinfo = {'client_id':client_id,
+                                    'url':data.existingfile.url,
+                                    'file':data.existingfile.filename};
+                            scope.options.formcallback.apply(scope, [fileinfo]);
                         }
                     }
                 }, true);
@@ -222,14 +227,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 82d8591..ccf55cd 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);
@@ -215,6 +215,9 @@ switch ($action) {
                     throw new file_exception('maxbytes');
                 }
                 $fileinfo = $repo->copy_to_area($source, $itemid, $saveas_path, $saveas_filename);
+                if (!isset($fileinfo['event'])) {
+                    $fileinfo['file'] = $fileinfo['title'];
+                }
                 echo json_encode($fileinfo);
                 die;
             }
@@ -270,7 +273,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':