| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TColorPicker class file
|
|
|
4 |
*
|
|
|
5 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TColorPicker.php 2549 2008-10-29 16:06:10Z carlgmathisen $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* TColorPicker class.
|
|
|
15 |
*
|
|
|
16 |
* Be aware, this control is EXPERIMENTAL and is not stablized yet.
|
|
|
17 |
*
|
|
|
18 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
19 |
* @version $Id: TColorPicker.php 2549 2008-10-29 16:06:10Z carlgmathisen $
|
|
|
20 |
* @package System.Web.UI.WebControls
|
|
|
21 |
* @since 3.0
|
|
|
22 |
*/
|
|
|
23 |
class TColorPicker extends TTextBox
|
|
|
24 |
{
|
|
|
25 |
const SCRIPT_PATH = 'prado/colorpicker';
|
|
|
26 |
|
|
|
27 |
private $_clientSide;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* @return boolean whether the color picker should pop up when the button is clicked.
|
|
|
31 |
*/
|
|
|
32 |
public function getShowColorPicker()
|
|
|
33 |
{
|
|
|
34 |
return $this->getViewState('ShowColorPicker',true);
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Sets whether to pop up the color picker when the button is clicked.
|
|
|
39 |
* @param boolean whether to show the color picker popup
|
|
|
40 |
*/
|
|
|
41 |
public function setShowColorPicker($value)
|
|
|
42 |
{
|
|
|
43 |
$this->setViewState('ShowColorPicker',TPropertyValue::ensureBoolean($value),true);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* @param TColorPickerMode color picker UI mode
|
|
|
48 |
*/
|
|
|
49 |
public function setMode($value)
|
|
|
50 |
{
|
|
|
51 |
$this->setViewState('Mode', TPropertyValue::ensureEnum($value, 'TColorPickerMode'), TColorPickerMode::Basic);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* @return TColorPickerMode current color picker UI mode. Defaults to TColorPickerMode::Basic.
|
|
|
56 |
*/
|
|
|
57 |
public function getMode()
|
|
|
58 |
{
|
|
|
59 |
return $this->getViewState('Mode', TColorPickerMode::Basic);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* @param string set the color picker style
|
|
|
64 |
*/
|
|
|
65 |
public function setColorPickerStyle($value)
|
|
|
66 |
{
|
|
|
67 |
$this->setViewState('ColorStyle', $value, 'default');
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* @return string current color picker style
|
|
|
72 |
*/
|
|
|
73 |
public function getColorPickerStyle()
|
|
|
74 |
{
|
|
|
75 |
return $this->getViewState('ColorStyle', 'default');
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* @return string text for the color picker OK button. Default is "OK".
|
|
|
80 |
*/
|
|
|
81 |
public function getOKButtonText()
|
|
|
82 |
{
|
|
|
83 |
return $this->getViewState('OKButtonText', 'OK');
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* @param string text for the color picker OK button
|
|
|
88 |
*/
|
|
|
89 |
public function setOKButtonText($value)
|
|
|
90 |
{
|
|
|
91 |
$this->setViewState('OKButtonText', $value, 'OK');
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* @return string text for the color picker Cancel button. Default is "Cancel".
|
|
|
96 |
*/
|
|
|
97 |
public function getCancelButtonText()
|
|
|
98 |
{
|
|
|
99 |
return $this->getViewState('CancelButtonText', 'Cancel');
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
* @param string text for the color picker Cancel button
|
|
|
104 |
*/
|
|
|
105 |
public function setCancelButtonText($value)
|
|
|
106 |
{
|
|
|
107 |
$this->setViewState('CancelButtonText', $value, 'Cancel');
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* @return TColorPickerClientSide javascript event options.
|
|
|
112 |
*/
|
|
|
113 |
public function getClientSide()
|
|
|
114 |
{
|
|
|
115 |
if(is_null($this->_clientSide))
|
|
|
116 |
$this->_clientSide = $this->createClientSide();
|
|
|
117 |
return $this->_clientSide;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* @return TColorPickerClientSide javascript validator event options.
|
|
|
122 |
*/
|
|
|
123 |
protected function createClientSide()
|
|
|
124 |
{
|
|
|
125 |
return new TColorPickerClientSide;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Get javascript color picker options.
|
|
|
130 |
* @return array color picker client-side options
|
|
|
131 |
*/
|
|
|
132 |
protected function getPostBackOptions()
|
|
|
133 |
{
|
|
|
134 |
$options = parent::getPostBackOptions();
|
|
|
135 |
$options['ClassName'] = $this->getCssClass();
|
|
|
136 |
$options['ShowColorPicker'] = $this->getShowColorPicker();
|
|
|
137 |
if($options['ShowColorPicker'])
|
|
|
138 |
{
|
|
|
139 |
$mode = $this->getMode();
|
|
|
140 |
if($mode == TColorPickerMode::Full) $options['Mode'] = $mode;
|
|
|
141 |
else if($mode == TColorPickerMode::Simple) $options['Palette'] = 'Tiny';
|
|
|
142 |
$options['OKButtonText'] = $this->getOKButtonText();
|
|
|
143 |
$options['CancelButtonText'] = $this->getCancelButtonText();
|
|
|
144 |
}
|
|
|
145 |
$options = array_merge($options,$this->getClientSide()->getOptions()->toArray());
|
|
|
146 |
return $options;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* @param string asset file in the self::SCRIPT_PATH directory.
|
|
|
151 |
* @return string asset file url.
|
|
|
152 |
*/
|
|
|
153 |
protected function getAssetUrl($file='')
|
|
|
154 |
{
|
|
|
155 |
$base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
|
|
|
156 |
return $base.'/'.self::SCRIPT_PATH.'/'.$file;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
/**
|
|
|
160 |
* Publish the color picker Css asset files.
|
|
|
161 |
*/
|
|
|
162 |
public function onPreRender($param)
|
|
|
163 |
{
|
|
|
164 |
parent::onPreRender($param);
|
|
|
165 |
$this->publishColorPickerAssets();
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
/**
|
|
|
169 |
* Publish the color picker assets.
|
|
|
170 |
*/
|
|
|
171 |
protected function publishColorPickerAssets()
|
|
|
172 |
{
|
|
|
173 |
$cs = $this->getPage()->getClientScript();
|
|
|
174 |
$key = "prado:".get_class($this);
|
|
|
175 |
$imgs['button.gif'] = $this->getAssetUrl('button.gif');
|
|
|
176 |
$imgs['background.png'] = $this->getAssetUrl('background.png');
|
|
|
177 |
$options = TJavaScript::encode($imgs);
|
|
|
178 |
$code = "Prado.WebUI.TColorPicker.UIImages = {$options};";
|
|
|
179 |
$cs->registerEndScript($key, $code);
|
|
|
180 |
$cs->registerPradoScript("colorpicker");
|
|
|
181 |
$url = $this->getAssetUrl($this->getColorPickerStyle().'.css');
|
|
|
182 |
if(!$cs->isStyleSheetFileRegistered($url))
|
|
|
183 |
$cs->registerStyleSheetFile($url, $url);
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
/**
|
|
|
187 |
* Renders additional body content.
|
|
|
188 |
* This method overrides parent implementation by adding
|
|
|
189 |
* additional color picker button.
|
|
|
190 |
* @param THtmlWriter writer
|
|
|
191 |
*/
|
|
|
192 |
public function renderEndTag($writer)
|
|
|
193 |
{
|
|
|
194 |
parent::renderEndTag($writer);
|
|
|
195 |
|
|
|
196 |
$color = $this->getText();
|
|
|
197 |
$writer->addAttribute('class', 'TColorPicker_button');
|
|
|
198 |
$writer->renderBeginTag('span');
|
|
|
199 |
|
|
|
200 |
$writer->addAttribute('id', $this->getClientID().'_button');
|
|
|
201 |
$writer->addAttribute('src', $this->getAssetUrl('button.gif'));
|
|
|
202 |
if($color !== '')
|
|
|
203 |
$writer->addAttribute('style', "background-color:{$color};");
|
|
|
204 |
$writer->addAttribute('width', '20');
|
|
|
205 |
$writer->addAttribute('height', '20');
|
|
|
206 |
$writer->addAttribute('alt', '');
|
|
|
207 |
$writer->renderBeginTag('img');
|
|
|
208 |
$writer->renderEndTag();
|
|
|
209 |
$writer->renderEndTag();
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
/**
|
|
|
213 |
* Gets the name of the javascript class responsible for performing postback for this control.
|
|
|
214 |
* This method overrides the parent implementation.
|
|
|
215 |
* @return string the javascript class name
|
|
|
216 |
*/
|
|
|
217 |
protected function getClientClassName()
|
|
|
218 |
{
|
|
|
219 |
return 'Prado.WebUI.TColorPicker';
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
/**
|
|
|
224 |
* TColorPickerMode class.
|
|
|
225 |
* TColorPickerMode defines the enumerable type for the possible UI mode
|
|
|
226 |
* that a {@link TColorPicker} control can take.
|
|
|
227 |
*
|
|
|
228 |
* The following enumerable values are defined:
|
|
|
229 |
* - Simple
|
|
|
230 |
* - Basic
|
|
|
231 |
* - Full
|
|
|
232 |
*
|
|
|
233 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
234 |
* @version $Id: TColorPicker.php 2549 2008-10-29 16:06:10Z carlgmathisen $
|
|
|
235 |
* @package System.Web.UI.WebControls
|
|
|
236 |
* @since 3.0.4
|
|
|
237 |
*/
|
|
|
238 |
class TColorPickerMode extends TEnumerable
|
|
|
239 |
{
|
|
|
240 |
const Simple='Simple';
|
|
|
241 |
const Basic='Basic';
|
|
|
242 |
const Full='Full';
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
/**
|
|
|
246 |
* TColorPickerClientSide class.
|
|
|
247 |
*
|
|
|
248 |
* Client-side javascript code options.
|
|
|
249 |
*
|
|
|
250 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
251 |
* @version $Id: TColorPicker.php 2549 2008-10-29 16:06:10Z carlgmathisen $
|
|
|
252 |
* @package System.Web.UI.WebControls
|
|
|
253 |
* @since 3.1
|
|
|
254 |
*/
|
|
|
255 |
class TColorPickerClientSide extends TClientSideOptions
|
|
|
256 |
{
|
|
|
257 |
/**
|
|
|
258 |
* @return string javascript code for when a color is selected.
|
|
|
259 |
*/
|
|
|
260 |
public function getOnColorSelected()
|
|
|
261 |
{
|
|
|
262 |
return $this->getOption('OnColorSelected');
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
/**
|
|
|
266 |
* @param string javascript code for when a color is selected.
|
|
|
267 |
*/
|
|
|
268 |
public function setOnColorSelected($javascript)
|
|
|
269 |
{
|
|
|
270 |
$this->setFunction('OnColorSelected', $javascript);
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
|