]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19756 Improved API of OUTPUT->confirm()
authornicolasconnault <nicolasconnault>
Thu, 30 Jul 2009 06:09:45 +0000 (06:09 +0000)
committernicolasconnault <nicolasconnault>
Thu, 30 Jul 2009 06:09:45 +0000 (06:09 +0000)
admin/index.php
course/lib.php
course/view.php
lib/deprecatedlib.php
lib/outputlib.php

index 079decdc526944e4b73542e198d5332065b4cb3b..435db0bca6c61b4352cadd6e3359669af271d526 100644 (file)
@@ -189,13 +189,7 @@ if ($version > $CFG->version) {  // upgrade
     if (empty($confirmupgrade)) {
         $navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc')));
         print_header($strdatabasechecking, $stradministration, $navigation, '', '', false, '&nbsp;', '&nbsp;');
-        $formcontinue = new html_form();
-        $formcontinue->button->label = get_string('yes');
-        $formcontinue->url = new moodle_url('index.php', array('confirmupgrade' => 1));
-        $formcancel = new html_form();
-        $formcancel->url = new moodle_url('index.php');
-        echo $OUTPUT->confirm(get_string('upgradesure', 'admin', $a->newversion), $formcontinue, $formcancel);
-
+        echo $OUTPUT->confirm(get_string('upgradesure', 'admin', $a->newversion), new moodle_url('index.php', array('confirmupgrade' => 1)), 'index.php');
         print_footer();
         exit;
 
index 95a925eae79cb38a6c4457e1fb0424c43fa48065..7257c2754928e0b4f8e86366badb334121b9c855 100644 (file)
@@ -1598,13 +1598,13 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
     }
 
     if (!empty($resources)) {
-        $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&amp;sesskey=".sesskey()."&amp;add=",
+        $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=".sesskey()."&add=",
                               $resources, "ressection$section", "", $straddresource, 'resource/types', $straddresource, true);
     }
 
     if (!empty($activities)) {
         $output .= ' ';
-        $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&amp;sesskey=".sesskey()."&amp;add=",
+        $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=".sesskey()."&add=",
                     $activities, "section$section", "", $straddactivity, 'mods', $straddactivity, true);
     }
 
index afb98374097b3835b54fad5e4ead9a1d93fcac59..735f16c5c9415b2f21db84040d4637f856a098de 100644 (file)
     // Content wrapper end.
     echo "</div>\n\n";
 
