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;
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'];
}
}
}
<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>
_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 = {};
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,
_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?");
}
_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;
})();
}
$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 {
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;
$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;