From: jamiesensei Date: Tue, 26 Sep 2006 09:42:42 +0000 (+0000) Subject: * added error message for setHelpButton method not existing X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=80f962df90c6bc1c0804b4d197de41d789c7f4ba;p=moodle.git * added error message for setHelpButton method not existing * modified htmleditor class so that differences in formatting for this element are defined by css but use the same html * added type name of element classes to css wrapper class names --- diff --git a/course/edit2.php b/course/edit2.php index ec6ac863ae..8cfa2160e7 100644 --- a/course/edit2.php +++ b/course/edit2.php @@ -292,7 +292,7 @@ print_heading($streditcoursesettings); $mform->display(); - + print_footer($course); ?> diff --git a/course/edit_form.php b/course/edit_form.php index 12eb8337a1..9c596355f1 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -213,7 +213,7 @@ }else { $mform->addElement('hidden', 'restrictmodules', $default->restrictmodules); } - $mform->add_help_buttons(array('category'=>array("coursecategory", get_string("category")), + $mform->addHelpButtons(array('category'=>array("coursecategory", get_string("category")), 'fullname'=>array("coursefullname", get_string("fullname")), 'shortname'=>array("courseshortname", get_string("shortname")), 'idnumber'=>array("courseidnumber", get_string("idnumbercourse")), diff --git a/lang/en_utf8/form.php b/lang/en_utf8/form.php index ecaebdfa70..7b1754790b 100644 --- a/lang/en_utf8/form.php +++ b/lang/en_utf8/form.php @@ -2,4 +2,5 @@ $string['denotesreq']='$a denotes required field.'; $string['requiredelement']='Required field.'; $string['nonexistentformelements']='Trying to add help buttons to nonexistent form elements : $a'; +$string['nomethodforaddinghelpbutton']='There is no method for adding a help button to form element $a->name (class $a->classname)'; ?> \ No newline at end of file diff --git a/lib/form/htmleditor.php b/lib/form/htmleditor.php index 5882cf4316..7630f5b76b 100644 --- a/lib/form/htmleditor.php +++ b/lib/form/htmleditor.php @@ -9,26 +9,31 @@ require_once("$CFG->libdir/form/textarea.php"); * @access public */ class moodleform_htmleditor extends moodleform_textarea{ - var $_type = 'htmleditor'; + var $_type; var $_elementTemplateType='default'; var $_canUseHtmlEditor; var $_options=array('course'=>0); function moodleform_htmleditor($elementName=null, $elementLabel=null, $attributes=null){ + parent::moodleform_textarea($elementName, $elementLabel, $attributes); $this->_canUseHtmlEditor=can_use_html_editor(); if ($this->_canUseHtmlEditor){ - $this->_elementTemplateType='wide'; + $this->_type='htmleditor'; + //$this->_elementTemplateType='wide'; }else{ - $this->_elementTemplateType='default'; + $this->_type='textarea'; } - parent::moodleform_textarea($elementName, $elementLabel, $attributes); } function getElementTemplateType(){ return $this->_elementTemplateType; } function toHtml(){ - ob_start(); - use_html_editor($this->getName()); - $script=ob_get_clean(); + if ($this->_canUseHtmlEditor){ + ob_start(); + use_html_editor($this->getName()); + $script=ob_get_clean(); + } else { + $script=''; + } if ($this->_flagFrozen) { return $this->getFrozenHtml(); } else { diff --git a/lib/formslib.php b/lib/formslib.php index c9b7016447..cd020988cf 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -91,7 +91,7 @@ class moodleform extends HTML_QuickForm_DHTMLRulesTableless{ if (!empty($oldclass)){ $this->updateAttributes(array('class'=>$oldclass.' mform')); }else { - $this->updateAttributes(array('class'=>'mform')); + $this->updateAttributes(array('class'=>'mform')); } $this->_helpImageURL="$CFG->wwwroot/lib/form/req.gif"; $this->_reqHTML = @@ -110,14 +110,19 @@ class moodleform extends HTML_QuickForm_DHTMLRulesTableless{ * * @access public */ - function add_help_buttons($buttons, $suppresscheck=false){ + function addHelpButtons($buttons, $suppresscheck=false){ foreach ($this->_elements as $no => $element){ if (array_key_exists($element->getName(), $buttons)){ - //dynamically create a property so we don't have to modify element - //class : - $this->_elements[$no]->setHelpButton($buttons[$element->getName()]); + if (method_exists($element, 'setHelpButton')){ + $this->_elements[$no]->setHelpButton($buttons[$element->getName()]); + }else{ + $a=new object(); + $a->name=$element->getName(); + $a->classname=get_class($element); + print_error('nomethodforaddinghelpbutton', 'form', '', $a); + } unset($buttons[$element->getName()]); } @@ -178,8 +183,8 @@ class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ var $_elementTemplates; var $_htmleditors=array(); function moodleform_renderer(){ - $this->_elementTemplates=array('default'=>"\n\t\t
error\">{error}
{element}
", - 'wide'=>"\n\t\t

error\">{error}
{element}
"); + $this->_elementTemplates=array('default'=>"\n\t\t
error {type}\">{error}
{element}
", + 'wide'=>"\n\t\t

error {type}\">{error}
{element}
"); parent::HTML_QuickForm_Renderer_Tableless(); } @@ -201,6 +206,8 @@ class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ $html =str_replace('{help}', '', $html); } + $html =str_replace('{type}', 'group', $html); + $this->_templates[$group->getName()]=$html; // Fix for bug in tableless quickforms that didn't allow you to stop a // fieldset before a group of elements. @@ -220,6 +227,7 @@ class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ $html = $this->_elementTemplates['default']; } + $html =str_replace('{type}', $element->getType(), $html); if (method_exists($element, 'getHelpButton')){ $html=str_replace('{help}', $element->getHelpButton(), $html); }else{ diff --git a/theme/standard/styles_form.css b/theme/standard/styles_form.css index 3f7118991a..3d97010d00 100644 --- a/theme/standard/styles_form.css +++ b/theme/standard/styles_form.css @@ -41,6 +41,7 @@ form.mform textarea { form.mform br { clear: left; } + form.mform div.qfelement { display: inline; float: left; @@ -48,10 +49,14 @@ form.mform div.qfelement { padding: 0; } -form.mform div.qfelementwide { - margin: 0 10% 10px 10%; +form.mform div.htmleditor { + margin: 0 auto 10px auto; + width : 600px; + clear:both; + float:none; } + form.mform span.error, form.mform span.required { color: red; } @@ -59,4 +64,7 @@ form.mform div.error { border: 1px solid red; padding: 5px; color: inherit; +} +form.mform div.qfrow { + clear:both; } \ No newline at end of file