MDL-20204 fixed recent regressions + improved action handling - sorrrry
authorPetr Skoda <skodak@moodle.org>
Thu, 11 Feb 2010 15:44:06 +0000 (15:44 +0000)
committerPetr Skoda <skodak@moodle.org>
Thu, 11 Feb 2010 15:44:06 +0000 (15:44 +0000)
enrol/authorize/locallib.php
grade/edit/tree/index.php
grade/edit/tree/lib.php
lib/outputcomponents.php
lib/outputrenderers.php
mod/wiki/admin.php
mod/wiki/view.php

index 81e08bf..5355a69 100644 (file)
@@ -69,10 +69,9 @@ function authorize_print_orders($courseid, $userid) {
     $popupmenu .= $OUTPUT->single_select(new moodle_url($baseurl.'&course='.$courseid), 'status', $statusmenu, $status, null, 'statusmenu');
     if ($canmanagepayments) {
         $popupmenu .= '<br />';
-        $id = html_writer::random_id('ea');
         $PAGE->requires->js('/enrol/authorize/authorize.js');
-        $OUTPUT->add_action_handler($id, new component_action('click', 'authorize_jump_to_mypayments', array('userid' => $USER->id, 'status' => $status)));
-        $popupmenu .= html_writer::checkbox('enrol_authorize', 1, $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), array('id'=>$id));
+        $aid = $OUTPUT->add_action_handler(new component_action('click', 'authorize_jump_to_mypayments', array('userid' => $USER->id, 'status' => $status)));
+        $popupmenu .= html_writer::checkbox('enrol_authorize', 1, $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), array('id'=>$aid));
     }
 
     if (SITEID != $courseid) {
index b9d0448..092e3ac 100644 (file)
@@ -324,7 +324,7 @@ if (!$moving && count($grade_edit_tree->categories) > 1) {
     echo get_string('moveselectedto', 'grades') . ' ';
     $attributes = array('id'=>'menumoveafter');
     echo html_writer::select($grade_edit_tree->categories, 'moveafter', '', array(''=>'choosedots'), $attributes);
-    $PAGE->add_action_handler('menumoveafter', new component_action('change', 'submit_bulk_move'));
+    $OUTPUT->add_action_handler(new component_action('change', 'submit_bulk_move'), 'menumoveafter');
     echo '<div id="noscriptgradetreeform" class="hiddenifjs">
             <input type="submit" value="'.get_string('go').'" />
           </div>';
index 204814a..c9a8137 100755 (executable)
@@ -655,7 +655,7 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
             $attributes['id'] = 'aggregation_'.$category->id;
             $aggregation = html_writer::select($options, 'aggregation_'.$category->id, $category->aggregation, null, $attributes);
             $action = new component_action('change', 'update_category_aggregation', array('courseid' => $params['id'], 'category' => $category->id, 'sesskey' => sesskey()));
-            $PAGE->add_action_handler('aggregation_'.$category->id, $action);
+            $OUTPUT->add_action_handler($action, 'aggregation_'.$category->id);
         }
 
         $categorycell = clone($this->categorycell);
index 9e2a6a6..a9c2f56 100644 (file)
@@ -199,8 +199,8 @@ class pix_icon implements renderable {
      * @param array $attributes html attributes
      */
     public function __construct($pix, $alt, $component='moodle', array $attributes = null) {
-        $this->icon       = $pix;
-        $this->compondent = $component;
+        $this->pix        = $pix;
+        $this->component  = $component;
         $this->attributes = (array)$attributes;
 
         $this->attributes['alt'] = $alt;
index a63edbc..783d8be 100644 (file)
@@ -71,12 +71,16 @@ class renderer_base {
 
     /**
      * Adds JS handlers needed for event execution for one html element id
-     * @param string $id
      * @param component_action $actions
-     * @return void
+     * @param string $id
+     * @return string id of element, either original submitted or random new if not supplied
      */
-    public function add_action_handler($id, component_action $action) {
+    public function add_action_handler(component_action $action, $id=null) {
+        if (!$id) {
+            $id = html_writer::random_id($action->event);
+        }
         $this->page->requires->event_handler("#$id", $action->event, $action->jsfunction, $action->jsfunctionargs);
+        return $id;
     }
 
     /**
@@ -950,7 +954,7 @@ class core_renderer extends renderer_base {
                 $id = $attributes['id'];
             }
             foreach ($link->actions as $action) {
-                $this->add_action_handler($id, $action);
+                $this->add_action_handler($action, $id);
             }
         }
 
@@ -1034,7 +1038,7 @@ class core_renderer extends renderer_base {
             $id = html_writer::random_id('single_button');
             $attributes['id'] = $id;
             foreach ($button->actions as $action) {
-                $this->add_action_handler($id, $action);
+                $this->add_action_handler($action, $id);
             }
         }
 
@@ -1229,13 +1233,12 @@ class core_renderer extends renderer_base {
 
         $url = new moodle_url(get_docs_url($path));
 
-        $link = new html_link($url, $icon.$text);
-
+        $attributes = array('href'=>$url);
         if (!empty($CFG->doctonewwindow)) {
-            $link->add_action(new popup_action('click', $url));
+            $attributes['id'] = $this->add_action_handler(new popup_action('click', $url));
         }
-
-        return $this->link($link);
+        
+        return html_writer::tag('a', $attributes, $icon.$text);
     }
 
     /**
@@ -1256,10 +1259,10 @@ class core_renderer extends renderer_base {
      * @param pix_icon $icon
      * @return string HTML fragment
      */
-    public function render_icon(pix_icon $icon) {
+    public function render_pix_icon(pix_icon $icon) {
         $attributes = $icon->attributes;
         $attributes['src'] = $this->pix_url($icon->pix, $icon->component);
-        return html_writer::empty_tag('img', $atrributes);
+        return html_writer::empty_tag('img', $attributes);
     }
 
     /**
@@ -1384,7 +1387,7 @@ class core_renderer extends renderer_base {
         $attributes = array('href'=>$url, 'title'=>$title);
         $id = html_writer::random_id('helpicon');
         $attributes['id'] = $id;
-        $this->add_action_handler($id, new popup_action('click', $url));
+        $this->add_action_handler(new popup_action('click', $url), $id);
         $output = html_writer::tag('a', $attributes, $output);
 
         // and finally span
@@ -1594,7 +1597,7 @@ class core_renderer extends renderer_base {
         if ($userpicture->popup) {
             $id = html_writer::random_id('userpicture');
             $attributes['id'] = $id;
-            $this->add_action_handler($id, new popup_action('click', $url));
+            $this->add_action_handler(new popup_action('click', $url), $id);
         }
 
         return html_writer::tag('a', $attributes, $output);
index ae9013d..1be7801 100644 (file)
         while(list($key,$val)=each($wiki_list)) {
           $wiki_admin_list[$key."&amp;action=$action"]=$val;
         }
-        $attributes = array('id'=>'changeid');
+        $aid = $OUTPUT->add_action_handler(new component_action('change', 'go_to_wiki'));
+        $attributes = array('id'=>$aid);
         echo html_writer::select($wiki_admin_list, 'wikiselect', $selected, array(''=>'choose'), $attributes);
-        $PAGE->add_action_handler('changeid', new component_action('change', 'go_to_wiki'));
         echo '</td>';
         echo '</tr></table>';
         echo '</fieldset></form>';
index 5a7da29..1f69de4 100644 (file)
 
         echo '<td class="sideblockheading">'
             .get_string('otherwikis', 'wiki').':&nbsp;&nbsp;';
-        $attributes = array('id'=>'changeid');
+        $aid = $OUTPUT->add_action_handler(new component_action('change', 'go_to_wiki'));
+        $attributes = array('id'=>$aid);
         echo html_writer::select($wiki_list, 'wikiselect', $selected, array(''=>'choose'), $attributes);
-        $PAGE->add_action_handler('changeid', new component_action('change', 'go_to_wiki'));
         echo '</td>';
         echo '</tr></table>';
         echo '</form>';