From 2ea02214b2fb6bedb58dbbd318ef171a9e146524 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Mon, 29 May 2006 03:08:07 +0000
Subject: Merge from 3.0 branch till 1099.
---
framework/Web/UI/WebControls/TBaseValidator.php | 76 ++++++++++++++++---------
framework/Web/UI/WebControls/TDatePicker.php | 30 ++++++++--
framework/Web/UI/WebControls/TListControl.php | 39 +++++++++++++
3 files changed, 112 insertions(+), 33 deletions(-)
(limited to 'framework/Web/UI/WebControls')
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index ffdfd057..3c76db30 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -83,6 +83,12 @@ abstract class TBaseValidator extends TLabel implements IValidator
* @var TClientSideValidatorOptions validator client-script options.
*/
private $_clientSide;
+ /**
+ * Controls for which the client-side validation3.js file needs to handle
+ * them specially.
+ * @var array list of control class names
+ */
+ private static $_clientClass = array('THtmlArea', 'TDatePicker');
/**
* Constructor.
@@ -152,28 +158,44 @@ abstract class TBaseValidator extends TLabel implements IValidator
$options['ValidationGroup'] = $this->getValidationGroup();
$options['ControlToValidate'] = $control->getClientID();
$options['ControlCssClass'] = $this->getControlCssClass();
- $options['ControlType'] = get_class($control);
-
+
+ $options['ControlType'] = $this->getClientControlClass($control);
+
if(!is_null($this->_clientSide))
$options = array_merge($options,$this->_clientSide->getOptions()->toArray());
-
+
return $options;
}
-
+
+ /**
+ * Gets the Control type for client-side validation. If new cases exists in
+ * TBaseValidator::$_clientClass, be sure to update the corresponding
+ * "Javascript/validation3.js" file as well.
+ * @param TControl control to validate.
+ * @return string control type for client-side validation.
+ */
+ private function getClientControlClass($control)
+ {
+ foreach(self::$_clientClass as $type)
+ if($control instanceof $type)
+ return $type;
+ return get_class($control);
+ }
+
/**
* Gets the TClientSideValidatorOptions that allows modification of the client-
- * side validator events.
- *
+ * side validator events.
+ *
* The client-side validator supports the following events.
* # OnValidate -- raised before client-side validation is
- * executed.
+ * executed.
* # OnSuccess -- raised after client-side validation is completed
* and is successfull, overrides default validator error messages updates.
* # OnError -- raised after client-side validation is completed
- * and failed, overrides default validator error message updates.
- *
+ * and failed, overrides default validator error message updates.
+ *
* You can attach custom javascript code to each of these events
- *
+ *
* @return TClientSideValidatorOptions javascript validator event options.
*/
public function getClientSide()
@@ -182,7 +204,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
$this->_clientSide = $this->createClientSideOptions();
return $this->_clientSide;
}
-
+
/**
* @return TClientSideValidatorOptions javascript validator event options.
*/
@@ -206,7 +228,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
if($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey))
{
$manager['FormID'] = $formID;
- $options = TJavaScript::encode($manager);
+ $options = TJavaScript::encode($manager);
$scripts->registerPradoScript('validator');
$scripts->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});");
}
@@ -493,22 +515,22 @@ abstract class TBaseValidator extends TLabel implements IValidator
/**
* TClientSideValidatorOptions 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 TClientSideValidatorOptions
* properties. The client-side validator supports the following events.
- *
+ *
* The OnValidate event is raise before the validator validation
* functions are called.
- *
+ *
* The OnSuccess event is raised after the validator has successfully
* validate the control.
- *
+ *
* The OnError event is raised after the validator fails validation.
- *
+ *
* See the quickstart documentation for further details.
- *
+ *
* @author Wei Zhuo
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
@@ -521,19 +543,19 @@ class TClientSideValidatorOptions extends TClientSideOptions
*/
public function getOnValidate()
{
- return $this->getOption('OnValidate');
+ return $this->getOption('OnValidate');
}
-
+
/**
* Client-side OnValidate validator event is raise before the validators
- * validation functions are called.
+ * validation functions are called.
* @param string javascript code for client-side OnValidate event.
*/
public function setOnValidate($javascript)
{
$this->setFunction('OnValidate', $javascript);
}
-
+
/**
* Client-side OnSuccess event is raise after validation is successfull.
* This will override the default client-side validator behaviour.
@@ -543,7 +565,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
{
$this->setFunction('OnSuccess', $javascript);
}
-
+
/**
* @return string javascript code for client-side OnSuccess event.
*/
@@ -551,7 +573,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
{
return $this->getOption('OnSuccess');
}
-
+
/**
* Client-side OnError event is raised after validation failure.
* This will override the default client-side validator behaviour.
@@ -561,7 +583,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
{
$this->setFunction('OnError', $javascript);
}
-
+
/**
* @return string javascript code for client-side OnError event.
*/
@@ -569,7 +591,7 @@ class TClientSideValidatorOptions extends TClientSideOptions
{
return $this->getOption('OnError');
}
-
+
/**
* Ensure the string is a valid javascript function. If the string begins
* with "javascript:" valid javascript function is assumed, otherwise the
@@ -583,4 +605,4 @@ class TClientSideValidatorOptions extends TClientSideOptions
}
}
-?>
\ No newline at end of file
+?>
diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php
index 59a71c90..a746437b 100644
--- a/framework/Web/UI/WebControls/TDatePicker.php
+++ b/framework/Web/UI/WebControls/TDatePicker.php
@@ -681,6 +681,18 @@ 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.
+ */
+ protected function publishIFrameSpacer()
+ {
+ $cs = $this->getPage()->getClientScript();
+ $spacer = 'System.Web.Javascripts.datepicker.spacer';
+ if(($file = Prado::getPathOfNamespace($spacer,'.gif')) != null)
+ return $this->publishFilePath($file);
+ }
/**
* Add the client id to the input textbox, and register the client scripts.
@@ -696,18 +708,24 @@ class TDatePicker extends TTextBox
/**
* Registers the javascript code to initialize the date picker.
- * Must use "Event.OnLoad" to initialize the date picker when the
- * full page is loaded, otherwise IE will throw an error.
*/
protected function registerCalendarClientScript()
{
if($this->getShowCalendar())
{
- $scripts = $this->getPage()->getClientScript();
- $scripts->registerPradoScript("datepicker");
+ $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 = "Event.OnLoad(function(){ new Prado.WebUI.TDatePicker($options); });";
- $scripts->registerEndScript("prado:".$this->getClientID(), $code);
+ $code = "new Prado.WebUI.TDatePicker($options);";
+ $cs->registerEndScript("prado:".$this->getClientID(), $code);
}
}
}
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index 57d8563a..42f09aad 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -502,6 +502,45 @@ abstract class TListControl extends TDataBoundControl
$this->_cachedSelectedValue=$value;
}
+
+ /**
+ * @return array list of the selected item values (strings)
+ */
+ public function getSelectedValues()
+ {
+ $values=array();
+ if($this->_items)
+ {
+ foreach($this->_items as $item)
+ {
+ if($item->getSelected())
+ $values[]=$item->getValue();
+ }
+ }
+ return $values;
+ }
+
+ /**
+ * @param array list of the selected item values
+ */
+ public function setSelectedValues($values)
+ {
+ if($this->_items)
+ {
+ $this->clearSelection();
+ $lookup=array();
+ foreach($this->_items as $item)
+ $lookup[$item->getValue()]=$item;
+ foreach($values as $value)
+ {
+ if(isset($lookup["$value"]))
+ $lookup["$value"]->setSelected(true);
+ else
+ throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value);
+ }
+ }
+ }
+
/**
* @return string selected value
*/
--
cgit v1.2.3