From: nicolasconnault Date: Tue, 28 Jul 2009 09:37:14 +0000 (+0000) Subject: MDL-19756 Removed redundant component::add_action_object() function and calls to it X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3f9a45dffaead2d845dae5c9cb30792b821e0948;p=moodle.git MDL-19756 Removed redundant component::add_action_object() function and calls to it --- diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index bba4202d42..56bacd7513 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2438,7 +2438,7 @@ function link_to_popup_window ($url, $name=null, $linkname=null, } $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); @@ -2518,7 +2518,7 @@ function button_to_popup_window ($url, $name=null, $linkname=null, } $popupaction = new popup_action('click', $url, $name, $popupparams); - $button->add_action_object($popupaction); + $button->add_action($popupaction); $output = $OUTPUT->button($button); if ($return) { @@ -2564,7 +2564,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus 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); @@ -2657,7 +2657,7 @@ function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=fa 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); @@ -2958,13 +2958,11 @@ function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno= $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; diff --git a/lib/outputlib.php b/lib/outputlib.php index 51eb76442b..17af8daac9 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -2550,7 +2550,8 @@ class moodle_core_renderer extends moodle_renderer_base { $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; @@ -2690,7 +2691,7 @@ class moodle_core_renderer extends moodle_renderer_base { $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); @@ -2759,7 +2760,7 @@ class moodle_core_renderer extends moodle_renderer_base { public function select_menu($selectmenu) { $selectmenu = clone($selectmenu); $selectmenu->prepare(); - + $this->prepare_event_handlers($selectmenu); if ($selectmenu->nothinglabel) { @@ -2794,7 +2795,7 @@ class moodle_core_renderer extends moodle_renderer_base { $attributes['multiple'] = 'multiple'; } } - + $html = ''; if (!empty($selectmenu->label)) { @@ -3281,7 +3282,7 @@ class moodle_html_component { /** * 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) @@ -3289,44 +3290,29 @@ class moodle_html_component { * @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; } } @@ -4146,7 +4132,7 @@ class user_picture extends moodle_html_component { $this->add_class('userpicture'); - if (empty($this->image->src)) { + if (empty($this->image->src) && !empty($this->user->picture)) { $this->image->src = $this->user->picture; } @@ -4482,7 +4468,7 @@ class html_list extends moodle_html_component { } /** - * 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