From: nicolasconnault Date: Thu, 13 Aug 2009 01:15:58 +0000 (+0000) Subject: MDL-19756 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7a5c78e049af7f95d6f2884596e4ee333e638372;p=moodle.git MDL-19756 * Removed outputpixfinders.php and put that code back in outputlib.php * Created labelled_html_component class and subclassed all appropriate components from it * Added component::add_confirm_action($message) as a shortcut for adding a confirmation popup * Fixed bug in close_window_button() --- diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index bdd238de48..4b08d911ff 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2901,7 +2901,7 @@ function print_arrow($direction='up', $strsort=null, $return=false) { function doc_link($path='', $text='', $iconpath='') { global $CFG, $OUTPUT; - // debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->action_icon().'); + // debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().'); if (empty($CFG->docroot)) { return ''; diff --git a/lib/javascript-static.js b/lib/javascript-static.js index c8581d6539..98e86ebad4 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -1041,8 +1041,9 @@ block_hider.prototype.update_state = function () { } /** Close the current browser window. */ -function close_window() { - window.close(); +function close_window(e) { + YAHOO.util.Event.preventDefault(e); + self.close(); } /** diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index f9d1431f98..8953056ec9 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -48,10 +48,6 @@ class moodle_html_component { * @var string $style value to use for the style attribute of this HTML tag. */ public $style = ''; - /** - * @var mixed $label The label for that component. String or html_label object - */ - public $label; /** * @var array class names to add to this HTML element. */ @@ -191,6 +187,23 @@ class moodle_html_component { return $this->actions; } + /** + * 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))); + } +} + +class labelled_html_component extends moodle_html_component { + /** + * @var mixed $label The label for that component. String or html_label object + */ + public $label; + /** * Adds a descriptive label to the component. * @@ -225,16 +238,6 @@ 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 @@ -284,7 +287,7 @@ class html_label extends moodle_html_component { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ -class html_select extends moodle_html_component { +class html_select extends labelled_html_component { /** * The html_select object parses an array of options into component objects * @see nested attribute @@ -735,7 +738,7 @@ class html_select extends moodle_html_component { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ -class html_select_option extends moodle_html_component { +class html_select_option extends labelled_html_component { /** * @var string $value The value of this option (will be sent with form) */ @@ -782,7 +785,7 @@ class html_select_option extends moodle_html_component { * @param string $alt * @return html_select_option A component ready for $OUTPUT->checkbox() */ - public function make_checkbox($value, $checked, $label='', $alt='') { + public function make_checkbox($value, $checked, $label, $alt='') { $checkbox = new html_select_option(); $checkbox->value = $value; $checkbox->selected = $checked; @@ -828,7 +831,7 @@ class html_select_optgroup extends moodle_html_component { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ -class html_field extends moodle_html_component { +class html_field extends labelled_html_component { /** * @var string $name The name attribute of the field */ @@ -900,7 +903,7 @@ class html_field extends moodle_html_component { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ -class html_table extends moodle_html_component { +class html_table extends labelled_html_component { /** * @var array of headings. The n-th array item is used as a heading of the n-th column. * @@ -1216,7 +1219,7 @@ class html_link extends moodle_html_component { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ -class html_button extends moodle_html_component { +class html_button extends labelled_html_component { /** * @var string $text */ @@ -1253,7 +1256,7 @@ class html_button extends moodle_html_component { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ -class html_image extends moodle_html_component { +class html_image extends labelled_html_component { /** * @var string $alt A descriptive text */ @@ -1813,7 +1816,7 @@ class moodle_user_picture extends moodle_html_component { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ -class moodle_help_icon extends moodle_html_component { +class moodle_help_icon extends labelled_html_component { /** * @var html_link $link A html_link object that will hold the URL info */ @@ -1943,7 +1946,7 @@ class moodle_help_icon extends moodle_html_component { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.0 */ -class moodle_action_icon extends moodle_html_component { +class moodle_action_icon extends labelled_html_component { /** * @var string $linktext Optional text to display next to the icon */ @@ -1973,6 +1976,13 @@ class moodle_action_icon extends moodle_html_component { public function prepare() { $this->image->add_class('action-icon'); + if (!empty($this->actions)) { + foreach ($this->actions as $action) { + $this->link->add_action($action); + } + unset($this->actions); + } + parent::prepare(); if (empty($this->image->src)) { diff --git a/lib/outputlib.php b/lib/outputlib.php index aa4eb64ea7..6a8e05fb89 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -26,7 +26,6 @@ define('HTML_ATTR_EMPTY', '@EMPTY@'); require_once($CFG->libdir.'/outputcomponents.php'); require_once($CFG->libdir.'/outputactions.php'); require_once($CFG->libdir.'/outputfactories.php'); -require_once($CFG->libdir.'/outputpixfinders.php'); require_once($CFG->libdir.'/outputrenderers.php'); /** @@ -889,6 +888,198 @@ class xhtml_container_stack { } } +/** + * An icon finder is responsible for working out the correct URL for an icon. + * + * A icon finder must also have a constructor that takes a theme object. + * (See {@link standard_icon_finder::__construct} for an example.) + * + * Note that we are planning to change the Moodle icon naming convention before + * the Moodle 2.0 release. Therefore, this API will probably change. + * + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 2.0 + */ +interface icon_finder { + /** + * Return the URL for an icon identified as in pre-Moodle 2.0 code. + * + * Suppose you have old code like $url = "$CFG->pixpath/i/course.gif"; + * then old_icon_url('i/course'); will return the equivalent URL that is correct now. + * + * @param string $iconname the name of the icon. + * @return string the URL for that icon. + */ + public function old_icon_url($iconname); + + /** + * Return the URL for an icon identified as in pre-Moodle 2.0 code. + * + * Suppose you have old code like $url = "$CFG->modpixpath/$mod/icon.gif"; + * then mod_icon_url('icon', $mod); will return the equivalent URL that is correct now. + * + * @param string $iconname the name of the icon. + * @param string $module the module the icon belongs to. + * @return string the URL for that icon. + */ + public function mod_icon_url($iconname, $module); +} + +/** + * This icon finder implements the old scheme that was used when themes that had + * $THEME->custompix = false. + * + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 2.0 + */ +class pix_icon_finder implements icon_finder { + /** + * Constructor + * @param theme_config $theme the theme we are finding icons for (which is irrelevant). + */ + public function __construct($theme) { + } + + /** + * Implement interface method. + * @param string $iconname the name of the icon. + * @return string the URL for that icon. + */ + public function old_icon_url($iconname) { + global $CFG; + if (file_exists($CFG->dirroot . '/pix/' . $iconname . '.png')) { + return $CFG->httpswwwroot . '/pix/' . $iconname . '.png'; + } else { + return $CFG->httpswwwroot . '/pix/' . $iconname . '.gif'; + } + } + + /** + * Implement interface method. + * @param string $iconname the name of the icon. + * @param string $module the module the icon belongs to. + * @return string the URL for that icon. + */ + public function mod_icon_url($iconname, $module) { + global $CFG; + if (file_exists($CFG->dirroot . '/mod/' . $module . '/' . $iconname . '.png')) { + return $CFG->httpswwwroot . '/mod/' . $module . '/' . $iconname . '.png'; + } else { + return $CFG->httpswwwroot . '/mod/' . $module . '/' . $iconname . '.gif'; + } + } +} + + +/** + * This icon finder implements the old scheme that was used for themes that had + * $THEME->custompix = true. + * + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 2.0 + */ +class theme_icon_finder implements icon_finder { + protected $themename; + /** + * Constructor + * @param theme_config $theme the theme we are finding icons for. + */ + public function __construct($theme) { + $this->themename = $theme->name; + } + + /** + * Implement interface method. + * @param string $iconname the name of the icon. + * @return string the URL for that icon. + */ + public function old_icon_url($iconname) { + global $CFG; + if (file_exists($CFG->themedir . '/' . $this->themename . '/pix/' . $iconname . '.png')) { + return $CFG->httpsthemewww . '/' . $this->themename . '/pix/' . $iconname . '.png'; + } else { + return $CFG->httpsthemewww . '/' . $this->themename . '/pix/' . $iconname . '.gif'; + } + } + + /** + * Implement interface method. + * @param string $iconname the name of the icon. + * @param string $module the module the icon belongs to. + * @return string the URL for that icon. + */ + public function mod_icon_url($iconname, $module) { + global $CFG; + if (file_exists($CFG->themedir . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.png')) { + return $CFG->httpsthemewww . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.png'; + } else { + return $CFG->httpsthemewww . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.gif'; + } + } +} + + +/** + * This icon finder implements the algorithm in pix/smartpix.php. + * + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 2.0 + */ +class smartpix_icon_finder extends pix_icon_finder { + protected $places = array(); + + /** + * Constructor + * @param theme_config $theme the theme we are finding icons for. + */ + public function __construct($theme) { + global $CFG; + $this->places[$CFG->themedir . '/' . $theme->name . '/pix/'] = + $CFG->httpsthemewww . '/' . $theme->name . '/pix/'; + if (!empty($theme->parent)) { + $this->places[$CFG->themedir . '/' . $theme->parent . '/pix/'] = + $CFG->httpsthemewww . '/' . $theme->parent . '/pix/'; + } + } + + /** + * Implement interface method. + * @param string $iconname the name of the icon. + * @return string the URL for that icon. + */ + public function old_icon_url($iconname) { + foreach ($this->places as $dirroot => $urlroot) { + if (file_exists($dirroot . $iconname . '.png')) { + return $dirroot . $iconname . '.png'; + } else if (file_exists($dirroot . $iconname . '.gif')) { + return $dirroot . $iconname . '.gif'; + } + } + return parent::old_icon_url($iconname); + } + + /** + * Implement interface method. + * @param string $iconname the name of the icon. + * @param string $module the module the icon belongs to. + * @return string the URL for that icon. + */ + public function mod_icon_url($iconname, $module) { + foreach ($this->places as $dirroot => $urlroot) { + if (file_exists($dirroot . 'mod/' . $iconname . '.png')) { + return $dirroot . 'mod/' . $iconname . '.png'; + } else if (file_exists($dirroot . 'mod/' . $iconname . '.gif')) { + return $dirroot . 'mod/' . $iconname . '.gif'; + } + } + return parent::old_icon_url($iconname, $module); + } +} + /** * Output CSS while replacing constants/variables. See MDL-6798 for details diff --git a/lib/outputpixfinders.php b/lib/outputpixfinders.php deleted file mode 100644 index decae9b2e1..0000000000 --- a/lib/outputpixfinders.php +++ /dev/null @@ -1,221 +0,0 @@ -. - -/** - * Interface and classes for icon finders. - * - * Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML - * for an overview. - * - * @package moodlecore - * @copyright 2009 Tim Hunt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * An icon finder is responsible for working out the correct URL for an icon. - * - * A icon finder must also have a constructor that takes a theme object. - * (See {@link standard_icon_finder::__construct} for an example.) - * - * Note that we are planning to change the Moodle icon naming convention before - * the Moodle 2.0 release. Therefore, this API will probably change. - * - * @copyright 2009 Tim Hunt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 2.0 - */ -interface icon_finder { - /** - * Return the URL for an icon identified as in pre-Moodle 2.0 code. - * - * Suppose you have old code like $url = "$CFG->pixpath/i/course.gif"; - * then old_icon_url('i/course'); will return the equivalent URL that is correct now. - * - * @param string $iconname the name of the icon. - * @return string the URL for that icon. - */ - public function old_icon_url($iconname); - - /** - * Return the URL for an icon identified as in pre-Moodle 2.0 code. - * - * Suppose you have old code like $url = "$CFG->modpixpath/$mod/icon.gif"; - * then mod_icon_url('icon', $mod); will return the equivalent URL that is correct now. - * - * @param string $iconname the name of the icon. - * @param string $module the module the icon belongs to. - * @return string the URL for that icon. - */ - public function mod_icon_url($iconname, $module); -} - -/** - * This icon finder implements the old scheme that was used when themes that had - * $THEME->custompix = false. - * - * @copyright 2009 Tim Hunt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 2.0 - */ -class pix_icon_finder implements icon_finder { - /** - * Constructor - * @param theme_config $theme the theme we are finding icons for (which is irrelevant). - */ - public function __construct($theme) { - } - - /** - * Implement interface method. - * @param string $iconname the name of the icon. - * @return string the URL for that icon. - */ - public function old_icon_url($iconname) { - global $CFG; - if (file_exists($CFG->dirroot . '/pix/' . $iconname . '.png')) { - return $CFG->httpswwwroot . '/pix/' . $iconname . '.png'; - } else { - return $CFG->httpswwwroot . '/pix/' . $iconname . '.gif'; - } - } - - /** - * Implement interface method. - * @param string $iconname the name of the icon. - * @param string $module the module the icon belongs to. - * @return string the URL for that icon. - */ - public function mod_icon_url($iconname, $module) { - global $CFG; - if (file_exists($CFG->dirroot . '/mod/' . $module . '/' . $iconname . '.png')) { - return $CFG->httpswwwroot . '/mod/' . $module . '/' . $iconname . '.png'; - } else { - return $CFG->httpswwwroot . '/mod/' . $module . '/' . $iconname . '.gif'; - } - } -} - - -/** - * This icon finder implements the old scheme that was used for themes that had - * $THEME->custompix = true. - * - * @copyright 2009 Tim Hunt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 2.0 - */ -class theme_icon_finder implements icon_finder { - protected $themename; - /** - * Constructor - * @param theme_config $theme the theme we are finding icons for. - */ - public function __construct($theme) { - $this->themename = $theme->name; - } - - /** - * Implement interface method. - * @param string $iconname the name of the icon. - * @return string the URL for that icon. - */ - public function old_icon_url($iconname) { - global $CFG; - if (file_exists($CFG->themedir . '/' . $this->themename . '/pix/' . $iconname . '.png')) { - return $CFG->httpsthemewww . '/' . $this->themename . '/pix/' . $iconname . '.png'; - } else { - return $CFG->httpsthemewww . '/' . $this->themename . '/pix/' . $iconname . '.gif'; - } - } - - /** - * Implement interface method. - * @param string $iconname the name of the icon. - * @param string $module the module the icon belongs to. - * @return string the URL for that icon. - */ - public function mod_icon_url($iconname, $module) { - global $CFG; - if (file_exists($CFG->themedir . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.png')) { - return $CFG->httpsthemewww . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.png'; - } else { - return $CFG->httpsthemewww . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.gif'; - } - } -} - - -/** - * This icon finder implements the algorithm in pix/smartpix.php. - * - * @copyright 2009 Tim Hunt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 2.0 - */ -class smartpix_icon_finder extends pix_icon_finder { - protected $places = array(); - - /** - * Constructor - * @param theme_config $theme the theme we are finding icons for. - */ - public function __construct($theme) { - global $CFG; - $this->places[$CFG->themedir . '/' . $theme->name . '/pix/'] = - $CFG->httpsthemewww . '/' . $theme->name . '/pix/'; - if (!empty($theme->parent)) { - $this->places[$CFG->themedir . '/' . $theme->parent . '/pix/'] = - $CFG->httpsthemewww . '/' . $theme->parent . '/pix/'; - } - } - - /** - * Implement interface method. - * @param string $iconname the name of the icon. - * @return string the URL for that icon. - */ - public function old_icon_url($iconname) { - foreach ($this->places as $dirroot => $urlroot) { - if (file_exists($dirroot . $iconname . '.png')) { - return $dirroot . $iconname . '.png'; - } else if (file_exists($dirroot . $iconname . '.gif')) { - return $dirroot . $iconname . '.gif'; - } - } - return parent::old_icon_url($iconname); - } - - /** - * Implement interface method. - * @param string $iconname the name of the icon. - * @param string $module the module the icon belongs to. - * @return string the URL for that icon. - */ - public function mod_icon_url($iconname, $module) { - foreach ($this->places as $dirroot => $urlroot) { - if (file_exists($dirroot . 'mod/' . $iconname . '.png')) { - return $dirroot . 'mod/' . $iconname . '.png'; - } else if (file_exists($dirroot . 'mod/' . $iconname . '.gif')) { - return $dirroot . 'mod/' . $iconname . '.gif'; - } - } - return parent::old_icon_url($iconname, $module); - } -} - - diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index c14789e6e4..bd29382188 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1155,7 +1155,7 @@ class moodle_core_renderer extends moodle_renderer_base { // Removing the button so it doesn't get output again unset($form->button); - return $this->form($form, $buttonoutput); + return $this->output_tag('div', array('class' => 'singlebutton'), $this->form($form, $buttonoutput)); } /** @@ -1206,8 +1206,7 @@ class moodle_core_renderer extends moodle_renderer_base { 'class' => $form->get_classes_string()); $divoutput = $this->output_tag('div', array(), $hiddenoutput . $contents . $buttonoutput); - $formoutput = $this->output_tag('form', $formattributes, $divoutput); - $output = $this->output_tag('div', array('class' => 'singlebutton'), $formoutput); + $output = $this->output_tag('form', $formattributes, $divoutput); return $output; } @@ -1545,12 +1544,13 @@ class moodle_core_renderer extends moodle_renderer_base { * @param string $text The lang string for the button's label (already output from get_string()) * @return string|void if $return is true, void otherwise */ - public function close_window_button($text) { + public function close_window_button($text='') { if (empty($text)) { $text = get_string('closewindow'); } $closeform = new html_form(); $closeform->url = '#'; + $closeform->method = 'get'; $closeform->button->text = $text; $closeform->button->add_action('click', 'close_window'); $closeform->button->prepare(); diff --git a/lib/weblib.php b/lib/weblib.php index 15881359e6..6d19a9daae 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -559,6 +559,8 @@ function prepare_url($url, $stripformparams=false) { if (preg_match('/(.*)\/([A-Za-z0-9-_]*\.php)$/', $PAGE->url->out(true), $matches)) { return $matches[1] . "/$output"; + } else if ($output == '') { + return $PAGE->url->out(false, array(), false) . '#'; } else { throw new coding_exception('Your page uses bizarre relative URLs which Moodle cannot handle. Please use absolute URLs.'); }