From 1a03384f5edddc1996bae1e18e39f4ce0d51513c Mon Sep 17 00:00:00 2001 From: dongsheng Date: Tue, 13 Oct 2009 08:31:50 +0000 Subject: [PATCH] "MDL-20470, rename formslib element name and add an option to turn the picker button on/off" --- admin/settings/plugins.php | 1 + lang/en_utf8/repository.php | 1 + lib/form/url.js | 19 ++++++ lib/form/url.php | 131 ++++++++++++++++++++++++++++++++++++ lib/formslib.php | 2 +- mod/url/mod_form.php | 2 +- 6 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 lib/form/url.js create mode 100755 lib/form/url.php diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 0fd5a1c7f6..fd30e8239e 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -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), diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index 586236c07d..486a5f6187 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -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'; diff --git a/lib/form/url.js b/lib/form/url.js new file mode 100644 index 0000000000..b5aecf390c --- /dev/null +++ b/lib/form/url.js @@ -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; +} diff --git a/lib/form/url.php b/lib/form/url.php new file mode 100755 index 0000000000..a167e365ba --- /dev/null +++ b/lib/form/url.php @@ -0,0 +1,131 @@ +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 = ''.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 .= <<