Skip to content

Commit

Permalink
MDL-7660 - mod_data: Changed the filepicker to filemanager for field …
Browse files Browse the repository at this point in the history
…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
abgreeve committed Jan 4, 2013
1 parent 9da506c commit 173c6f2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
12 changes: 12 additions & 0 deletions mod/data/data.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions mod/data/edit.php
Expand Up @@ -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
Expand Down
30 changes: 24 additions & 6 deletions mod/data/field/file/field.class.php
Expand Up @@ -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;
}
Expand Down
30 changes: 26 additions & 4 deletions mod/data/field/picture/field.class.php
Expand Up @@ -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;
Expand All @@ -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.'" />';
Expand All @@ -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;
}

Expand Down

0 comments on commit 173c6f2

Please sign in to comment.