From b65bfc3e70f10c01d7ab7ca424066187e5346cf4 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Fri, 14 Aug 2009 03:16:23 +0000 Subject: [PATCH] MDL-19756 Fixed a number of small API issues in components and renderers --- lib/outputcomponents.php | 31 ++++++++++++++++++++++++------- lib/outputrenderers.php | 31 ++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 0913466a72..07c515a1bb 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -536,6 +536,7 @@ class html_select extends labelled_html_component { $select->form = new html_form(); $select->form->id = $formid; $select->form->method = 'get'; + $select->form->jssubmitaction = true; $select->form->add_class('popupform'); $select->form->url = new moodle_url($CFG->wwwroot . '/course/jumpto.php', array('sesskey' => sesskey())); $select->form->button->text = get_string('go'); @@ -1242,7 +1243,7 @@ class html_button extends labelled_html_component { $this->add_class('singlebutton'); if (empty($this->text)) { - throw new coding_exception('A html_button must have a text value!'); + $this->text = get_string('submit'); } if ($this->disabled) { @@ -1275,6 +1276,10 @@ class html_image extends labelled_html_component { * @return void */ public function prepare() { + if (empty($this->src)) { + throw new coding_exception('html_image requires a $src value (moodle_url).'); + } + $this->add_class('image'); parent::prepare(); } @@ -1365,7 +1370,10 @@ class html_form extends moodle_html_component { * @var html_button $button A submit button */ public $button; - + /** + * @var boolean $jssubmitaction If true, the submit button will be hidden when JS is enabled + */ + public $jssubmitaction = false; /** * Constructor: sets up the other components in case they are needed * @return void @@ -1423,6 +1431,11 @@ class html_list extends moodle_html_component { */ public $type = 'unordered'; + /** + * @var string $text An optional descriptive text for the list. Will be output as a list item before opening the new list + */ + public $text = false; + /** * @see lib/moodle_html_component#prepare() * @return void @@ -1443,17 +1456,21 @@ class html_list extends moodle_html_component { $this->add_class("list-$level"); + $i = 1; foreach ($tree as $key => $element) { if (is_array($element)) { $newhtmllist = new html_list(); + $newhtmllist->type = $this->type; $newhtmllist->load_data($element, $level + 1); + $newhtmllist->text = $key; $this->items[] = $newhtmllist; } else { $listitem = new html_list_item(); $listitem->value = $element; - $listitem->add_class("list-item-$level-$key"); + $listitem->add_class("list-item-$level-$i"); $this->items[] = $listitem; } + $i++; } } @@ -1868,12 +1885,12 @@ class moodle_help_icon extends labelled_html_component { throw new coding_exception('A moodle_help_icon object requires a $page parameter'); } - if (empty($this->text)) { - throw new coding_exception('A moodle_help_icon object requires a $text parameter'); + if (empty($this->text) && empty($this->link->text)) { + throw new coding_exception('A moodle_help_icon object (or its $link attribute) requires a $text parameter'); + } else if (!empty($this->text) && empty($this->link->text)) { + $this->link->text = $this->text; } - $this->link->text = $this->text; - // fix for MDL-7734 $this->link->url = new moodle_url('/help.php', array('module' => $this->module, 'file' => $this->page .'.html')); diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 06aaba42a2..05ec985ba8 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1178,7 +1178,6 @@ class moodle_core_renderer extends moodle_renderer_base { $contents = $this->output_empty_tag('input', array('type' => 'submit', 'value' => get_string('ok'))); } else if (!empty($form->button)) { $form->button->prepare(); - $buttonoutput = $this->output_start_tag('div', array('id' => "noscript$form->id")); $this->prepare_event_handlers($form->button); $buttonattributes = array('class' => $form->button->get_classes_string(), @@ -1187,9 +1186,13 @@ class moodle_core_renderer extends moodle_renderer_base { 'disabled' => $form->button->disabled, 'id' => $form->button->id); - $buttonoutput .= $this->output_empty_tag('input', $buttonattributes); - $buttonoutput .= $this->output_end_tag('div'); - $this->page->requires->js_function_call('hide_item', array("noscript$form->id")); + $buttonoutput = $this->output_empty_tag('input', $buttonattributes); + + // Hide the submit button if the button has a JS submit action + if ($form->jssubmitaction) { + $buttonoutput = $this->output_start_tag('div', array('id' => "noscript$form->id")) . $buttonoutput . $this->output_end_tag('div'); + $this->page->requires->js_function_call('hide_item', array("noscript$form->id")); + } } @@ -1330,8 +1333,9 @@ class moodle_core_renderer extends moodle_renderer_base { // Use image if one is given if (!empty($image) && $image instanceof html_image) { - if (empty($image->alt)) { + if (empty($image->alt) || $image->alt == HTML_ATTR_EMPTY) { $image->alt = $link->text; + $image->title = $link->text; } $link->text = $this->image($image); @@ -1353,13 +1357,14 @@ class moodle_core_renderer extends moodle_renderer_base { */ public function spacer($image) { $image = clone($image); - $image->prepare(); - $image->add_class('spacer'); if (empty($image->src)) { $image->src = $this->old_icon_url('spacer'); } + $image->prepare(); + $image->add_class('spacer'); + $output = $this->image($image); return $output; @@ -1524,16 +1529,20 @@ class moodle_core_renderer extends moodle_renderer_base { foreach ($list->items as $listitem) { if ($listitem instanceof html_list) { - $output .= $this->output_start_tag('li', array()); - $output .= $this->htmllist($listitem); - $output .= $this->output_end_tag('li'); + $output .= $this->output_start_tag('li', array()) . "\n"; + $output .= $this->htmllist($listitem) . "\n"; + $output .= $this->output_end_tag('li') . "\n"; } else if ($listitem instanceof html_list_item) { $listitem->prepare(); $this->prepare_event_handlers($listitem); - $output .= $this->output_tag('li', array('class' => $listitem->get_classes_string()), $listitem->value); + $output .= $this->output_tag('li', array('class' => $listitem->get_classes_string()), $listitem->value) . "\n"; } } + if ($list->text) { + $output = $list->text . $output; + } + return $output . $this->output_end_tag($tag); } -- 2.39.5