]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19756 Added a shortcut method to moodle_html_components: add_confirm_action(...
authornicolasconnault <nicolasconnault>
Mon, 10 Aug 2009 07:31:31 +0000 (07:31 +0000)
committernicolasconnault <nicolasconnault>
Mon, 10 Aug 2009 07:31:31 +0000 (07:31 +0000)
lib/deprecatedlib.php
lib/outputcomponents.php

index 9f1b50ade5f36ed332ad540fcec524360ff652ac..1ae249389a97fb65bf704896a5735a392da1ba8d 100644 (file)
@@ -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);
index 933f3e80ae8c61e1a2e575155d21229407cdbee9..6113b09407a416d3be0eae211ceb1eb1321bc4a8 100644 (file)
@@ -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