-
+    $image = new html_image();
+    $image->src = $OUTPUT->old_icon_url('help');
+    $image->add_action('click', 'confirm_dialog', array('message' => 'Are you sure?'));
+    echo $OUTPUT->image($image);
     // Use AJAX?
     if ($useajax && has_capability('moodle/course:manageactivities', $context)) {
         // At the bottom because we want to process sections and activities
index 5783d6dce9a839ec39a5a4e3a193c55e13a1597f..bf5dc87fb8460ad13a2ace4e94a1a3017656ff69 100644 (file)
@@ -2070,6 +2070,8 @@ function notify($message, $classes = 'notifyproblem', $align = 'center', $return
 /**
  * Print a continue button that goes to a particular URL.
  *
+ * @deprecated since Moodle 2.0
+ *
  * @param string $link The url to create a link to.
  * @param bool $return If set to true output is returned rather than echoed, default false
  * @return string|void HTML String if return=true nothing otherwise
@@ -2098,6 +2100,8 @@ function print_continue($link, $return = false) {
  * Returns a string containing a link to the user documentation for the current
  * page. Also contains an icon by default. Shown to teachers and admin only.
  *
+ * @deprecated since Moodle 2.0
+ *
  * @global object
  * @global object
  * @param string $text The text to be displayed for the link
@@ -3310,8 +3314,6 @@ function print_date_selector($day, $month, $year, $currenttime=0, $return=false)
  * submits the form (while avoiding the usual acessibility problems with this appoach).
  * With JavaScript off, a 'Go' button is printed.
  *
- * @todo Finish documenting this function
- *
  * @global object
  * @global object
  * @param string $baseurl The target URL up to the point of the variable that changes
@@ -3359,18 +3361,8 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose'
         $selectmenu->nothinglabel = $nothing;
     }
 
-    if ($selectlabel) {
-        $selectmenu->label = new html_label();
-        $selectmenu->label->text = $selectlabel;
-        $selectmenu->label->for = $selectmenu->id;
-    }
-
-    if ($help) {
-        $selectmenu->helpicon = new help_icon();
-        $selectmenu->helpicon->page = $help;
-        $selectmenu->helpicon->text = $helptext;
-        $selectmenu->helpicon->linktext = false;
-    }
+    $selectmenu->set_label($selectlabel, $selectmenu->id);
+    $selectmenu->set_help_icon($help, $helptext);
 
     $output = $OUTPUT->select_menu($selectmenu);
 
index 227bad67317f41dc71c793d312f6675b2518df83..a9a441a803795adff8ac59aef2e385d026ef887f 100644 (file)
@@ -318,9 +318,9 @@ class theme_config {
      */
     public $layouts = array();
 
-    /* 
+    /*
      * Time in seconds to cache the CSS style sheets for the chosen theme
-     * 
+     *
      * @var integer
      */
     public $csslifetime = 1800;
@@ -2436,16 +2436,25 @@ class moodle_core_renderer extends moodle_renderer_base {
             $continueform = new html_form();
             $continueform->url = new moodle_url($continue);
             $continue = $continueform;
-        } else if (!is_object($continue)) {
-            throw new coding_exception('The 2nd param to $OUTPUT->confirm must be either a URL (string/moodle_url) or a html_form object.');
+        } else if ($continue instanceof moodle_url) {
+            $continueform = new html_form();
+            $continueform->url = $continue;
+            $continue = $continueform;
+        } else {
+            throw new coding_exception('The continue param to $OUTPUT->confirm must be either a URL (string/moodle_url) or a html_form object.');
+
         }
 
         if (!($cancel instanceof html_form) && !is_object($cancel)) {
             $cancelform = new html_form();
             $cancelform->url = new moodle_url($cancel);
             $cancel = $cancelform;
-        } else if (!is_object($cancel)) {
-            throw new coding_exception('The 3rd param to $OUTPUT->confirm must be either a URL (string/moodle_url) or a html_form object.');
+        } else if ($cancel instanceof moodle_url) {
+            $cancelform = new html_form();
+            $cancelform->url = $cancel;
+            $cancel = $cancelform;
+        } else {
+            throw new coding_exception('The cancel param to $OUTPUT->confirm must be either a URL (string/moodle_url) or a html_form object.');
         }
 
         if (empty($continue->button->text)) {
@@ -2640,11 +2649,14 @@ class moodle_core_renderer extends moodle_renderer_base {
     public function image($image) {
         $image->prepare();
 
+        $this->prepare_event_handlers($image);
+
         $attributes = array('class' => $image->get_classes_string(),
                             'style' => $this->prepare_legacy_width_and_height($image),
                             'src' => prepare_url($image->src),
                             'alt' => $image->alt,
-                            'title' => $image->title);
+                            'title' => $image->title,
+                            'id' => $image->id);
 
         return $this->output_empty_tag('img', $attributes);
     }
@@ -2753,6 +2765,20 @@ class moodle_core_renderer extends moodle_renderer_base {
     /**
      * Output a <select> menu.
      *
+     * This method is extremely versatile, and can be used to output yes/no menus,
+     * form-enclosed menus with automatic redirects when an option is selected,
+     * descriptive labels and help icons. By default it just outputs a select
+     * menu.
+     *
+     * To add a descriptive label, use moodle_select_menu::set_label($text, $for) or
+     * moodle_select_menu::set_label($label) passing a html_label object
+     *
+     * To add a help icon, use moodle_select_menu::set_help($page, $text, $linktext) or
+     * moodle_select_menu::set_help($helpicon) passing a help_icon object
+     *
+     * To surround the menu with a form, simply set moodle_select_menu->form as a
+     * valid html_form object.
+     *
      * You can either call this function with a single moodle_select_menu argument
      * or, with a list of parameters, in which case those parameters are sent to
      * the moodle_select_menu constructor.
@@ -3457,7 +3483,7 @@ class moodle_select_menu extends moodle_html_component {
      */
     public function prepare() {
         global $CFG;
-        
+
         // name may contain [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading
         if (empty($this->id)) {
             $this->id = 'menu' . str_replace(array('[', ']'), '', $this->name);
@@ -3698,6 +3724,71 @@ class moodle_select_menu extends moodle_html_component {
 
         return $selectmenu;
     }
+
+    /**
+     * Adds a descriptive label to the select menu.
+     *
+     * This can be used in two ways:
+     *
+     * <pre>
+     * $selectmenu->set_label($elementid, $elementlabel);
+     * // OR
+     * $label = new html_label();
+     * $label->for = $elementid;
+     * $label->text = $elementlabel;
+     * $selectmenu->set_label($label);
+     * </pre>
+     *
+     * Use the second form when you need to add additional HTML attributes
+     * to the label and/or JS actions.
+     *
+     * @param mixed $text Either the text of the label or a html_label object
+     * @param text  $for The value of the "for" attribute (the associated element's id)
+     * @return void
+     */
+    public function set_label($text, $for=null) {
+        if ($text instanceof html_label) {
+            $this->label = $text;
+        } else if (!empty($text)) {
+            $this->label = new html_label();
+            $this->label->for = $for;
+            $this->label->text = $text;
+        }
+    }
+
+    /**
+     * Adds a help icon next to the select menu.
+     *
+     * This can be used in two ways:
+     *
+     * <pre>
+     * $selectmenu->set_help_icon($page, $text, $linktext);
+     * // OR
+     * $helpicon = new help_icon();
+     * $helpicon->page = $page;
+     * $helpicon->text = $text;
+     * $helpicon->linktext = $linktext;
+     * $selectmenu->set_help_icon($helpicon);
+     * </pre>
+     *
+     * Use the second form when you need to add additional HTML attributes
+     * to the label and/or JS actions.
+     *
+     * @param mixed $page Either the keyword that defines a help page or a help_icon object
+     * @param text  $text The text of the help icon
+     * @param boolean $linktext Whether or not to show text next to the icon
+     * @return void
+     */
+    public function set_help_icon($page, $text, $linktext=false) {
+        if ($page instanceof help_icon) {
+            $this->helpicon = $page;
+        } else if (!empty($page)) {
+            $this->helpicon = new html_label();
+            $this->helpicon->page = $page;
+            $this->helpicon->text = $text;
+            $this->helpicon->linktext = $linktext;
+        }
+    }
 }
 
 /**
@@ -4606,11 +4697,11 @@ class html_form extends moodle_html_component {
      * @return void
      */
     public function __construct() {
-        static $go;
+        static $yes;
         $this->button = new html_button();
-        if (!isset($go)) {
-            $go = get_string('go');
-            $this->button->text = $go;
+        if (!isset($yes)) {
+            $yes = get_string('yes');
+            $this->button->text = $yes;
         }
     }