mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
MDL-24030, fixed url field type
This commit is contained in:
parent
9c9de5f0c2
commit
cd4a1897d9
@ -71,7 +71,6 @@ M.data_filepicker.init = function(Y, options) {
|
||||
M.data_urlpicker = {};
|
||||
|
||||
M.data_urlpicker.init = function(Y, options) {
|
||||
this.formelementid = options.formelementid;
|
||||
options.formcallback = M.data_urlpicker.callback;
|
||||
if (!M.core_filepicker.instances[options.client_id]) {
|
||||
M.core_filepicker.init(Y, options);
|
||||
@ -84,12 +83,11 @@ M.data_urlpicker.init = function(Y, options) {
|
||||
};
|
||||
|
||||
M.data_urlpicker.callback = function (params) {
|
||||
document.getElementById(M.data_urlpicker.formelementid).value = params.url;
|
||||
document.getElementById('field_url_'+params.client_id).value = params.url;
|
||||
}
|
||||
|
||||
M.data_imagepicker = {};
|
||||
|
||||
|
||||
M.data_imagepicker.callback = function(params) {
|
||||
var html = '<a href="'+params['url']+'"><img src="'+params['url']+'" /> '+params['file']+'</a>';
|
||||
document.getElementById('file_info_'+params['client_id']).innerHTML = html;
|
||||
|
@ -28,6 +28,16 @@ class data_field_url extends data_field_base {
|
||||
function display_add_field($recordid=0) {
|
||||
global $CFG, $DB, $OUTPUT, $PAGE;
|
||||
|
||||
$args = new stdclass;
|
||||
$args->accepted_types = '*';
|
||||
$args->return_types = FILE_EXTERNAL;
|
||||
$args->context = $this->context;
|
||||
$args->env = 'url';
|
||||
$fp = new file_picker($args);
|
||||
$options = $fp->options;
|
||||
|
||||
$fieldid = 'field_url_'.$options->client_id;
|
||||
|
||||
$straddlink = get_string('choosealink', 'repository');
|
||||
$url = '';
|
||||
$text = '';
|
||||
@ -36,30 +46,22 @@ class data_field_url extends data_field_base {
|
||||
$url = $content->content;
|
||||
$text = $content->content1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$str = '<div title="'.s($this->field->description).'">';
|
||||
if (!empty($this->field->param1) and empty($this->field->param2)) {
|
||||
$str .= '<table><tr><td align="right">';
|
||||
$str .= get_string('url','data').':</td><td><input type="text" name="field_'.$this->field->id.'_0" id="field_'.$this->field->id.'_0" value="'.$url.'" size="60" /></td></tr>';
|
||||
$str .= get_string('url','data').':</td><td><input type="text" name="field_'.$this->field->id.'_0" id="'.$fieldid.'" value="'.$url.'" size="60" /></td></tr>';
|
||||
$str .= '<tr><td align="right">'.get_string('text','data').':</td><td><input type="text" name="field_'.$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="'.s($text).'" size="60" /></td></tr>';
|
||||
$str .= '</table>';
|
||||
} else {
|
||||
// Just the URL field
|
||||
$str .= '<input type="text" name="field_'.$this->field->id.'_0" id="field_'.$this->field->id.'_0" value="'.s($url).'" size="60" />';
|
||||
$str .= '<input type="text" name="field_'.$this->field->id.'_0" id="'.$fieldid.'" value="'.s($url).'" size="60" />';
|
||||
}
|
||||
$args = new stdclass;
|
||||
$args->accepted_types = '*';
|
||||
$args->return_types = FILE_EXTERNAL;
|
||||
$args->context = $this->context;
|
||||
$args->env = 'url';
|
||||
$fp = new file_picker($args);
|
||||
$options = $fp->options;
|
||||
$options->formelementid = 'field_'.$this->field->id.'_0';
|
||||
|
||||
$str .= '<button id="filepicker-button-'.$options->client_id.'" style="display:none">'.$straddlink.'</button>';
|
||||
|
||||
// print out file picker
|
||||
$str .= $OUTPUT->render($fp);
|
||||
//$str .= $OUTPUT->render($fp);
|
||||
|
||||
$module = array('name'=>'data_urlpicker', 'fullpath'=>'/mod/data/data.js', 'requires'=>array('core_filepicker'));
|
||||
$PAGE->requires->js_init_call('M.data_urlpicker.init', array($options), true, $module);
|
||||
@ -123,7 +125,7 @@ class data_field_url extends data_field_base {
|
||||
$content->fieldid = $this->field->id;
|
||||
$content->recordid = $recordid;
|
||||
$names = explode('_', $name);
|
||||
|
||||
|
||||
switch ($names[2]) {
|
||||
case 0:
|
||||
// update link
|
||||
@ -139,8 +141,8 @@ class data_field_url extends data_field_base {
|
||||
|
||||
if (!empty($content->content) && (strpos($content->content, '://') === false) && (strpos($content->content, '/', 0) === false)) {
|
||||
$content->content = 'http://' . $content->content;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
|
||||
$content->id = $oldcontent->id;
|
||||
return $DB->update_record('data_content', $content);
|
||||
|
Loading…
x
Reference in New Issue
Block a user