[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Classes representing JS event handlers, used by output components. 19 * 20 * Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML 21 * for an overview. 22 * 23 * @package core 24 * @category output 25 * @copyright 2009 Nicolas Connault 26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 */ 28 29 defined('MOODLE_INTERNAL') || die(); 30 31 /** 32 * Helper class used by other components that involve an action on the page (URL or JS). 33 * 34 * @copyright 2009 Nicolas Connault 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 * @since Moodle 2.0 37 * @package core 38 * @category output 39 */ 40 class component_action { 41 42 /** 43 * @var string $event The DOM event that will trigger this action when caught 44 */ 45 public $event; 46 47 /** 48 * @var string A function name to call when the button is clicked 49 * The JS function you create must have two arguments: 50 * 1. The event object 51 * 2. An object/array of arguments ($jsfunctionargs) 52 */ 53 public $jsfunction = false; 54 55 /** 56 * @var array An array of arguments to pass to the JS function 57 */ 58 public $jsfunctionargs = array(); 59 60 /** 61 * Constructor 62 * @param string $event DOM event 63 * @param string $jsfunction An optional JS function. Required if jsfunctionargs is given 64 * @param array $jsfunctionargs An array of arguments to pass to the jsfunction 65 */ 66 public function __construct($event, $jsfunction, $jsfunctionargs=array()) { 67 $this->event = $event; 68 69 $this->jsfunction = $jsfunction; 70 $this->jsfunctionargs = $jsfunctionargs; 71 72 if (!empty($this->jsfunctionargs)) { 73 if (empty($this->jsfunction)) { 74 throw new coding_exception('The component_action object needs a jsfunction value to pass the jsfunctionargs to.'); 75 } 76 } 77 } 78 } 79 80 81 /** 82 * Confirm action 83 * 84 * @copyright 2009 Nicolas Connault 85 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 86 * @since Moodle 2.0 87 * @package core 88 * @category output 89 */ 90 class confirm_action extends component_action { 91 /** 92 * Constructs the confirm action object 93 * 94 * @param string $message The message to display to the user when they are shown 95 * the confirm dialogue. 96 * @param string $callback Deprecated since 2.7 97 * @param string $continuelabel The string to use for he continue button 98 * @param string $cancellabel The string to use for the cancel button 99 */ 100 public function __construct($message, $callback = null, $continuelabel = null, $cancellabel = null) { 101 if ($callback !== null) { 102 debugging('The callback argument to new confirm_action() has been deprecated.' . 103 ' If you need to use a callback, please write Javascript to use moodle-core-notification-confirmation ' . 104 'and attach to the provided events.', 105 DEBUG_DEVELOPER); 106 } 107 parent::__construct('click', 'M.util.show_confirm_dialog', array( 108 'message' => $message, 109 'continuelabel' => $continuelabel, 'cancellabel' => $cancellabel)); 110 } 111 } 112 113 114 /** 115 * Component action for a popup window. 116 * 117 * @copyright 2009 Nicolas Connault 118 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 119 * @since Moodle 2.0 120 * @package core 121 * @category output 122 */ 123 class popup_action extends component_action { 124 125 /** 126 * @var string The JS function to call for the popup 127 */ 128 public $jsfunction = 'openpopup'; 129 130 /** 131 * @var array An array of parameters that will be passed to the openpopup JS function 132 */ 133 public $params = array( 134 'height' => 400, 135 'width' => 500, 136 'top' => 0, 137 'left' => 0, 138 'menubar' => false, 139 'location' => false, 140 'scrollbars' => true, 141 'resizable' => true, 142 'toolbar' => true, 143 'status' => true, 144 'directories' => false, 145 'fullscreen' => false, 146 'dependent' => true); 147 148 /** 149 * Constructor 150 * 151 * @param string $event DOM event 152 * @param moodle_url|string $url A moodle_url object, required if no jsfunction is given 153 * @param string $name The JS function to call for the popup (default 'popup') 154 * @param array $params An array of popup parameters 155 */ 156 public function __construct($event, $url, $name='popup', $params=array()) { 157 global $CFG; 158 $this->name = $name; 159 160 $url = new moodle_url($url); 161 162 if ($this->name) { 163 $_name = $this->name; 164 if (($_name = preg_replace("/\s/", '_', $_name)) != $this->name) { 165 throw new coding_exception('The $name of a popup window shouldn\'t contain spaces - string modified. '. $this->name .' changed to '. $_name); 166 $this->name = $_name; 167 } 168 } else { 169 $this->name = 'popup'; 170 } 171 172 foreach ($this->params as $var => $val) { 173 if (array_key_exists($var, $params)) { 174 $this->params[$var] = $params[$var]; 175 } 176 } 177 178 $attributes = array('url' => $url->out(false), 'name' => $name, 'options' => $this->get_js_options($params)); 179 if (!empty($params['fullscreen'])) { 180 $attributes['fullscreen'] = 1; 181 } 182 parent::__construct($event, $this->jsfunction, $attributes); 183 } 184 185 /** 186 * Returns a string of concatenated option->value pairs used by JS to call the popup window, 187 * based on this object's variables 188 * 189 * @return string String of option->value pairs for JS popup function. 190 */ 191 public function get_js_options() { 192 $jsoptions = ''; 193 194 foreach ($this->params as $var => $val) { 195 if (is_string($val) || is_int($val)) { 196 $jsoptions .= "$var=$val,"; 197 } elseif (is_bool($val)) { 198 $jsoptions .= ($val) ? "$var," : "$var=0,"; 199 } 200 } 201 202 $jsoptions = substr($jsoptions, 0, strlen($jsoptions) - 1); 203 204 return $jsoptions; 205 } 206 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |