mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-21400 converting forms stuff to new M namespace and using standardised JS module coding style, fixed some regressions - for now works in FF only
This commit is contained in:
parent
5f81eeeaca
commit
4c508047eb
@ -197,6 +197,7 @@ M.core_comment = {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
delete: function(id) {
|
||||
var scope = this;
|
||||
var params = {'commentid': id};
|
||||
|
@ -147,6 +147,7 @@ class page_requirements_manager {
|
||||
$this->M_yui_loader->insertBefore = 'firstthemesheet';
|
||||
$this->M_yui_loader->modules = array();
|
||||
$this->add_yui2_modules(); // adds loading info for YUI2
|
||||
$this->js_module($this->find_module('core_filepicker'));
|
||||
|
||||
// YUI3 init code
|
||||
$libs = array('cssreset', 'cssbase', 'cssfonts', 'cssgrids', 'node', 'loader'); // full CSS reset + basic libs
|
||||
@ -335,9 +336,7 @@ class page_requirements_manager {
|
||||
if (strpos($name, 'core_') === 0) {
|
||||
// must be some core stuff
|
||||
if ($name === 'core_filepicker') {
|
||||
$module = array('name'=>$name, 'fullpath'=>'/repository/filepicker.js', 'requires' => array('base', 'node', 'json', 'async-queue', 'io'));
|
||||
} else if($name === 'core_filemanager') {
|
||||
$module = array('name'=>$name, 'fullpath'=>'/lib/form/filemanager.js', 'requires' => array('base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'));
|
||||
$module = array('name'=>$name, 'fullpath'=>'/repository/filepicker.js', 'requires' => array('base', 'node', 'json', 'async-queue', 'io', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'));
|
||||
} else if($name === 'core_comment') {
|
||||
$module = array('name'=>$name, 'fullpath'=>'/comment/comment.js', 'requires' => array('base', 'io', 'node', 'json', 'yui2-animation'));
|
||||
} else if($name === 'core_role') {
|
||||
@ -496,14 +495,16 @@ class page_requirements_manager {
|
||||
* The first argument is always the YUI3 Y instance with all required dependencies
|
||||
* already loaded.
|
||||
* @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM)
|
||||
* @param array $module JS module specification array
|
||||
* @return void
|
||||
*/
|
||||
public function js_init_call($function, array $extraarguments = null, $ondomready = false) {
|
||||
public function js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) {
|
||||
$jscode = js_writer::function_call_with_Y($function, $extraarguments);
|
||||
$module = null;
|
||||
// detect module automatically
|
||||
if (preg_match('/M\.([a-z0-9]+_[^\.]+)/', $function, $matches)) {
|
||||
$module = $this->find_module($matches[1]);
|
||||
if (!$module) {
|
||||
// detect module automatically
|
||||
if (preg_match('/M\.([a-z0-9]+_[^\.]+)/', $function, $matches)) {
|
||||
$module = $this->find_module($matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->js_init_code($jscode, $ondomready, $module);
|
||||
|
@ -45,7 +45,7 @@ class textarea_texteditor extends texteditor {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function use_editor($elementid, array $options=null) {
|
||||
public function use_editor($elementid, array $options=null, $fpoptions=null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +0,0 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* TinyMCE helper javascript functions
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage editor
|
||||
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
function mce_init_editor(elementid, params) {
|
||||
tinyMCE.init(params);
|
||||
}
|
||||
|
||||
function mce_toggleEditor(id) {
|
||||
tinyMCE.execCommand('mceToggleEditor',false,id);
|
||||
}
|
||||
|
||||
function mce_saveOnSubmit(id) {
|
||||
var prevOnSubmit = document.getElementById(id).form.onsubmit;
|
||||
document.getElementById(id).form.onsubmit = function() {
|
||||
tinyMCE.triggerSave();
|
||||
var ret = true;
|
||||
if (prevOnSubmit != undefined) {
|
||||
if (prevOnSubmit()) {
|
||||
ret = true;
|
||||
prevOnSubmit = null;
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
var editor_filepickers = {};
|
||||
var editor_options = {};
|
||||
function editor_filepicker_callback(args) {
|
||||
}
|
||||
function editor_init_filepicker(editorid, options) {
|
||||
editor_options[editorid] = options;
|
||||
}
|
||||
function mce_moodlefilemanager(target_id, url, type, win) {
|
||||
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 M.core_filepicker(options);
|
||||
}
|
||||
editor_filepickers[client_id].show();
|
||||
});
|
||||
}
|
@ -52,15 +52,15 @@ class tinymce_texteditor extends texteditor {
|
||||
}
|
||||
|
||||
public function head_setup() {
|
||||
global $CFG, $PAGE;
|
||||
require_once("$CFG->dirroot/repository/lib.php");
|
||||
$PAGE->requires->js('/lib/editor/tinymce/tiny_mce_src.js');
|
||||
$PAGE->requires->js('/lib/editor/tinymce/extra/tinymce_utils.js');
|
||||
}
|
||||
|
||||
public function use_editor($elementid, array $options=null) {
|
||||
public function use_editor($elementid, array $options=null, $fpoptions=null) {
|
||||
global $PAGE;
|
||||
$PAGE->requires->js_function_call('mce_init_editor', array($elementid, $this->get_init_params($elementid, $options)));
|
||||
$PAGE->requires->js('/lib/editor/tinymce/tiny_mce_src.js');
|
||||
$PAGE->requires->js_init_call('M.editor_tinymce.init_editor', array($elementid, $this->get_init_params($elementid, $options)), true);
|
||||
if ($fpoptions) {
|
||||
$PAGE->requires->js_init_call('M.editor_tinymce.init_filepicker', array($elementid, $fpoptions), true);
|
||||
}
|
||||
}
|
||||
|
||||
protected function get_init_params($elementid, array $options=null) {
|
||||
@ -131,7 +131,7 @@ class tinymce_texteditor extends texteditor {
|
||||
|
||||
if (empty($options['legacy'])) {
|
||||
if (isset($options['maxfiles']) and $options['maxfiles'] != 0) {
|
||||
$params['file_browser_callback'] = "mce_moodlefilemanager";
|
||||
$params['file_browser_callback'] = "M.editor_tinymce.filepicker";
|
||||
}
|
||||
}
|
||||
|
||||
|
62
lib/editor/tinymce/module.js
Normal file
62
lib/editor/tinymce/module.js
Normal file
@ -0,0 +1,62 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* TinyMCE helper javascript functions
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage editor
|
||||
* @copyright 2010 Petr Skoda (skodak) info@skoda.org
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
M.editor_tinymce = M.editor_tinymce || {};
|
||||
|
||||
M.editor_tinymce.editor_options = M.editor_tinymce.options || {};
|
||||
M.editor_tinymce.filepicker_options = M.editor_tinymce.filepicker_options || {};
|
||||
|
||||
M.editor_tinymce.init_editor = function(Y, editorid, options) {
|
||||
M.editor_tinymce.editor_options[editorid] = options;
|
||||
tinyMCE.init(options);
|
||||
|
||||
var item = document.getElementById(editorid+'_filemanager');
|
||||
if (item) {
|
||||
item.parentNode.removeChild(item);
|
||||
}
|
||||
};
|
||||
|
||||
M.editor_tinymce.init_filepicker = function(Y, editorid, options) {
|
||||
M.editor_tinymce.filepicker_options[editorid] = options;
|
||||
};
|
||||
|
||||
M.editor_tinymce.toggle = function(id) {
|
||||
tinyMCE.execCommand('mceToggleEditor', false, id);
|
||||
};
|
||||
|
||||
M.editor_tinymce.filepicker_callback = function(args) {
|
||||
};
|
||||
|
||||
M.editor_tinymce.filepicker = function(target_id, url, type, win) {
|
||||
YUI(M.yui.loader).use('core_filepicker', function (Y) {
|
||||
var editor_id = tinyMCE.selectedInstance.editorId;
|
||||
var options = M.editor_tinymce.filepicker_options[editor_id];
|
||||
|
||||
options.formcallback = M.editor_tinymce.filepicker_callback;
|
||||
options.editor_target = win.document.getElementById(target_id);
|
||||
|
||||
M.core_filepicker.show(Y, options);
|
||||
});
|
||||
};
|
||||
|
@ -32,7 +32,7 @@
|
||||
* @global object
|
||||
* @global object
|
||||
* @param int $format text format or null of none
|
||||
* @return object texteditor object
|
||||
* @return texteditor object
|
||||
*/
|
||||
function get_preferred_texteditor($format=null) {
|
||||
global $CFG, $USER;
|
||||
@ -171,9 +171,10 @@ abstract class texteditor {
|
||||
* Add required JS needed for editor
|
||||
* @param string $elementid id of text area to be converted to editor
|
||||
* @param array $options
|
||||
* @param obejct $fpoptions file picker options
|
||||
* @return void
|
||||
*/
|
||||
public abstract function use_editor($elementid, array $options=null);
|
||||
public abstract function use_editor($elementid, array $options=null, $fpoptions = null);
|
||||
|
||||
/**
|
||||
* Setup all JS and CSS needed for editor.
|
||||
|
@ -119,6 +119,8 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
|
||||
return $this->getFrozenHtml();
|
||||
}
|
||||
|
||||
$ctx = $this->_options['context'];
|
||||
|
||||
$id = $this->_attributes['id'];
|
||||
$elname = $this->_attributes['name'];
|
||||
|
||||
@ -146,9 +148,34 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
|
||||
$formats[$fid] = $strformats[$fid];
|
||||
}
|
||||
|
||||
// get filepicker info
|
||||
$fpoptions = null;
|
||||
if ($maxfiles != 0 ) {
|
||||
if (empty($draftitemid)) {
|
||||
// no existing area info provided - let's use fresh new draft area
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
$this->setValue(array('itemid'=>file_get_unused_draft_itemid()));
|
||||
$draftitemid = $this->_values['itemid'];
|
||||
}
|
||||
|
||||
$args = new stdclass;
|
||||
// need these three to filter repositories list
|
||||
$args->accepted_types = array('image', 'video', 'media');
|
||||
$args->return_types = (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
$args->context = $ctx;
|
||||
$args->env = 'filepicker';
|
||||
|
||||
$fpoptions = initialise_filepicker($args);
|
||||
|
||||
$fpoptions->client_id = uniqid();
|
||||
$fpoptions->maxbytes = $this->_options['maxbytes'];
|
||||
$fpoptions->maxfiles = 1;
|
||||
$fpoptions->env = 'editor';
|
||||
$fpoptions->itemid = $draftitemid;
|
||||
}
|
||||
|
||||
/// print text area - TODO: add on-the-fly switching, size configuration, etc.
|
||||
$editor->use_editor($id, $this->_options);
|
||||
$ctx = $this->_options['context'];
|
||||
$editor->use_editor($id, $this->_options, $fpoptions);
|
||||
|
||||
$str .= '<div><textarea id="'.$id.'" name="'.$elname.'[text]" rows="15" cols="80">';
|
||||
$str .= s($text);
|
||||
@ -164,45 +191,15 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
|
||||
$str .= '</div>';
|
||||
|
||||
if ($maxfiles != 0 ) { // 0 means no files, -1 unlimited
|
||||
if (empty($draftitemid)) {
|
||||
// no existing area info provided - let's use fresh new draft area
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
$this->setValue(array('itemid'=>file_get_unused_draft_itemid()));
|
||||
$draftitemid = $this->_values['itemid'];
|
||||
}
|
||||
$str .= '<div><input type="hidden" name="'.$elname.'[itemid]" value="'.$draftitemid.'" /></div>';
|
||||
/// embedded image files - TODO: hide on the fly when switching editors
|
||||
$str .= '<div id="'.$id.'_filemanager">';
|
||||
$editorurl = "$CFG->wwwroot/repository/filepicker.php?action=browse&env=editor&itemid=$draftitemid&subdirs=$subdirs&maxbytes=$maxbytes&ctx_id=".$ctx->id;
|
||||
$str .= '<object type="text/html" data="'.$editorurl.'" height="160" width="600" style="border:1px solid #000">Error</object>'; // TODO: localise, fix styles, etc.
|
||||
$str .= '</div>';
|
||||
|
||||
$client_id = uniqid();
|
||||
|
||||
$args = new stdclass;
|
||||
// need these three to filter repositories list
|
||||
$args->accepted_types = array('image', 'video', 'media');
|
||||
$args->return_types = (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
$args->context = $ctx;
|
||||
$args->env = 'filepicker';
|
||||
|
||||
$options = initialise_filepicker($args);
|
||||
|
||||
$options->client_id = $client_id;
|
||||
$options->maxbytes = $this->_options['maxbytes'];
|
||||
$options->maxfiles = 1;
|
||||
$options->env = 'editor';
|
||||
$options->itemid = $draftitemid;
|
||||
|
||||
$PAGE->requires->js_module('core_filepicker');
|
||||
$PAGE->requires->js_function_call('editor_init_filepicker', array($id, $options))->on_dom_ready();
|
||||
|
||||
if ($editor->supports_repositories()) {
|
||||
$str .= html_writer::script(js_writer::function_call('destroy_item', array("{$id}_filemanager")));
|
||||
}
|
||||
} else {
|
||||
// should disable file picker
|
||||
$str .= 'No file allowed';
|
||||
//$str .= 'No file allowed';
|
||||
}
|
||||
|
||||
$str .= '</div>';
|
||||
|
@ -32,39 +32,42 @@
|
||||
* this.options.currentpath
|
||||
* this.options.itemid
|
||||
*/
|
||||
M.filemanagers = M.filemanagers||{};
|
||||
M.fm_filepickers = M.fm_filepickers || {};
|
||||
|
||||
YUI.add('core_filemanager', function(Y) {
|
||||
function core_filemanager (args) {
|
||||
core_filemanager.superclass.constructor.apply(this, arguments);
|
||||
|
||||
M.form_filemanager = {};
|
||||
|
||||
/**
|
||||
* This fucntion is called for each file picker on page.
|
||||
*/
|
||||
M.form_filemanager.init = function(Y, options) {
|
||||
var FileManagerHelper = function(options) {
|
||||
FileManagerHelper.superclass.constructor.apply(this, arguments);
|
||||
}
|
||||
core_filemanager.NAME = "FileManager";
|
||||
core_filemanager.ATTRS = {
|
||||
FileManagerHelper.NAME = "FileManager";
|
||||
FileManagerHelper.ATTRS = {
|
||||
options: {},
|
||||
lang: {}
|
||||
};
|
||||
Y.extend(core_filemanager, Y.Base, {
|
||||
|
||||
Y.extend(FileManagerHelper, Y.Base, {
|
||||
api: M.cfg.wwwroot+'/files/files_ajax.php',
|
||||
menus: {},
|
||||
initializer: function(args) {
|
||||
this.options = args;
|
||||
initializer: function(options) {
|
||||
this.options = options;
|
||||
this.client_id = options.client_id;
|
||||
this.currentpath = '/';
|
||||
this.filepicker_options = args.filepicker;
|
||||
this.client_id = '';
|
||||
this.maxfiles = args.maxfiles;
|
||||
this.maxbytes = args.maxbytes;
|
||||
if (args.client_id) {
|
||||
this.client_id = args.client_id;
|
||||
}
|
||||
if (args.filecount) {
|
||||
this.filecount = args.filecount;
|
||||
this.filepicker_options = options.filepicker;
|
||||
this.maxfiles = options.maxfiles;
|
||||
this.maxbytes = options.maxbytes;
|
||||
if (options.filecount) {
|
||||
this.filecount = options.filecount;
|
||||
} else {
|
||||
this.filecount = 0;
|
||||
}
|
||||
this.setup_buttons();
|
||||
this.render();
|
||||
},
|
||||
|
||||
request: function(args) {
|
||||
var api = this.api + '?action='+args.action;
|
||||
var params = {};
|
||||
@ -72,7 +75,7 @@ YUI.add('core_filemanager', function(Y) {
|
||||
if (args['scope']) {
|
||||
scope = args['scope'];
|
||||
}
|
||||
params['sesskey']=M.cfg.sesskey;
|
||||
params['sesskey'] = M.cfg.sesskey;
|
||||
params['client_id'] = this.client_id;
|
||||
params['filepath'] = this.currentpath;
|
||||
params['itemid'] = this.options.itemid?this.options.itemid:0;
|
||||
@ -133,10 +136,9 @@ YUI.add('core_filemanager', function(Y) {
|
||||
});
|
||||
},
|
||||
setup_buttons: function() {
|
||||
var client_id = this.client_id;
|
||||
var button_download = Y.one("#btndwn-"+client_id);
|
||||
var button_create = Y.one("#btncrt-"+client_id);
|
||||
var button_addfile = Y.one("#btnadd-"+client_id);
|
||||
var button_download = Y.one("#btndwn-"+this.client_id);
|
||||
var button_create = Y.one("#btncrt-"+this.client_id);
|
||||
var button_addfile = Y.one("#btnadd-"+this.client_id);
|
||||
|
||||
// setup 'add file' button
|
||||
// if maxfiles == -1, the no limit
|
||||
@ -146,18 +148,11 @@ YUI.add('core_filemanager', function(Y) {
|
||||
} else {
|
||||
button_addfile.on('click', function(e) {
|
||||
var options = this.filepicker_options;
|
||||
var scope = this;
|
||||
var client_id = this.client_id;
|
||||
Y.use('core_filepicker', function (Y) {
|
||||
options.formcallback = scope.filepicker_callback;
|
||||
// XXX: magic here, to let filepicker use filemanager scope
|
||||
options.magicscope = scope;
|
||||
options.savepath = scope.currentpath;
|
||||
if (!M.fm_filepickers[client_id]) {
|
||||
M.fm_filepickers[client_id] = new M.core_filepicker(options);
|
||||
}
|
||||
M.fm_filepickers[client_id].show();
|
||||
});
|
||||
options.formcallback = this.filepicker_callback;
|
||||
// XXX: magic here, to let filepicker use filemanager scope
|
||||
options.magicscope = this;
|
||||
options.savepath = this.currentpath;
|
||||
M.core_filepicker.show(Y, options);
|
||||
}, this);
|
||||
}
|
||||
|
||||
@ -224,11 +219,10 @@ YUI.add('core_filemanager', function(Y) {
|
||||
}, this);
|
||||
},
|
||||
render: function() {
|
||||
var client_id = this.client_id;
|
||||
var options = this.options;
|
||||
var path = this.options.path;
|
||||
var list = this.options.list;
|
||||
var breadcrumb = Y.one('#fm-path-'+client_id);
|
||||
var breadcrumb = Y.one('#fm-path-'+this.client_id);
|
||||
// build breadcrumb
|
||||
if (path) {
|
||||
// empty breadcrumb
|
||||
@ -243,7 +237,7 @@ YUI.add('core_filemanager', function(Y) {
|
||||
}
|
||||
count++;
|
||||
|
||||
var pathid = 'fm-path-node-'+client_id;
|
||||
var pathid = 'fm-path-node-'+this.client_id;
|
||||
pathid += ('-'+count);
|
||||
|
||||
var crumb = Y.Node.create('<a href="###" id="'+pathid+'">'+path[p].name+'</a>');
|
||||
@ -252,7 +246,7 @@ YUI.add('core_filemanager', function(Y) {
|
||||
|
||||
var args = {};
|
||||
args.requestpath = path[p].path;
|
||||
args.client_id = client_id;
|
||||
args.client_id = this.client_id;
|
||||
Y.one('#'+pathid).on('click', function(e, args) {
|
||||
var scope = this;
|
||||
var params = {};
|
||||
@ -270,7 +264,7 @@ YUI.add('core_filemanager', function(Y) {
|
||||
}
|
||||
}
|
||||
var template = Y.one('#fm-template');
|
||||
var container = Y.one('#filemanager-' + client_id);
|
||||
var container = Y.one('#filemanager-' + this.client_id);
|
||||
var listhtml = '';
|
||||
|
||||
// folder list items
|
||||
@ -308,11 +302,11 @@ YUI.add('core_filemanager', function(Y) {
|
||||
for(var i in list) {
|
||||
count++;
|
||||
// the li html element
|
||||
var htmlid = 'fileitem-'+client_id+'-'+count;
|
||||
var htmlid = 'fileitem-'+this.client_id+'-'+count;
|
||||
// link to file
|
||||
var fileid = 'filename-'+client_id+'-'+count;
|
||||
var fileid = 'filename-'+this.client_id+'-'+count;
|
||||
// file menu
|
||||
var action = 'action-' +client_id+'-'+count;
|
||||
var action = 'action-' +this.client_id+'-'+count;
|
||||
|
||||
var html = template.get('innerHTML');
|
||||
|
||||
@ -326,7 +320,7 @@ YUI.add('core_filemanager', function(Y) {
|
||||
var url = "###";
|
||||
// check main file
|
||||
//var ismainfile = false;
|
||||
//if (fm_cfg[client_id].mainfilename && (fm_cfg[client_id].mainfilename.toLowerCase() == list[i].fullname.toLowerCase())) {
|
||||
//if (fm_cfg[this.client_id].mainfilename && (fm_cfg[this.client_id].mainfilename.toLowerCase() == list[i].fullname.toLowerCase())) {
|
||||
//ismainfile = true;
|
||||
//}
|
||||
|
||||
@ -366,11 +360,11 @@ YUI.add('core_filemanager', function(Y) {
|
||||
html = '<li id="'+htmlid+'">'+html+'</li>';
|
||||
listhtml += html;
|
||||
}
|
||||
if (!Y.one('#draftfiles-'+client_id)) {
|
||||
var filelist = Y.Node.create('<ul id="draftfiles-'+client_id+'"></ul>');
|
||||
if (!Y.one('#draftfiles-'+this.client_id)) {
|
||||
var filelist = Y.Node.create('<ul id="draftfiles-'+this.client_id+'"></ul>');
|
||||
container.appendChild(filelist);
|
||||
}
|
||||
Y.one('#draftfiles-'+client_id).set('innerHTML', listhtml);
|
||||
Y.one('#draftfiles-'+this.client_id).set('innerHTML', listhtml);
|
||||
|
||||
// click normal file menu
|
||||
Y.on('click', this.create_filemenu, file_ids, this, file_data);
|
||||
@ -661,5 +655,17 @@ YUI.add('core_filemanager', function(Y) {
|
||||
menu.show();
|
||||
}
|
||||
});
|
||||
M.core_filemanager = core_filemanager;
|
||||
}, '3.0.1', {requires: ['base', 'io', 'node', 'json']});
|
||||
|
||||
// finally init everything needed
|
||||
|
||||
var item = document.getElementById('nonjs-filemanager-'+options.client_id);
|
||||
if (item) {
|
||||
item.parentNode.removeChild(item);
|
||||
}
|
||||
item = document.getElementById('filemanager-wrapper-'+options.client_id);
|
||||
if (item) {
|
||||
item.style.display = '';
|
||||
}
|
||||
|
||||
new FileManagerHelper(options);
|
||||
};
|
||||
|
@ -46,8 +46,6 @@ 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_module('core_filepicker');
|
||||
$PAGE->requires->js_module('core_filemanager');
|
||||
}
|
||||
|
||||
function setName($name) {
|
||||
@ -199,9 +197,10 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
|
||||
$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();
|
||||
|
||||
$module = array('name'=>'form_filemanager', 'fullpath'=>'/lib/form/filemanager.js', 'requires' => array('core_filepicker', 'base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'));
|
||||
$PAGE->requires->js_module($module);
|
||||
$PAGE->requires->js_init_call('M.form_filemanager.init', array($options), true, $module);
|
||||
|
||||
// print out this only once
|
||||
if (empty($CFG->filemanagertemplateloaded)) {
|
||||
|
@ -1,17 +1,31 @@
|
||||
var pickers = {};
|
||||
function fp_filepicker_callback(params) {
|
||||
|
||||
M.form_filepicker = {};
|
||||
|
||||
|
||||
M.form_filepicker.callback = function(params) {
|
||||
var html = '<a href="'+params['url']+'">'+params['file']+'</a>';
|
||||
document.getElementById('file_info_'+params['client_id']).innerHTML = html;
|
||||
}
|
||||
};
|
||||
|
||||
function fp_init_filepicker(id, options) {
|
||||
YUI(M.yui.loader).use("core_filepicker", function (Y) {
|
||||
options.formcallback = fp_filepicker_callback;
|
||||
if (!pickers[options.client_id]) {
|
||||
pickers[options.client_id] = new M.core_filepicker(options);
|
||||
}
|
||||
Y.one('#'+id).on('click', function(e, client_id) {
|
||||
pickers[options.client_id].show();
|
||||
}, this, options.client_id);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This fucntion is called for each file picker on page.
|
||||
*/
|
||||
M.form_filepicker.init = function(Y, options) {
|
||||
options.formcallback = M.form_filepicker.callback;
|
||||
if (!M.core_filepicker.instances[options.client_id]) {
|
||||
M.core_filepicker.init(Y, options);
|
||||
}
|
||||
Y.on('click', function(e, client_id) {
|
||||
e.preventDefault();
|
||||
M.core_filepicker.instances[client_id].show();
|
||||
}, '#filepicker-button-'+options.client_id, null, options.client_id);
|
||||
|
||||
var item = document.getElementById('nonjs-filepicker-'+options.client_id);
|
||||
if (item) {
|
||||
item.parentNode.removeChild(item);
|
||||
}
|
||||
item = document.getElementById('filepicker-wrapper-'+options.client_id);
|
||||
if (item) {
|
||||
item.style.display = '';
|
||||
}
|
||||
};
|
||||
|
@ -115,10 +115,9 @@ Moodle File Picker
|
||||
</object>
|
||||
</noscript>
|
||||
EOD;
|
||||
$str .= html_writer::script(js_writer::function_call('destroy_item', array("nonjs-filepicker-{$client_id}")));
|
||||
$str .= html_writer::script(js_writer::function_call('show_item', array("filepicker-wrapper-{$client_id}")));
|
||||
$PAGE->requires->js_function_call('fp_init_filepicker', array('filepicker-button-'.$client_id, $options))->on_dom_ready();
|
||||
$PAGE->requires->js_module('filepicker');
|
||||
$module = array('name'=>'form_filepicker', 'fullpath'=>'/lib/form/filepicker.js', 'requires'=>array('core_filepicker'));
|
||||
$PAGE->requires->js_module($module);
|
||||
$PAGE->requires->js_init_call('M.form_filepicker.init', array($options), true, $module);
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
@ -157,17 +157,6 @@ M.util.CollapsibleRegion.prototype.icon = null;
|
||||
|
||||
//=== old legacy JS code, hopefully to be replaced soon by M.xx.yy and YUI3 code ===
|
||||
|
||||
function launch_filemanager(options) {
|
||||
// TODO: move to M.form_filemanager.init()
|
||||
YUI(M.yui.loader).use('core_filemanager', function(Y) {
|
||||
var client_id = options.client_id;
|
||||
// filemangers defined in lib/form/filemanager.js
|
||||
if (!filemanagers[client_id]) {
|
||||
filemanagers[client_id] = new M.core_filemanager(options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function popupchecker(msg) {
|
||||
var testwindow = window.open('', '', 'width=1,height=1,left=0,top=0,scrollbars=no');
|
||||
if (!testwindow) {
|
||||
|
@ -39,33 +39,47 @@
|
||||
* this.logindata, cached login form
|
||||
*/
|
||||
|
||||
var active_filepicker = null;
|
||||
M.core_filepicker = M.core_filepicker || {};
|
||||
|
||||
M.core_filepicker = (function(){
|
||||
function core_filepicker (args) {
|
||||
core_filepicker.superclass.constructor.apply(this, arguments);
|
||||
/**
|
||||
* instances of file pickers used on page
|
||||
*/
|
||||
M.core_filepicker.instances = M.core_filepicker.instances || {};
|
||||
|
||||
/**
|
||||
* Init and show file picker
|
||||
*/
|
||||
M.core_filepicker.show = function(Y, options) {
|
||||
if (!M.core_filepicker.instances[options.client_id]) {
|
||||
M.core_filepicker.init(Y, options);
|
||||
}
|
||||
core_filepicker.NAME = "FilePicker";
|
||||
core_filepicker.ATTRS = {
|
||||
M.core_filepicker.instances[options.client_id].show();
|
||||
};
|
||||
|
||||
/**
|
||||
* Add new file picker to current instances
|
||||
*/
|
||||
M.core_filepicker.init = function(Y, options) {
|
||||
var FilePickerHelper = function(options) {
|
||||
FilePickerHelper.superclass.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
FilePickerHelper.NAME = "FilePickerHelper";
|
||||
FilePickerHelper.ATTRS = {
|
||||
options: {},
|
||||
lang: {}
|
||||
};
|
||||
core_filepicker.json_decode = function(string, source) {
|
||||
var obj = null;
|
||||
try {
|
||||
obj = Y.JSON.parse(string);
|
||||
} catch(e) {
|
||||
alert(mstr.repository.invalidjson+' - |'+source+'| -'+stripHTML(string));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
Y.extend(core_filepicker, Y.Base, {
|
||||
|
||||
Y.extend(FilePickerHelper, Y.Base, {
|
||||
api: M.cfg.wwwroot+'/repository/repository_ajax.php',
|
||||
initializer: function(args) {
|
||||
this.options = args;
|
||||
|
||||
initializer: function(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
destructor: function() {
|
||||
},
|
||||
|
||||
request: function(args, redraw) {
|
||||
var api = this.api + '?action='+args.action;
|
||||
var params = {};
|
||||
@ -95,7 +109,12 @@ M.core_filepicker = (function(){
|
||||
alert('IO FATAL');
|
||||
return;
|
||||
}
|
||||
var data = core_filepicker.json_decode(o.responseText);
|
||||
var data = null;
|
||||
try {
|
||||
data = Y.JSON.parse(o.responseText);
|
||||
} catch(e) {
|
||||
alert(mstr.repository.invalidjson+' - |'+source+'| -'+stripHTML(o.responseText));
|
||||
}
|
||||
args.callback(id,data,p);
|
||||
}
|
||||
},
|
||||
@ -106,7 +125,8 @@ M.core_filepicker = (function(){
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'User-Agent': 'MoodleFilePicker/3.0'
|
||||
},
|
||||
data: build_querystring(params)
|
||||
data: build_querystring(params),
|
||||
context: this
|
||||
};
|
||||
if (args.form) {
|
||||
cfg.form = args.form;
|
||||
@ -116,6 +136,7 @@ M.core_filepicker = (function(){
|
||||
this.wait('load');
|
||||
}
|
||||
},
|
||||
|
||||
build_tree: function(node, level) {
|
||||
var client_id = this.options.client_id;
|
||||
if(node.children) {
|
||||
@ -773,7 +794,7 @@ M.core_filepicker = (function(){
|
||||
Y.one('#panel-'+client_id).appendChild(upload_form);
|
||||
var scope = this;
|
||||
Y.one('#'+id+'_action').on('click', function() {
|
||||
Y.use('io-upload-iframe' ,function() {
|
||||
Y.use('io-upload-iframe', function() {
|
||||
scope.request({
|
||||
scope: scope,
|
||||
action:'upload',
|
||||
@ -1043,7 +1064,7 @@ M.core_filepicker = (function(){
|
||||
}
|
||||
var panel = Y.one('#panel-'+client_id);
|
||||
var p = this.filepath;
|
||||
if(p && p.length!=0) {
|
||||
if (p && p.length!=0) {
|
||||
var path = Y.Node.create('<div id="path-'+client_id+'" class="fp-pathbar"></div>');
|
||||
panel.appendChild(path);
|
||||
for(var i = 0; i < p.length; i++) {
|
||||
@ -1074,5 +1095,6 @@ M.core_filepicker = (function(){
|
||||
this.render();
|
||||
}
|
||||
});
|
||||
return core_filepicker;
|
||||
})();
|
||||
|
||||
M.core_filepicker.instances[options.client_id] = new FilePickerHelper(options);
|
||||
};
|
||||
|
@ -136,7 +136,7 @@
|
||||
<html><head>
|
||||
<script type="text/javascript">
|
||||
if(window.opener){
|
||||
active_filepicker.list();
|
||||
M.core_filepicker.active.list();
|
||||
window.close();
|
||||
} else {
|
||||
alert("{$strhttpsbug }");
|
||||
|
Loading…
x
Reference in New Issue
Block a user