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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 @@ class data_field_file extends data_field_base {
|
||||
$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 @@ class data_field_picture extends data_field_base {
|
||||
|
||||
$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 @@ 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 .= '<div class="mdl-left">';
|
||||
$str .= '<input type="hidden" name="field_'.$this->field->id.'_file" value="'.$itemid.'" />';
|
||||
@@ -95,8 +102,23 @@ class data_field_picture extends data_field_base {
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user