mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
"MDL-21170, rename filepicker to core_filepicker, upgrade filemanager to yui3 module"
This commit is contained in:
parent
3e6161fb1c
commit
840912d5cf
@ -77,9 +77,9 @@ case 'delete':
|
||||
$fs = get_file_storage();
|
||||
$filepath = file_correct_filepath($filepath);
|
||||
$return = new stdclass;
|
||||
if ($file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, $filename)) {
|
||||
$parent_path = $file->get_parent_directory()->get_filepath();
|
||||
if($result = $file->delete()) {
|
||||
if ($stored_file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, $filename)) {
|
||||
$parent_path = $stored_file->get_parent_directory()->get_filepath();
|
||||
if($result = $stored_file->delete()) {
|
||||
$return->filepath = $parent_path;
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
@ -93,11 +93,11 @@ case 'delete':
|
||||
case 'renamedir':
|
||||
$fs = get_file_storage();
|
||||
$fb = get_file_browser();
|
||||
$file = $fb->get_file_info($user_context, 'user_draft', $itemid, $filepath, '.');
|
||||
if ($result = $file->delete()) {
|
||||
$fs->create_directory($user_context->id, 'user_draft', $itemid, file_correct_filepath($newfilename));
|
||||
$return = new stdclass;
|
||||
$return->filepath = file_correct_filepath($newfilename);
|
||||
$return = new stdclass;
|
||||
$fileinfo = $fb->get_file_info($user_context, 'user_draft', $itemid, $filepath, '.');
|
||||
if ($result = $fileinfo->delete()) {
|
||||
$newdir = $fs->create_directory($user_context->id, 'user_draft', $itemid, file_correct_filepath($newfilename));
|
||||
$return->filepath = $newdir->get_parent_directory()->get_filepath();
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
echo json_encode(false);
|
||||
@ -192,6 +192,9 @@ case 'unzip':
|
||||
}
|
||||
break;
|
||||
|
||||
case 'upload':
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -343,11 +343,14 @@ class page_requirements_manager {
|
||||
|
||||
if (strpos($name, 'core_') === 0) {
|
||||
// must be some core stuff
|
||||
} else {
|
||||
if ($name === 'filepicker') { // TODO: rename to 'core_filepicker' and move above
|
||||
if ($name === 'core_filepicker') {
|
||||
$pathtofilepicker = $CFG->httpswwwroot.'/repository/filepicker.js';
|
||||
$module = array('fullpath'=>$pathtofilepicker, 'requires' => array('base', 'node', 'json', 'async-queue', 'io', 'yui2-button', 'yui2-container', 'yui2-treeview', 'yui2-layout'));
|
||||
$module = array('fullpath'=>$pathtofilepicker, 'requires' => array('base', 'node', 'json', 'async-queue', 'io'));
|
||||
} else if($name === 'core_filemanager') {
|
||||
$pathtofilemanager = $CFG->httpswwwroot.'/lib/form/filemanager.js';
|
||||
$module = array('fullpath'=>$pathtofilemanager, 'requires' => array('base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'));
|
||||
}
|
||||
} else {
|
||||
//TODO: look for plugin info?
|
||||
}
|
||||
|
||||
|
@ -55,14 +55,14 @@ function editor_init_filepicker(editorid, options) {
|
||||
editor_options[editorid] = options;
|
||||
}
|
||||
function mce_moodlefilemanager(target_id, url, type, win) {
|
||||
YUI(M.yui.loader).use("filepicker", function (Y) {
|
||||
YUI(M.yui.loader).use('core_filepicker', function (Y) {
|
||||
var editor_id = tinyMCE.selectedInstance.editorId;
|
||||
var options = editor_options[editor_id];
|
||||
var client_id = options.client_id;
|
||||
options.formcallback = editor_filepicker_callback;
|
||||
options.editor_target = win.document.getElementById(target_id);
|
||||
if (!editor_filepickers[client_id]) {
|
||||
editor_filepickers[client_id] = new Y.filepicker(options);
|
||||
editor_filepickers[client_id] = new Y.core_filepicker(options);
|
||||
}
|
||||
editor_filepickers[client_id].show();
|
||||
});
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -31,7 +31,7 @@ require_once("$CFG->dirroot/repository/lib.php");
|
||||
|
||||
class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
public $_helpbutton = '';
|
||||
protected $_options = array('mainfile'=>'', 'subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||
protected $_options = array('mainfile'=>'', 'subdirs'=>1, 'maxbytes'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||
|
||||
function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
|
||||
global $CFG, $PAGE;
|
||||
@ -46,7 +46,8 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
|
||||
}
|
||||
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$PAGE->requires->js('/lib/form/filemanager.js');
|
||||
$PAGE->requires->js_module('core_filepicker');
|
||||
$PAGE->requires->js_module('core_filemanager');
|
||||
}
|
||||
|
||||
function setName($name) {
|
||||
@ -169,7 +170,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$args = new stdclass;
|
||||
// need these three to filter repositories list
|
||||
$args->accepted_types = $accepted_types;
|
||||
$args->return_types = $this->_options['return_types'];
|
||||
$args->return_types = FILE_INTERNAL;
|
||||
$args->context = $PAGE->context;
|
||||
$args->env = 'filemanager';
|
||||
|
||||
@ -178,6 +179,8 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$filepicker_options->client_id = $client_id;
|
||||
$filepicker_options->maxbytes = $this->_options['maxbytes'];
|
||||
$filepicker_options->maxfiles = $this->_options['maxfiles'];
|
||||
$filepicker_options->env = 'filemanager';
|
||||
$filepicker_options->itemid = $draftitemid;
|
||||
|
||||
// Generate file picker
|
||||
$result = new stdclass;
|
||||
@ -190,13 +193,19 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$options->filecount = $filecount;
|
||||
$options->itemid = $draftitemid;
|
||||
$options->subdirs = $this->_options['subdirs'];
|
||||
// store filepicker options
|
||||
$options->filepicker = $filepicker_options;
|
||||
$options->target = $id;
|
||||
|
||||
$html = $this->_getTabs();
|
||||
|
||||
$PAGE->requires->js_function_call('destroy_item', array("nonjs-filemanager-{$client_id}"))->on_dom_ready();
|
||||
$PAGE->requires->js_function_call('show_item', array("filemanager-wrapper-{$client_id}"))->on_dom_ready();
|
||||
$PAGE->requires->js_function_call('launch_filemanager', array($options))->on_dom_ready();
|
||||
|
||||
// print out this only once
|
||||
if (empty($CFG->filemanagertemplateloaded)) {
|
||||
$CFG->filemanagertemplateloaded = true;
|
||||
// print html template
|
||||
$html .= <<<FMHTML
|
||||
<div id="fm-template" style="display:none"><div class="fm-file-menu">___action___</div> <div class="fm-file-name">___fullname___</div></div>
|
||||
FMHTML;
|
||||
@ -219,18 +228,13 @@ FMHTML;
|
||||
</div>
|
||||
FMHTML;
|
||||
// non-javascript file manager, will be destroied automatically if javascript is enabled.
|
||||
// will be removed if javascript is enabled
|
||||
$editorurl = "$CFG->wwwroot/repository/filepicker.php?env=filemanager&action=embedded&itemid=$draftitemid&subdirs=/&maxbytes=$options->maxbytes&ctx_id=".$PAGE->context->id;
|
||||
$html .= <<<NONJS
|
||||
<div id="nonjs-filemanager-$client_id">';
|
||||
<object type="text/html" data="$editorurl" height="160" width="600" style="border:1px solid #000">Error</object>';
|
||||
<div id="nonjs-filemanager-$client_id">
|
||||
<object type="text/html" data="$editorurl" height="160" width="600" style="border:1px solid #000">Error</object>
|
||||
</div>
|
||||
NONJS;
|
||||
|
||||
$PAGE->requires->js_module('filepicker');
|
||||
$PAGE->requires->js_function_call('destroy_item', array("nonjs-filemanager-{$client_id}"))->on_dom_ready();
|
||||
$PAGE->requires->js_function_call('show_item', array("filemanager-wrapper-{$client_id}"))->on_dom_ready();
|
||||
$PAGE->requires->js_function_call('launch_filemanager', array($client_id, $options))->on_dom_ready();
|
||||
$PAGE->requires->js_function_call('fm_init_filepicker', array('btnadd-'.$client_id, $filepicker_options))->on_dom_ready();
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ function fp_filepicker_callback(params) {
|
||||
}
|
||||
|
||||
function fp_init_filepicker(id, options) {
|
||||
YUI(M.yui.loader).use("filepicker", function (Y) {
|
||||
YUI(M.yui.loader).use("core_filepicker", function (Y) {
|
||||
options.formcallback = fp_filepicker_callback;
|
||||
if (!pickers[options.client_id]) {
|
||||
pickers[options.client_id] = new Y.filepicker(options);
|
||||
pickers[options.client_id] = new Y.core_filepicker(options);
|
||||
}
|
||||
Y.one('#'+id).on('click', function(e, client_id) {
|
||||
pickers[options.client_id].show();
|
||||
|
@ -41,16 +41,16 @@
|
||||
|
||||
var active_filepicker = null;
|
||||
|
||||
YUI.add('filepicker', function(Y) {
|
||||
function filepicker (args) {
|
||||
filepicker.superclass.constructor.apply(this, arguments);
|
||||
YUI.add('core_filepicker', function(Y) {
|
||||
function core_filepicker (args) {
|
||||
core_filepicker.superclass.constructor.apply(this, arguments);
|
||||
}
|
||||
filepicker.NAME = "FilePicker";
|
||||
filepicker.ATTRS = {
|
||||
core_filepicker.NAME = "FilePicker";
|
||||
core_filepicker.ATTRS = {
|
||||
options: {},
|
||||
lang: {}
|
||||
};
|
||||
filepicker.json_decode = function(string, source) {
|
||||
core_filepicker.json_decode = function(string, source) {
|
||||
var obj = null;
|
||||
try {
|
||||
obj = Y.JSON.parse(string);
|
||||
@ -59,7 +59,7 @@ YUI.add('filepicker', function(Y) {
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
Y.extend(filepicker, Y.Base, {
|
||||
Y.extend(core_filepicker, Y.Base, {
|
||||
api: M.cfg.wwwroot+'/repository/repository_ajax.php',
|
||||
initializer: function(args) {
|
||||
this.options = args;
|
||||
@ -95,7 +95,7 @@ YUI.add('filepicker', function(Y) {
|
||||
alert('IO FATAL');
|
||||
return;
|
||||
}
|
||||
var data = filepicker.json_decode(o.responseText);
|
||||
var data = core_filepicker.json_decode(o.responseText);
|
||||
args.callback(id,data,p);
|
||||
}
|
||||
},
|
||||
@ -278,11 +278,6 @@ YUI.add('filepicker', function(Y) {
|
||||
}
|
||||
count++;
|
||||
}
|
||||
//if (list.length == 0 && !this.upload) {
|
||||
//panel.innerHTML = '<div class="fp-error">'+mstr.repository.emptylist+'</div>';
|
||||
//}
|
||||
//container.appendChild(panel);
|
||||
//repository_client.print_footer(client_id);
|
||||
},
|
||||
select_file: function(args) {
|
||||
var client_id = this.options.client_id;
|
||||
@ -336,7 +331,7 @@ YUI.add('filepicker', function(Y) {
|
||||
var repository_id = this.active_repo.id;
|
||||
var title = Y.one('#newname-'+client_id).get('value');
|
||||
var filesource = Y.one('#filesource-'+client_id).get('value');
|
||||
var params = {'title':title, 'file':filesource};
|
||||
var params = {'title':title, 'file':filesource, 'savepath': this.options.savepath};
|
||||
|
||||
if (this.options.env == 'editor') {
|
||||
var linkexternal = Y.one('#linkexternal-'+client_id).get('checked');
|
||||
@ -349,19 +344,25 @@ YUI.add('filepicker', function(Y) {
|
||||
|
||||
this.wait('download', title);
|
||||
this.request({
|
||||
action:'download',
|
||||
client_id: client_id,
|
||||
repository_id: repository_id,
|
||||
'params': params,
|
||||
callback: function(id, obj, args) {
|
||||
if (scope.options.editor_target&&scope.options.env=='editor') {
|
||||
scope.options.editor_target.value=obj.url;
|
||||
scope.options.editor_target.onchange();
|
||||
}
|
||||
scope.hide();
|
||||
obj.client_id = client_id;
|
||||
scope.options.formcallback(obj);
|
||||
action:'download',
|
||||
client_id: client_id,
|
||||
repository_id: repository_id,
|
||||
'params': params,
|
||||
callback: function(id, obj, args) {
|
||||
if (scope.options.editor_target&&scope.options.env=='editor') {
|
||||
scope.options.editor_target.value=obj.url;
|
||||
scope.options.editor_target.onchange();
|
||||
}
|
||||
scope.hide();
|
||||
obj.client_id = client_id;
|
||||
var formcallback_scope = null;
|
||||
if (scope.options.magicscope) {
|
||||
formcallback_scope = args.scope.options.magicscope;
|
||||
} else {
|
||||
formcallback_scope = args.scope;
|
||||
}
|
||||
scope.options.formcallback.apply(formcallback_scope, [obj]);
|
||||
}
|
||||
}, true);
|
||||
}, this);
|
||||
var cancel = Y.one('#fp-cancel-'+client_id);
|
||||
@ -787,7 +788,13 @@ YUI.add('filepicker', function(Y) {
|
||||
}
|
||||
scope.hide();
|
||||
o.client_id = client_id;
|
||||
scope.options.formcallback(o);
|
||||
var formcallback_scope = null;
|
||||
if (scope.options.magicscope) {
|
||||
formcallback_scope = args.scope.options.magicscope;
|
||||
} else {
|
||||
formcallback_scope = args.scope;
|
||||
}
|
||||
scope.options.formcallback.apply(formcallback_scope, [o]);
|
||||
}
|
||||
}, true);
|
||||
});
|
||||
@ -1067,5 +1074,5 @@ YUI.add('filepicker', function(Y) {
|
||||
this.render();
|
||||
}
|
||||
});
|
||||
Y.filepicker = filepicker;
|
||||
Y.core_filepicker = core_filepicker;
|
||||
}, '3.0.0', {requires:['base', 'node', 'json', 'async-queue', 'io']});
|
||||
|
Loading…
x
Reference in New Issue
Block a user