MDL-26244 mod_date:added some logic show or hide the file picker button based on repository availability

This commit is contained in:
Andrew Davis 2013-10-08 13:59:16 +07:00
parent 4e47920f08
commit fa4fb78642
3 changed files with 15 additions and 15 deletions

View File

@ -79,7 +79,7 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
* @return string
*/
function toHtml(){
global $CFG, $COURSE, $USER, $PAGE, $OUTPUT;
global $PAGE, $OUTPUT;
$id = $this->_attributes['id'];
$elname = $this->_attributes['name'];
@ -94,20 +94,9 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
if (empty($this->_options['usefilepicker'])) {
return $str;
}
$strsaved = get_string('filesaved', 'repository');
$straddlink = get_string('choosealink', 'repository');
if ($COURSE->id == SITEID) {
$context = context_system::instance();
} else {
$context = context_course::instance($COURSE->id);
}
$client_id = uniqid();
$str .= <<<EOD
<button id="filepicker-button-{$client_id}" style="display:none">
$straddlink
</button>
EOD;
$args = new stdClass();
$args->accepted_types = '*';
$args->return_types = FILE_EXTERNAL;
@ -117,6 +106,15 @@ EOD;
$fp = new file_picker($args);
$options = $fp->options;
if (count($options->repositories) > 0) {
$straddlink = get_string('choosealink', 'repository');
$str .= <<<EOD
<button id="filepicker-button-{$client_id}" style="display:none">
$straddlink
</button>
EOD;
}
// print out file picker
$str .= $OUTPUT->render($fp);

View File

@ -62,7 +62,9 @@ class data_field_url extends data_field_base {
// Just the URL field
$str .= '<label class="accesshide" for="' . $fieldid . '">'. $this->field->name .'</label>';
$str .= '<input type="text" name="field_'.$this->field->id.'_0" id="'.$fieldid.'" value="'.s($url).'" size="60" />';
$str .= '<button id="filepicker-button-'.$options->client_id.'" style="display:none">'.$straddlink.'</button>';
if (count($options->repositories) > 0) {
$str .= '<button id="filepicker-button-'.$options->client_id.'" style="display:none">'.$straddlink.'</button>';
}
}
// print out file picker

View File

@ -23,7 +23,7 @@
* this.options.client_id, the instance id
* this.options.contextid
* this.options.itemid
* this.options.repositories, stores all repositories displaied in file picker
* this.options.repositories, stores all repositories displayed in file picker
* this.options.formcallback
*
* Active repository options