Permalink
Browse files

* 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
  • Loading branch information...
jamiesensei
jamiesensei committed Sep 26, 2006
1 parent 51d59bb commit 80f962df90c6bc1c0804b4d197de41d789c7f4ba
Showing with 40 additions and 18 deletions.
  1. +1 −1 course/edit2.php
  2. +1 −1 course/edit_form.php
  3. +1 −0 lang/en_utf8/form.php
  4. +12 −7 lib/form/htmleditor.php
  5. +15 −7 lib/formslib.php
  6. +10 −2 theme/standard/styles_form.css
View
@@ -292,7 +292,7 @@
print_heading($streditcoursesettings);
$mform->display();
-
+
print_footer($course);
?>
View
@@ -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")),
View
@@ -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)';
?>
View
@@ -9,26 +9,31 @@
* @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 {
View
@@ -91,7 +91,7 @@ function moodleform($formName='', $method='post', $action='', $target='', $attri
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 @@ function getReqHTML(){
*
* @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<div class=\"qfrow\"><label class=\"qflabel\">{label}{help}<!-- BEGIN required -->{req}<!-- END required --></label><div class=\"qfelement<!-- BEGIN error --> error<!-- END error -->\"><!-- BEGIN error --><span class=\"error\">{error}</span><br /><!-- END error -->{element}</div></div>",
- 'wide'=>"\n\t\t<div class=\"qfrow\"><label class=\"qflabel\">{label}{help}<!-- BEGIN required -->{req}<!-- END required --></label><br /><div class=\"qfelementwide<!-- BEGIN error --> error<!-- END error -->\"><!-- BEGIN error --><span class=\"error\">{error}</span><br /><!-- END error -->{element}</span></div>");
+ $this->_elementTemplates=array('default'=>"\n\t\t<div class=\"qfrow\"><label class=\"qflabel\">{label}{help}<!-- BEGIN required -->{req}<!-- END required --></label><div class=\"qfelement<!-- BEGIN error --> error<!-- END error --> {type}\"><!-- BEGIN error --><span class=\"error\">{error}</span><br /><!-- END error -->{element}</div></div>",
+ 'wide'=>"\n\t\t<div class=\"qfrow\"><label class=\"qflabel\">{label}{help}<!-- BEGIN required -->{req}<!-- END required --></label><br /><div class=\"qfelementwide<!-- BEGIN error --> error<!-- END error --> {type}\"><!-- BEGIN error --><span class=\"error\">{error}</span><br /><!-- END error -->{element}</span></div>");
parent::HTML_QuickForm_Renderer_Tableless();
}
@@ -201,6 +206,8 @@ function startGroup(&$group, $required, $error){
$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 @@ function renderElement(&$element, $required, $error){
$html = $this->_elementTemplates['default'];
}
+ $html =str_replace('{type}', $element->getType(), $html);
if (method_exists($element, 'getHelpButton')){
$html=str_replace('{help}', $element->getHelpButton(), $html);
}else{
@@ -41,22 +41,30 @@ form.mform textarea {
form.mform br {
clear: left;
}
+
form.mform div.qfelement {
display: inline;
float: left;
margin: 5px 0 0 10px;
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;
}
form.mform div.error {
border: 1px solid red;
padding: 5px;
color: inherit;
+}
+form.mform div.qfrow {
+ clear:both;
}

0 comments on commit 80f962d

Please sign in to comment.