"MDL-20470, rename formslib element name and add an option to turn the picker button on/off"

This commit is contained in:
dongsheng
2009-10-13 08:31:50 +00:00
parent 8449364cfa
commit 1a03384f5e
6 changed files with 154 additions and 2 deletions
+1
View File
@@ -206,6 +206,7 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext))
$temp->add(new admin_setting_heading('managerepositoriescommonheading', get_string('commonsettings', 'admin'), ''));
$temp->add(new admin_setting_configtext('repositorycacheexpire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120));
$temp->add(new admin_setting_configcheckbox('repositoryuseexternallink', get_string('useexternallink', 'repository'), get_string('configuseexternallink', 'repository'), 0));
$temp->add(new admin_setting_configcheckbox('repositoryusepickerbutton', get_string('usepickerbutton', 'repository'), '', 1));
$ADMIN->add('repositorysettings', $temp);
$ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
get_string('addplugin', 'repository'), $url, 'moodle/site:config', true),
+1
View File
@@ -121,6 +121,7 @@ $string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully';
$string['useexternallink'] = 'Use external link instead downloading files';
$string['configuseexternallink'] = 'Will return the external link to file picker instead downloading external files';
$string['usepickerbutton'] = 'Use file picker button beside text element';
$string['wrongcontext'] = 'You cannot access to this context';
$string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';
$string['ziped'] = 'Compress folder successfully';
+19
View File
@@ -0,0 +1,19 @@
function url_callback(params) {
}
function url_launch_filepicker(id, client_id, itemid) {
var picker = document.createElement('DIV');
picker.id = 'file-picker-'+client_id;
picker.className = 'file-picker';
document.body.appendChild(picker);
var el=document.getElementById(id);
var params = {};
params.env = 'texturl';
params.itemid = itemid;
params.maxbytes = -1;
params.maxfiles = -1;
params.savepath = '/';
params.target = el;
params.callback = url_callback;
var fp = open_filepicker(client_id, params);
return false;
}
+131
View File
@@ -0,0 +1,131 @@
<?php
require_once("HTML/QuickForm/text.php");
/**
* HTML class for a url type element
*
* @author Jamie Pratt
* @access public
*/
class MoodleQuickForm_url extends HTML_QuickForm_text{
/**
* html for help button, if empty then no help
*
* @var string
*/
var $_helpbutton='';
var $_hiddenLabel=false;
function MoodleQuickForm_url($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
$options = (array)$options;
foreach ($options as $name=>$value) {
$this->_options[$name] = $value;
}
parent::HTML_QuickForm_text($elementName, $elementLabel, $attributes);
repository_head_setup();
}
function setHiddenLabel($hiddenLabel){
$this->_hiddenLabel = $hiddenLabel;
}
function toHtml(){
global $CFG, $COURSE, $USER, $PAGE;
$id = $this->_attributes['id'];
$elname = $this->_attributes['name'];
if ($this->_hiddenLabel) {
$this->_generateId();
$str = '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
$this->getLabel().'</label>'.parent::toHtml();
} else {
$str = parent::toHtml();
}
if (!$CFG->repositoryusepickerbutton) {
return $str;
}
$strsaved = get_string('filesaved', 'repository');
$straddlink = get_string('choosealink', 'repository');
if ($COURSE->id == SITEID) {
$context = get_context_instance(CONTEXT_SYSTEM);
} else {
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
}
$client_id = uniqid();
$repojs = repository_get_client($context, $client_id, '*', 'link');
$PAGE->requires->js('lib/form/url.js');
$str .= $repojs;
$str .= <<<EOD
<button id="filepicker-btn-{$client_id}" style="display:none" onclick="return url_launch_filepicker('$id', '$client_id', 0)">$straddlink</button>
EOD;
// hide the button if javascript is not enabled
$str .= $PAGE->requires->js_function_call('show_item', array("filepicker-btn-{$client_id}"))->asap();
return $str;
}
/**
* Automatically generates and assigns an 'id' attribute for the element.
*
* Currently used to ensure that labels work on radio buttons and
* checkboxes. Per idea of Alexander Radivanovich.
* Overriden in moodleforms to remove qf_ prefix.
*
* @access private
* @return void
*/
function _generateId()
{
static $idx = 1;
if (!$this->getAttribute('id')) {
$this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
}
} // end func _generateId
/**
* set html for help button
*
* @access public
* @param array $help array of arguments to make a help button
* @param string $function function name to call to get html
*/
function setHelpButton($helpbuttonargs, $function='helpbutton'){
if (!is_array($helpbuttonargs)){
$helpbuttonargs=array($helpbuttonargs);
}else{
$helpbuttonargs=$helpbuttonargs;
}
//we do this to to return html instead of printing it
//without having to specify it in every call to make a button.
if ('helpbutton' == $function){
$defaultargs=array('', '', 'moodle', true, false, '', true);
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
}
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
}
/**
* get html for help button
*
* @access public
* @return string html for help button
*/
function getHelpButton(){
return $this->_helpbutton;
}
/**
* Slightly different container template when frozen. Don't want to use a label tag
* with a for attribute in that case for the element label but instead use a div.
* Templates are defined in renderer constructor.
*
* @return string
*/
function getElementTemplateType(){
if ($this->_flagFrozen){
return 'static';
} else {
return 'default';
}
}
}
+1 -1
View File
@@ -2240,6 +2240,6 @@ MoodleQuickForm::registerElementType('submitlink', "$CFG->libdir/form/submitlink
MoodleQuickForm::registerElementType('tags', "$CFG->libdir/form/tags.php", 'MoodleQuickForm_tags');
MoodleQuickForm::registerElementType('text', "$CFG->libdir/form/text.php", 'MoodleQuickForm_text');
MoodleQuickForm::registerElementType('textarea', "$CFG->libdir/form/textarea.php", 'MoodleQuickForm_textarea');
MoodleQuickForm::registerElementType('texturl', "$CFG->libdir/form/texturl.php", 'MoodleQuickForm_texturl');
MoodleQuickForm::registerElementType('url', "$CFG->libdir/form/url.php", 'MoodleQuickForm_url');
MoodleQuickForm::registerElementType('warning', "$CFG->libdir/form/warning.php", 'MoodleQuickForm_warning');
?>
+1 -1
View File
@@ -46,7 +46,7 @@ class mod_url_mod_form extends moodleform_mod {
//-------------------------------------------------------
$mform->addElement('header', 'content', get_string('contentheader', 'url'));
$mform->addElement('texturl', 'externalurl', get_string('externalurl', 'url'), array('size'=>'60'), null);
$mform->addElement('url', 'externalurl', get_string('externalurl', 'url'), array('size'=>'60'), null);
//-------------------------------------------------------
$mform->addElement('header', 'optionssection', get_string('optionsheader', 'url'));