Permalink
Browse files

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.
  • Loading branch information...
1 parent 9da506c commit 173c6f2c8bb5464e85ca9b6606ff8a526cf19c7b @abgreeve abgreeve committed Dec 21, 2012
Showing with 63 additions and 10 deletions.
  1. +12 −0 mod/data/data.js
  2. +1 −0 mod/data/edit.php
  3. +24 −6 mod/data/field/file/field.class.php
  4. +26 −4 mod/data/field/picture/field.class.php
View
@@ -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);
View
@@ -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
@@ -71,21 +71,39 @@ function display_add_field($recordid=0) {
$html .= '<input type="hidden" name="field_'.$this->field->id.'_file" value="'.$itemid.'" />';
$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 .= '</fieldset>';
$html .= '</div>';
- $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;
}
@@ -67,13 +67,17 @@ function display_add_field($recordid=0) {
$str = '<div title="'.s($this->field->description).'">';
$str .= '<fieldset><legend><span class="accesshide">'.$this->field->name.'</span></legend>';
+ $str .= '<noscript>';
if ($file) {
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php/', $this->context->id.'/mod_data/content/'.$content->id.'/'.$file->get_filename());
$str .= '<img width="'.s($this->previewwidth).'" height="'.s($this->previewheight).'" src="'.$src.'" alt="" />';
}
+ $str .= '</noscript>';
$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 @@ function display_add_field($recordid=0) {
$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 .= '<div class="mdl-left">';
$str .= '<input type="hidden" name="field_'.$this->field->id.'_file" value="'.$itemid.'" />';
@@ -95,8 +102,23 @@ function display_add_field($recordid=0) {
$str .= '</fieldset>';
$str .= '</div>';
- $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;
}

0 comments on commit 173c6f2

Please sign in to comment.