From 173c6f2c8bb5464e85ca9b6606ff8a526cf19c7b Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Fri, 21 Dec 2012 11:52:10 +0800 Subject: [PATCH] MDL-7660 - mod_data: Changed the filepicker to filemanager for field elements. This allows users to delete their files or pictures when editing their entries which was previously unavailable. Also the use of the filemanager allows for drag and drop to be active. --- mod/data/data.js | 12 +++++++++++ mod/data/edit.php | 1 + mod/data/field/file/field.class.php | 30 ++++++++++++++++++++------ mod/data/field/picture/field.class.php | 30 ++++++++++++++++++++++---- 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/mod/data/data.js b/mod/data/data.js index 18861e79cab..79f1b371562 100644 --- a/mod/data/data.js +++ b/mod/data/data.js @@ -48,9 +48,15 @@ M.data_filepicker.callback = function(params) { }; /** + * Deprecated since 2.5, will be removed in 2.7. + * Please don't use this function. + * Use the filemanager instead. (/lib/form/filemanager.js) * This fucntion is called for each file picker on page. */ M.data_filepicker.init = function(Y, options) { + if (M.cfg.developerdebug) { + Y.log("You are using a deprecated function call (M.data_filepicker). Please look at rewriting your call to use M.form_filemanager"); + } options.formcallback = M.data_filepicker.callback; if (!M.core_filepicker.instances[options.client_id]) { M.core_filepicker.init(Y, options); @@ -96,9 +102,15 @@ M.data_imagepicker.callback = function(params) { }; /** + * Deprecated since 2.5, will be removed in 2.7. + * Please don't use this function. + * Use the filemanager instead. (/lib/form/filemanager.js) * This fucntion is called for each file picker on page. */ M.data_imagepicker.init = function(Y, options) { + if (M.cfg.developerdebug) { + Y.log("You are using a deprecated function call (M.data_imagepicker). Please look at rewriting your call to use M.form_filemanager"); + } options.formcallback = M.data_imagepicker.callback; if (!M.core_filepicker.instances[options.client_id]) { M.core_filepicker.init(Y, options); diff --git a/mod/data/edit.php b/mod/data/edit.php index 41780364874..c92aa5f5177 100644 --- a/mod/data/edit.php +++ b/mod/data/edit.php @@ -26,6 +26,7 @@ require_once('../../config.php'); require_once('lib.php'); require_once("$CFG->libdir/rsslib.php"); +require_once("$CFG->libdir/form/filemanager.php"); $id = optional_param('id', 0, PARAM_INT); // course module id $d = optional_param('d', 0, PARAM_INT); // database id diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index 605eab387d6..6e81ff5e35d 100644 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -71,21 +71,39 @@ class data_field_file extends data_field_base { $html .= ''; $options = new stdClass(); - $options->maxbytes = $this->field->param3; + $options->areamaxbytes = $this->field->param3; + $options->maxbytes = $this->field->param3; + $options->maxfiles = 1; // Limit to one file for the moment, this may be changed if requested as a feature in the future. $options->itemid = $itemid; $options->accepted_types = '*'; $options->return_types = FILE_INTERNAL; $options->context = $PAGE->context; - $fp = new file_picker($options); - // print out file picker - $html .= $OUTPUT->render($fp); + $fm = new form_filemanager($options); + // Print out file manager. + + $output = $PAGE->get_renderer('core', 'files'); + $html .= $output->render($fm); $html .= ''; $html .= ''; - $module = array('name'=>'data_filepicker', 'fullpath'=>'/mod/data/data.js', 'requires'=>array('core_filepicker')); - $PAGE->requires->js_init_call('M.data_filepicker.init', array($fp->options), true, $module); + $module = array( + 'name'=>'form_filemanager', + 'fullpath'=>'/lib/form/filemanager.js', + 'requires' => array('core_filepicker', 'base', 'io-base', 'node', + 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'), + 'strings' => array( + array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'), + array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'), + array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'), + array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'), + array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'), + array('confirmrenamefile', 'repository') + ) + ); + + $PAGE->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module); return $html; } diff --git a/mod/data/field/picture/field.class.php b/mod/data/field/picture/field.class.php index 37b320d8a9d..3e2ee7e4003 100644 --- a/mod/data/field/picture/field.class.php +++ b/mod/data/field/picture/field.class.php @@ -67,13 +67,17 @@ class data_field_picture extends data_field_base { $str = '
'; $str .= '
'.$this->field->name.''; + $str .= ''; $options = new stdClass(); + $options->areamaxbytes = $this->field->param3; $options->maxbytes = $this->field->param3; + $options->maxfiles = 1; // Only one picture permitted. $options->itemid = $itemid; $options->accepted_types = array('web_image'); $options->return_types = FILE_INTERNAL; @@ -82,9 +86,12 @@ class data_field_picture extends data_field_base { $options->filename = $file->get_filename(); $options->filepath = '/'; } - $fp = new file_picker($options); - $str .= $OUTPUT->render($fp); + $fm = new form_filemanager($options); + // Print out file manager. + + $output = $PAGE->get_renderer('core', 'files'); + $str .= $output->render($fm); $str .= '
'; $str .= ''; @@ -95,8 +102,23 @@ class data_field_picture extends data_field_base { $str .= '
'; $str .= '
'; - $module = array('name'=>'data_imagepicker', 'fullpath'=>'/mod/data/data.js', 'requires'=>array('core_filepicker')); - $PAGE->requires->js_init_call('M.data_imagepicker.init', array($fp->options), true, $module); + $module = array( + 'name'=>'form_filemanager', + 'fullpath'=>'/lib/form/filemanager.js', + 'requires' => array('core_filepicker', 'base', 'io-base', 'node', + 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'), + 'strings' => array( + array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'), + array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'), + array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'), + array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'), + array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'), + array('confirmrenamefile', 'repository') + ) + ); + + $PAGE->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module); + return $str; }