summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/TClientScriptManager.php77
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php79
-rw-r--r--framework/Web/UI/WebControls/TDatePicker.php91
-rw-r--r--framework/Web/UI/WebControls/TValidationSummary.php78
4 files changed, 195 insertions, 130 deletions
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 75effa50..54bf2aa4 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -477,4 +477,81 @@ class TClientScriptManager extends TApplicationComponent
}
}
+/**
+ * TClientSideOptions abstract class.
+ *
+ * TClientSideOptions manages client-side options for components that have
+ * common client-side javascript behaviours and client-side events such as
+ * between ActiveControls and validators.
+ *
+ * @author <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.0
+ */
+abstract class TClientSideOptions extends TComponent
+{
+ /**
+ * @var TMap list of client-side options.
+ */
+ private $_options;
+
+ /**
+ * Constructor, initialize the options list.
+ */
+ public function __construct()
+ {
+ $this->_options = Prado::createComponent('System.Collections.TMap');
+ }
+
+ /**
+ * Adds on client-side event handler by wrapping the code within a
+ * javascript function block. If the code begins with "javascript:", the
+ * code is assumed to be a javascript function block rather than arbiturary
+ * javascript statements.
+ * @param string option name
+ * @param string javascript statements.
+ */
+ protected function setFunction($name, $code)
+ {
+ if(!TJavascript::isFunction($code))
+ $code = TJavascript::quoteFunction($this->ensureFunction($code));
+ $this->setOption($name, $code);
+ }
+
+ /**
+ * @return string gets a particular option, null if not set.
+ */
+ protected function getOption($name)
+ {
+ return $this->_options->itemAt($name);
+ }
+
+ /**
+ * @param string option name
+ * @param mixed option value.
+ */
+ protected function setOption($name, $value)
+ {
+ $this->_options->add($name, $value);
+ }
+
+ /**
+ * @return TMap gets the list of options as TMap
+ */
+ public function getOptions()
+ {
+ return $this->_options;
+ }
+
+ /**
+ * Ensure that the javascript statements are wrapped in a javascript
+ * function block as <code>function(sender, parameter){ //code }</code>.
+ */
+ protected function ensureFunction($javascript)
+ {
+ return "function(sender, parameter){ {$javascript} }";
+ }
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index bcddfa5f..5c75273e 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -85,7 +85,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
*/
private $_registered=false;
/**
- * @var TValidatorClientScript validator client-script options.
+ * @var TValidatorClientSideOptions validator client-script options.
*/
private $_clientScript;
/**
@@ -165,13 +165,14 @@ abstract class TBaseValidator extends TLabel implements IValidator
$options['ControlCssClass'] = $this->getControlCssClass();
$options['ControlType'] = $this->getClientControlClass($control);
-
+
//get date format from date picker target control
if($control instanceof TDatePicker)
$options['DateFormat'] = $control->getDateFormat();
if(!is_null($this->_clientScript))
- $options = array_merge($options,$this->_clientScript->getOptions());
+ $options = array_merge($options,
+ $this->_clientScript->getOptions()->toArray());
return $options;
}
@@ -192,7 +193,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
}
/**
- * Gets the TValidatorClientScript that allows modification of the client-
+ * Gets the TValidatorClientSide that allows modification of the client-
* side validator events.
*
* The client-side validator supports the following events.
@@ -205,21 +206,21 @@ abstract class TBaseValidator extends TLabel implements IValidator
*
* You can attach custom javascript code to each of these events
*
- * @return TValidatorClientScript javascript validator event options.
+ * @return TValidatorClientSide javascript validator event options.
*/
public function getClientSide()
{
if(is_null($this->_clientScript))
- $this->_clientScript = $this->createClientScript();
+ $this->_clientScript = $this->createClientSide();
return $this->_clientScript;
}
/**
* @return TValidatorClientScript javascript validator event options.
*/
- protected function createClientScript()
+ protected function createClientSide()
{
- return new TValidatorClientScript;
+ return new TValidatorClientSide;
}
/**
@@ -567,11 +568,11 @@ abstract class TBaseValidator extends TLabel implements IValidator
}
/**
- * TValidatorClientScript class.
+ * TValidatorClientSide class.
*
* Client-side validator events can be modified through the {@link
* TBaseValidator::getClientSide ClientSide} property of a validator. The
- * subproperties of ClientSide are those of the TValidatorClientScript
+ * subproperties of ClientSide are those of the TValidatorClientSide
* properties. The client-side validator supports the following events.
*
* The <tt>OnValidate</tt> event is raise before the validator validation
@@ -589,27 +590,14 @@ abstract class TBaseValidator extends TLabel implements IValidator
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TValidatorClientScript extends TComponent
+class TValidatorClientSide extends TClientSideOptions
{
/**
- * @var TMap client-side validator event javascript code.
- */
- private $_options;
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- $this->_options = new TMap;
- }
-
- /**
* @return string javascript code for client-side OnValidate event.
*/
public function getOnValidate()
{
- return $this->_options->itemAt['OnValidate'];
+ return $this->getOption('OnValidate');
}
/**
@@ -619,7 +607,7 @@ class TValidatorClientScript extends TComponent
*/
public function setOnValidate($javascript)
{
- $this->_options->add('OnValidate', $this->ensureFunction($javascript));
+ $this->setFunction('OnValidate', $javascript);
}
/**
@@ -629,7 +617,7 @@ class TValidatorClientScript extends TComponent
*/
public function setOnSuccess($javascript)
{
- $this->_options->add('OnSuccess', $this->ensureFunction($javascript));
+ $this->setFunction('OnSuccess', $javascript);
}
/**
@@ -637,7 +625,7 @@ class TValidatorClientScript extends TComponent
*/
public function getOnSuccess()
{
- return $this->_options->itemAt('OnSuccess');
+ return $this->getOption('OnSuccess');
}
/**
@@ -647,7 +635,7 @@ class TValidatorClientScript extends TComponent
*/
public function setOnError($javascript)
{
- $this->_options->add('OnError', $this->ensureFunction($javascript));
+ $this->setFunction('OnError', $javascript);
}
/**
@@ -655,7 +643,7 @@ class TValidatorClientScript extends TComponent
*/
public function getOnError()
{
- return $this->_options->itemAt('OnError');
+ return $this->getOption('OnError');
}
/**
@@ -663,7 +651,7 @@ class TValidatorClientScript extends TComponent
*/
public function setObserveChanges($value)
{
- $this->_options->add('ObserveChanges', TPropertyValue::ensureBoolean($value));
+ $this->setOption('ObserveChanges', TPropertyValue::ensureBoolean($value));
}
/**
@@ -671,36 +659,9 @@ class TValidatorClientScript extends TComponent
*/
public function getObserveChanges()
{
- $changes = $this->_options->itemAt('ObserveChanges');
+ $changes = $this->getOption('ObserveChanges');
return is_null($changes) ? true : $changes;
}
-
- /**
- * @return array list of client-side event code.
- */
- public function getOptions()
- {
- return $this->_options->toArray();
- }
-
-
- /**
- * Ensure the string is a valid javascript function. If the string begins
- * with "javascript:" valid javascript function is assumed, otherwise the
- * code block is enclosed with "function(validator, sender){ }" block.
- * @param string javascript code.
- * @return string javascript function code.
- */
- private function ensureFunction($javascript)
- {
- if(TJavascript::isFunction($javascript))
- return $javascript;
- else
- {
- $code = "function(validator, sender){ {$javascript} }";
- return TJavascript::quoteFunction($code);
- }
- }
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php
index 642d9953..0c3e0b9a 100644
--- a/framework/Web/UI/WebControls/TDatePicker.php
+++ b/framework/Web/UI/WebControls/TDatePicker.php
@@ -19,8 +19,6 @@ Prado::using('System.Web.UI.WebControls.TTextBox');
*
* TDatePicker class.
*
- * Be aware, this control is EXPERIMENTAL and is not stablized yet.
- *
* TDatePicker displays a text box for date input purpose.
* When the text box receives focus, a calendar will pop up and users can
* pick up from it a date that will be automatically entered into the text box.
@@ -69,14 +67,18 @@ Prado::using('System.Web.UI.WebControls.TTextBox');
class TDatePicker extends TTextBox
{
/**
+ * @var TDatePickerClientScript validator client-script options.
+ */
+ private $_clientScript;
+ /**
* AutoPostBack is not supported.
*/
public function setAutoPostBack($value)
{
throw new TNotSupportedException('tdatepicker_autopostback_unsupported',
- get_class($this));
+ get_class($this));
}
-
+
/**
* @return string the format of the date string
*/
@@ -278,7 +280,7 @@ class TDatePicker extends TTextBox
{
return $this->getText();
}
-
+
/**
* @param string date string
*/
@@ -288,6 +290,31 @@ class TDatePicker extends TTextBox
}
/**
+ * Gets the TDatePickerClientScript to set the TDatePicker event handlers.
+ *
+ * The date picker on the client-side supports the following events.
+ * # <tt>OnDateChanged</tt> -- raised when the date is changed.
+ *
+ * You can attach custom javascript code to each of these events
+ *
+ * @return TDatePickerClientScript javascript validator event options.
+ */
+ public function getClientSide()
+ {
+ if(is_null($this->_clientScript))
+ $this->_clientScript = $this->createClientScript();
+ return $this->_clientScript;
+ }
+
+ /**
+ * @return TDatePickerClientScript javascript validator event options.
+ */
+ protected function createClientScript()
+ {
+ return new TDatePickerClientScript;
+ }
+
+ /**
* Returns the value to be validated.
* This methid is required by IValidatable interface.
* @return integer the value of the property to be validated.
@@ -394,7 +421,7 @@ class TDatePicker extends TTextBox
$year = intval($values[$key.'$year']);
else
$year = $date['year'];
-
+
$date = @mktime(0, 0, 0, $month, $day, $year);
$pattern = $this->getDateFormat();
@@ -421,6 +448,9 @@ class TDatePicker extends TTextBox
$options['Trigger'] = $this->getDatePickerButtonID();
$options = array_merge($options, $this->getCulturalOptions());
+ if(!is_null($this->_clientScript))
+ $options = array_merge($options,
+ $this->_clientScript->getOptions()->toArray());
return $options;
}
@@ -583,7 +613,7 @@ class TDatePicker extends TTextBox
$writer->addAttribute('name', $this->getUniqueID().'$month');
$writer->addAttribute('class', 'datepicker_month_options');
if($this->getReadOnly() || !$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
+ $writer->addAttribute('disabled', 'disabled');
$writer->renderBeginTag('select');
$this->renderDropDownListOptions($writer,
$this->getLocalizedMonthNames($info), $selected-1);
@@ -604,8 +634,8 @@ class TDatePicker extends TTextBox
switch($formatter->getMonthPattern())
{
case 'MMM': return $info->getAbbreviatedMonthNames();
- case 'MM':
- $array = array();
+ case 'MM':
+ $array = array();
for($i=1;$i<=12;$i++)
$array[$i-1] = $i < 10 ? '0'.$i : $i;
return $array;
@@ -629,7 +659,7 @@ class TDatePicker extends TTextBox
$writer->addAttribute('id', $this->getClientID().'_year');
$writer->addAttribute('name', $this->getUniqueID().'$year');
if($this->getReadOnly() || !$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
+ $writer->addAttribute('disabled', 'disabled');
$writer->renderBeginTag('select');
$writer->addAttribute('class', 'datepicker_year_options');
$this->renderDropDownListOptions($writer, $years, $selected);
@@ -705,7 +735,7 @@ class TDatePicker extends TTextBox
else
throw new TConfigurationException('datepicker_calendarstyle_invalid',$style);
}
-
+
/**
* Publish the spacer.gif for IE iframe source.
* @return string the URL for the spacer.gif.
@@ -739,13 +769,13 @@ class TDatePicker extends TTextBox
{
$cs = $this->getPage()->getClientScript();
$cs->registerPradoScript("datepicker");
-
+
if(!$cs->isEndScriptRegistered('TDatePicker.spacer'))
{
$spacer = $this->publishIFrameSpacer();
$code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
$cs->registerEndScript('TDatePicker.spacer', $code);
- }
+ }
$options = TJavaScript::encode($this->getDatePickerOptions());
$code = "new Prado.WebUI.TDatePicker($options);";
@@ -754,4 +784,39 @@ class TDatePicker extends TTextBox
}
}
+/**
+ * TDatePickerClientScript class.
+ *
+ * Client-side date picker event {@link setOnDateChanged OnDateChanged}
+ * can be modified through the {@link TDatePicker:: getClientSide ClientSide}
+ * property of a date picker.
+ *
+ * The <tt>OnDateChanged</tt> event is raise when the date picker's date
+ * is changed.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDatePickerClientScript extends TClientSideOptions
+{
+ /**
+ * Javascript code to execute when the date picker's date is changed.
+ * @param string javascript code
+ */
+ public function setOnDateChanged($javascript)
+ {
+ $this->setFunction('OnDateChanged', $javascript);
+ }
+
+ /**
+ * @return string javascript code to execute when the date picker's date is changed.
+ */
+ public function getOnDateChanged()
+ {
+ return $this->getOption('OnDateChanged');
+ }
+}
+
?>
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php
index 027b0410..c7330f94 100644
--- a/framework/Web/UI/WebControls/TValidationSummary.php
+++ b/framework/Web/UI/WebControls/TValidationSummary.php
@@ -40,7 +40,7 @@ class TValidationSummary extends TWebControl
* @var TValidatorClientScript validator client-script options.
*/
private $_clientScript;
-
+
/**
* Constructor.
* This method sets the foreground color to red.
@@ -232,7 +232,7 @@ class TValidationSummary extends TWebControl
if($this->getEnableClientScript() && !$cs->isEndScriptRegistered($scriptKey))
{
$manager['FormID'] = $formID;
- $options = TJavaScript::encode($manager);
+ $options = TJavaScript::encode($manager);
$cs->registerPradoScript('validator');
$cs->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});");
}
@@ -262,10 +262,11 @@ class TValidationSummary extends TWebControl
$options['Refresh'] = $this->getAutoUpdate();
$options['ValidationGroup'] = $this->getValidationGroup();
$options['Display'] = $this->getDisplay();
-
+
if(!is_null($this->_clientScript))
- $options = array_merge($options,$this->_clientScript->getOptions());
-
+ $options = array_merge($options,
+ $this->_clientScript->getOptions()->toArray());
+
return $options;
}
@@ -279,7 +280,7 @@ class TValidationSummary extends TWebControl
$this->_clientScript = $this->createClientScript();
return $this->_clientScript;
}
-
+
/**
* @return TValidationSummaryClientScript javascript validation summary
* event options.
@@ -388,48 +389,35 @@ class TValidationSummary extends TWebControl
/**
* TValidationSummaryClientScript class.
- *
+ *
* Client-side validation summary events such as {@link setOnHideSummary
* OnHideSummary} and {@link setOnShowSummary OnShowSummary} can be modified
* through the {@link TBaseValidator:: getClientSide ClientSide} property of a
* validation summary.
- *
+ *
* The <tt>OnHideSummary</tt> event is raise when the validation summary
* requests to hide the messages.
- *
+ *
* The <tt>OnShowSummary</tt> event is raised when the validation summary
* requests to show the messages.
- *
+ *
* See the quickstart documentation for further details.
- *
+ *
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TValidationSummaryClientScript extends TComponent
+class TValidationSummaryClientScript extends TClientSideOptions
{
/**
- * @var TMap client-side validation summary event javascript code.
- */
- private $_options;
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- $this->_options = new TMap;
- }
-
- /**
* @return string javascript code for client-side OnHideSummary event.
*/
public function getOnHideSummary()
{
- return $this->_options->itemAt['OnHideSummary'];
+ return $this->getOption('OnHideSummary');
}
-
+
/**
* Client-side OnHideSummary validation summary event is raise when all the
* validators are valid. This will override the default client-side
@@ -438,9 +426,9 @@ class TValidationSummaryClientScript extends TComponent
*/
public function setOnHideSummary($javascript)
{
- $this->_options->add('OnHideSummary', $this->ensureFunction($javascript));
+ $this->setFunction('OnHideSummary', $javascript);
}
-
+
/**
* Client-side OnShowSummary event is raise when one or more validators are
* not valid. This will override the default client-side validation summary
@@ -449,42 +437,16 @@ class TValidationSummaryClientScript extends TComponent
*/
public function setOnShowSummary($javascript)
{
- $this->_options->add('OnShowSummary', $this->ensureFunction($javascript));
+ $this->setFunction('OnShowSummary', $javascript);
}
-
+
/**
* @return string javascript code for client-side OnShowSummary event.
*/
public function getOnShowSummary()
{
- return $this->_options->itemAt('OnShowSummary');
+ return $this->getOption('OnShowSummary');
}
-
- /**
- * @return array list of client-side event code.
- */
- public function getOptions()
- {
- return $this->_options->toArray();
- }
-
- /**
- * Ensure the string is a valid javascript function. If the string begins
- * with "javascript:" valid javascript function is assumed, otherwise the
- * code block is enclosed with "function(summary, validators){ }" block.
- * @param string javascript code.
- * @return string javascript function code.
- */
- private function ensureFunction($javascript)
- {
- if(TJavascript::isFunction($javascript))
- return $javascript;
- else
- {
- $code = "function(summary, validators){ {$javascript} }";
- return TJavascript::quoteFunction($code);
- }
- }
}
?> \ No newline at end of file