From: nicolasconnault Date: Mon, 10 Aug 2009 07:31:31 +0000 (+0000) Subject: MDL-19756 Added a shortcut method to moodle_html_components: add_confirm_action(... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e6fcbe276d3e868f4c0b9dc5c87bc3e736b515e6;p=moodle.git MDL-19756 Added a shortcut method to moodle_html_components: add_confirm_action($message). This adds the appropriate onclick event handler for a confirmation message and can be used on any component that gets prepared properly by a renderer function. --- diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 9f1b50ade5..1ae249389a 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2595,8 +2595,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus $form->id = $formid; if ($jsconfirmmessage) { - $confirmaction = new component_action('click', 'confirm_dialog', array('message' => $jsconfirmmessage)); - $form->button->add_action($confirmaction); + $form->button->add_confirm_action($jsconfirmmessage); } $output = $OUTPUT->button($form); diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 933f3e80ae..6113b09407 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -220,6 +220,16 @@ class moodle_html_component { $this->label->text = $text; } } + + /** + * Shortcut for adding a JS confirm dialog when the component is clicked. + * The message must be a yes/no question. + * @param string $message The yes/no confirmation question. If "Yes" is clicked, the original action will occur. + * @return void + */ + public function add_confirm_action($message) { + $this->add_action(new component_action('click', 'confirm_dialog', array('message' => $message))); + } } /// Components representing HTML elements