From 724e7ee6ac2228ae697d1c6418370643e46b1a7a Mon Sep 17 00:00:00 2001 From: dongsheng Date: Wed, 7 Oct 2009 05:23:36 +0000 Subject: [PATCH] "MDL-20470, add a texturl element, which can use filepicker to choose a url" --- lang/en_utf8/repository.php | 1 + lib/form/texturl.js | 19 ++++++ lib/form/texturl.php | 128 ++++++++++++++++++++++++++++++++++++ lib/formslib.php | 1 + mod/url/mod_form.php | 4 +- 5 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 lib/form/texturl.js create mode 100755 lib/form/texturl.php diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index b1d38e742c..4a258fba1b 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -22,6 +22,7 @@ $string['cannotdelete'] = 'Cannot delete this file.'; $string['cannotdownload'] = 'Cannot download this file'; $string['cannotdownloaddir'] = 'Cannot download this folder'; $string['cannotinitplugin'] = 'Call plugin_init failed'; +$string['choosealink'] = 'Choose a link...'; $string['clicktohide'] = 'Click here to hide'; $string['clicktoshow'] = 'Click here to show'; $string['close'] = 'Close'; diff --git a/lib/form/texturl.js b/lib/form/texturl.js new file mode 100644 index 0000000000..84ee2112f5 --- /dev/null +++ b/lib/form/texturl.js @@ -0,0 +1,19 @@ +function texturl_callback(params) { +} +function texturl_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 = texturl_callback; + var fp = open_filepicker(client_id, params); + return false; +} diff --git a/lib/form/texturl.php b/lib/form/texturl.php new file mode 100755 index 0000000000..6ea41b1117 --- /dev/null +++ b/lib/form/texturl.php @@ -0,0 +1,128 @@ +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; + $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/texturl.js'); + + $id = $this->_attributes['id']; + $elname = $this->_attributes['name']; + + $str = $repojs; + if ($this->_hiddenLabel) { + $this->_generateId(); + $str .= ''.parent::toHtml(); + } else { + $str .= parent::toHtml(); + } + $str .= <<