MDL-15405: A first form (partly) converted to the new filepicker element.

This commit is contained in:
scyrma 2008-08-27 07:57:54 +00:00
parent 535f6e60e1
commit 4302300219
2 changed files with 10 additions and 4 deletions

View File

@ -14,7 +14,13 @@ require_once(dirname(dirname(dirname(__FILE__))) . '/repository/lib.php');
*/
class MoodleQuickForm_filepicker extends HTML_QuickForm_button
{
var $_filearea;
var $_helpbutton='';
function MoodleQuickForm_filepicker($elementName=null, $value=null, $filearea=null, $attributes=null) {
parent::HTML_QuickForm_button($elementName, $value, $attributes);
$this->_filearea = $filearea;
}
function setHelpButton($helpbuttonargs, $function='helpbutton'){
if (!is_array($helpbuttonargs)){
$helpbuttonargs=array($helpbuttonargs);
@ -55,6 +61,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_button
$str = $this->_getTabs();
$str .= '<input type="hidden" value="" name="'.$this->_attributes['name'].'" id="'.$this->_attributes['id'].'_'.$suffix.'" />';
$id = $this->_attributes['id'];
$filearea = $this->_filearea;
$str .= <<<EOD
<script type="text/javascript">
function updatefile_$suffix(){
@ -66,11 +73,12 @@ function callpicker_$suffix(){
picker.id = 'file-picker-$suffix';
document.body.appendChild(picker);
var el=document.getElementById('${id}_${suffix}');
openpicker_$suffix({"env":"form", 'target':el, 'callback':updatefile_$suffix})
openpicker_$suffix({"env":"form", 'target':el, 'callback':updatefile_$suffix, 'filearea':${filearea}})
}
</script>
EOD;
// $this->_getAttrString($this->_attributes);
$str .= "<input name=\"filearea\" value=\"$filearea\" type=\"hidden\">\n";
$str .= '<input value ="'.get_string('openpicker', 'repository').'" type="button" onclick=\'callpicker_'.$suffix.'()\' />'.'<span id="repo_info_'.$suffix.'" style="color:green"></span>'.$ret['css'].$ret['js'];
return $str;
}

View File

@ -16,7 +16,6 @@ class mod_forum_post_form extends moodleform {
$forum = $this->_customdata['forum'];
$post = $this->_customdata['post']; // hack alert
$mform->addElement('header', 'general', '');//fill in the data depending on page params
//later using set_data
$mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
@ -54,9 +53,8 @@ class mod_forum_post_form extends moodleform {
}
if ($forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all
$mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
$mform->addElement('filepicker', 'attachment', get_string('attachment', 'forum'), 'forum_submission');
$mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'forum'), 'forum'));
}
if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) { // hack alert