]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19756 Improved the API for moodle_html_component::add_action to allow the first...
authornicolasconnault <nicolasconnault>
Tue, 28 Jul 2009 03:26:41 +0000 (03:26 +0000)
committernicolasconnault <nicolasconnault>
Tue, 28 Jul 2009 03:26:41 +0000 (03:26 +0000)
lib/outputlib.php

index 7694f13141fe8c0635084bb59fa18d840a39b511..4dddfee838097e0b7b13f0ef5e24f5e738f3fb72 100644 (file)
@@ -3261,16 +3261,23 @@ class moodle_html_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)
      *
-     * @param string $event a DOM event (click, mouseover etc.)
-     * @param string $jsfunction The name of the JS function to call
+     * @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)
      * @param array  $jsfunctionargs An optional array of JS arguments to pass to the function
      * @return void
      */
-    public function add_action($event, $jsfunction, $jsfunctionargs=array()) {
-        while (empty($this->id) || !in_array($this->id, moodle_html_component::$generated_ids)) {
-            $this->generate_id();
+    public function add_action($event, $jsfunction=null, $jsfunctionargs=array()) {
+        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);
         }
-        $this->actions[] = new component_action($event, $jsfunction, $jsfunctionargs);
     }
 
     /**
@@ -3394,6 +3401,9 @@ class moodle_select_menu extends moodle_html_component {
         if (empty($this->classes)) {
             $this->set_classes(array('menu' . str_replace(array('[', ']'), '', $this->name)));
         }
+        if (is_null($this->nothinglabel)) {
+            $this->nothinglabel = get_string('choosedots');
+        }
         $this->add_class('select');
         parent::prepare();
     }