]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13766, tell server side where file picker opened.
authordongsheng <dongsheng>
Fri, 1 Aug 2008 04:10:31 +0000 (04:10 +0000)
committerdongsheng <dongsheng>
Fri, 1 Aug 2008 04:10:31 +0000 (04:10 +0000)
lib/editor/tinymce.js.php
lib/form/filepicker.php
repository/ajax.php
repository/lib.php
repository/ws.php

index 003ffbdf1ac1c01014d214fe574a77ac634a082b..4e17b7ef2a997122b5dec418023bf7bf2cabdba7 100644 (file)
@@ -207,7 +207,7 @@ echo <<<EOF
         tinyMCE.execCommand('mceToggleEditor',false,id);
     }
     function mce_moodlefilemanager(field_name, url, type, win) {
-         openpicker();
+         openpicker({'env':'editor'});
     }
     function mce_saveOnSubmit(id) {
         var prevOnSubmit = document.getElementById(id).form.onsubmit;
index 249dc19c58ebd53f791e82bcd54388a1e49af4a3..376515444cff56a3016b4fb69382c5eac88bfeca 100644 (file)
@@ -45,7 +45,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_button
             return $this->getFrozenHtml();
         } else {
             $ret = get_repository_client();
-            return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' onclick=\'openpicker()\' />'.$ret['html'].$ret['js'];
+            return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' onclick=\'openpicker({"env":"form"})\' />'.$ret['html'].$ret['js'];
         }
     }
 }
index bc433bb02443992d1f219ede58305a72975986ae..2e1eb752d5d4c3bc43393b95f2900ed7183d67ad 100644 (file)
@@ -41,7 +41,7 @@ $ret = get_repository_client();
 <body class=" yui-skin-sam">
 <div id='control'>
     <h1>Open the picker</h1>
-    <input type="button" id="con1" onclick='openpicker()' value="Open File Picker" style="font-size: 24px;padding: 1em" /> <br/>
+    <input type="button" id="con1" onclick='openpicker({"env":"form"})' value="Open File Picker" style="font-size: 24px;padding: 1em" /> <br/>
     <input type='hidden' id="result">
 </div>
 <div>
index 64ee0b3bd794292f26b577f5cf9023207c099030..33e19ac724c44e3043ab8ba5e8a17e6502ee303b 100644 (file)
@@ -639,7 +639,7 @@ function get_repository_client(){
             _client.loading();
             var trans = YAHOO.util.Connect.asyncRequest('POST', 
                 '$CFG->wwwroot/repository/ws.php?id='+_client.repositoryid+'&action=download', 
-                _client.dlfile, _client.postdata({'file':file, 'title':title}));
+                _client.dlfile, _client.postdata({'env':_client.env, 'file':file, 'title':title}));
         }
         _client.login = function(){
             var obj = {};
@@ -653,6 +653,7 @@ function get_repository_client(){
                     obj[data[k].name] = el.value;
                 }
             }
+            obj['env'] = _client.env;
             _client.loading();
             var trans = YAHOO.util.Connect.asyncRequest('POST', 
                 '$CFG->wwwroot/repository/ws.php', _client.callback,
@@ -704,7 +705,7 @@ function get_repository_client(){
             _client.viewbar.set('disabled', false);
             _client.loading();
             _client.repositoryid = id;
-            var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?id='+id+'&p='+path+'&reset='+reset, _client.callback);
+            var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?id='+id+'&p='+path+'&reset='+reset+'&env='+_client.env, _client.callback);
         }
         _client.search = function(id){
             var data = window.prompt("What are you searching for?");
@@ -714,7 +715,7 @@ function get_repository_client(){
             }
             _client.viewbar.set('disabled', false);
             _client.loading();
-            var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?id='+id+'&s='+data, _client.callback);
+            var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?id='+id+'&s='+data+'&env='+_client.env, _client.callback);
         }
         return _client;
     })();
@@ -727,8 +728,9 @@ EOD;
     }
 
     $js .= <<<EOD
-    function openpicker() {
+    function openpicker(obj) {
         if(!repository_client.instance) {
+            repository_client.env = obj.env;
             repository_client.instance = new repository_client();
             repository_client.instance.create_picker();
         } else {
index 4baa8fb99069a0ce9c27f99942f15e3add5c924d..3513910032fa5addbb969fe2a460e9b7591fddc5 100644 (file)
@@ -5,16 +5,18 @@ require_once('../lib/filelib.php');
 require_once('lib.php');
 // set one hour here
 $CFG->repository_cache_expire = 60*60;
-// repository id
+// page
+$p     = optional_param('p', '', PARAM_RAW);
+// id of repository
 $id     = optional_param('id', 1, PARAM_INT);
-// action of client
-$action = optional_param('action', '', PARAM_RAW);
-// Search text
-$search = optional_param('s', '', PARAM_RAW);
-// files to be downloaded
+// opened in editor or moodleform
+$env   = optional_param('env', 'form', PARAM_RAW);
+// file to download
 $file  = optional_param('file', '', PARAM_RAW);
+// rename the file name
 $title = optional_param('title', '', PARAM_RAW);
-$p     = optional_param('p', '', PARAM_RAW);
+$action = optional_param('action', '', PARAM_RAW);
+$search = optional_param('s', '', PARAM_RAW);
 
 if(!$repository = $DB->get_record('repository', array('id'=>$id))) {
     $err = new stdclass;
@@ -74,8 +76,14 @@ if($action == 'list') {
         $entry->userid       = $USER->id;
         $fs = get_file_storage();
         if ($file = $fs->create_file_from_pathname($entry, $pathname)) {
-            //echo json_encode($file->get_content_file_location());
-            echo json_encode($file->get_itemid());
+            if($env == 'form'){
+                // return reference id
+                echo json_encode($file->get_itemid());
+            } elseif($env == 'editor') {
+                // return url
+                // echo json_encode($file->get_content_file_location());
+            } else {
+            }
         }
     } catch (repository_exception $e){
         $err = new stdclass;