$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');
$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) {
* @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();
}
* @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
*/
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
$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++;
}
}
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'));
$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(),
'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"));
+ }
}
// 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);
*/
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;
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);
}