}
$popupaction = new popup_action('click', $url, $name, $popupparams);
- $link->add_action_object($popupaction);
+ $link->add_action($popupaction);
// Call the output method
$output = $OUTPUT->link_to_popup($link);
}
$popupaction = new popup_action('click', $url, $name, $popupparams);
- $button->add_action_object($popupaction);
+ $button->add_action($popupaction);
$output = $OUTPUT->button($button);
if ($return) {
if ($jsconfirmmessage) {
$confirmaction = new component_action('click', 'confirm_dialog', array($jsconfirmmessage));
- $form->button->add_action_object($confirmaction);
+ $form->button->add_action($confirmaction);
}
$output = $OUTPUT->button($form);
if (!empty($target)) {
$popupaction = new popup_action('click', new moodle_url($target));
- $userpic->add_action_object($popupaction);
+ $userpic->add_action($popupaction);
}
$output = $OUTPUT->user_picture($userpic);
$formcontinue = new html_form();
$formcontinue->url = new moodle_url($linkyes, $optionsyes);
- $formcontinue->button = new html_button();
$formcontinue->button->label = get_string('yes');
$formcontinue->method = $methodyes;
$formcancel = new html_form();
$formcancel->url = new moodle_url($linkno, $optionsno);
- $formcancel->button = new html_button();
$formcancel->button->label = get_string('no');
$formcancel->method = $methodno;
$icon->prepare();
- $icon->link->add_action_object(new popup_action('click', $icon->link->url));
+ $popup = new popup_action('click', $icon->link->url);
+ $icon->link->add_action($popup);
$image = null;
$link = new html_link();
$link->url = $userpic->url;
$link->text = fullname($userpic->user);
- $link->add_action_object($actions[0]);
+ $link->add_action($actions[0]);
$output = $this->link_to_popup($link);
} else {
$output = $this->link(prepare_url($userpic->url), $output);
public function select_menu($selectmenu) {
$selectmenu = clone($selectmenu);
$selectmenu->prepare();
-
+
$this->prepare_event_handlers($selectmenu);
if ($selectmenu->nothinglabel) {
$attributes['multiple'] = 'multiple';
}
}
-
+
$html = '';
if (!empty($selectmenu->label)) {
/**
* Adds a JS action to this component.
* Note: the JS function you write must have only two arguments: (string)event and (object|array)args
- * If you want to add an instantiated component_action (or one of its subclasses), use $component->add_action_object($action)
+ * If you want to add an instantiated component_action (or one of its subclasses), give the object as the only parameter
*
* @param mixed $event a DOM event (click, mouseover etc.) or a component_action object
* @param string $jsfunction The name of the JS function to call. required if argument 1 is a string (event)
* @return void
*/
public function add_action($event, $jsfunction=null, $jsfunctionargs=array()) {
+ if (empty($this->id) || in_array($this->id, moodle_html_component::$generated_ids)) {
+ $this->generate_id();
+ }
+
if ($event instanceof component_action) {
$this->actions[] = $event;
} else {
if (empty($jsfunction)) {
throw new coding_exception('moodle_html_component::add_action requires a JS function argument if the first argument is a string event');
}
- while (empty($this->id) || !in_array($this->id, moodle_html_component::$generated_ids)) {
- $this->generate_id();
- }
$this->actions[] = new component_action($event, $jsfunction, $jsfunctionargs);
}
}
- /**
- * Adds an instantiated component_action to this component.
- * Note: the JS function you write must have only two arguments: (string)event and (object|array)args
- *
- * @param component_action $action An instantiated component_action or one of its subclasses
- * @return void
- */
- public function add_action_object($action) {
- if (!($action instanceof component_action)) {
- throw new coding_exception('moodle_html_component::add_action_object($action) only takes an instance of component_action.');
- }
-
- while (empty($this->id) && !in_array($this->id, moodle_html_component::$generated_ids)) {
- $this->generate_id();
- }
- $this->actions[] = $action;
- }
-
/**
* Internal method for generating a unique ID for the purpose of event handlers.
* @return void;
*/
protected function generate_id() {
- $this->id = get_class($this) . '-' . substr(sha1(microtime() * rand(0, 500)), 0, 5);
- if (!in_array($this->id, moodle_html_component::$generated_ids)) {
+ $this->id = get_class($this) . '-' . substr(sha1(microtime() * rand(0, 500)), 0, 6);
+ if (in_array($this->id, moodle_html_component::$generated_ids)) {
+ $this->generate_id();
+ } else {
moodle_html_component::$generated_ids[] = $this->id;
}
}
$this->add_class('userpicture');
- if (empty($this->image->src)) {
+ if (empty($this->image->src) && !empty($this->user->picture)) {
$this->image->src = $this->user->picture;
}
}
/**
- * Adds a html_list_item or html_list to this list.
+ * Adds a html_list_item or html_list to this list.
* If the param is a string, a html_list_item will be added.
* @param mixed $item String, html_list or html_list_item object
* @return void