summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php111
-rw-r--r--framework/Web/UI/WebControls/TClientScript.php75
-rw-r--r--framework/Web/UI/WebControls/TLiteral.php2
3 files changed, 187 insertions, 1 deletions
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index adbc85ae..4ca4c1f6 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -41,6 +41,10 @@
* and {@link setText Text} are empty, the body content of the validator will
* be displayed. Error display is controlled by {@link setDisplay Display} property.
*
+ * You can also customized the client-side behaviour by adding javascript
+ * code to the subproperties of the {@link getClientValidation ClientValidation}
+ * property.
+ *
* You can also place a {@link TValidationSummary} control on a page to display error messages
* from the validators together. In this case, only the {@link setErrorMessage ErrorMessage}
* property of the validators will be displayed in the {@link TValidationSummary} control.
@@ -75,6 +79,8 @@ abstract class TBaseValidator extends TLabel implements IValidator
* @var boolean whether the validator has been registered with the page
*/
private $_registered=false;
+
+ private $_clientScript;
/**
* Constructor.
@@ -145,8 +151,43 @@ abstract class TBaseValidator extends TLabel implements IValidator
$options['ControlToValidate'] = $control->getClientID();
$options['ControlCssClass'] = $this->getControlCssClass();
$options['ControlType'] = get_class($control);
+
+ if(!is_null($this->_clientScript))
+ $options = array_merge($options,$this->_clientScript->getOptions());
+
return $options;
}
+
+ /**
+ * Gets the TValidatorClientScript that allows modification of the client-
+ * side validator events.
+ *
+ * The client-side validator supports the following events.
+ * # <tt>OnValidate</tt> -- raised before client-side validation is
+ * executed.
+ * # <tt>OnSuccess</tt> -- raised after client-side validation is completed
+ * and is successfull, overrides default validator error messages updates.
+ * # <tt>OnError</tt> -- raised after client-side validation is completed
+ * and failed, overrides default validator error message updates.
+ *
+ * You can attach custom javascript code to each of these events
+ *
+ * @return TValidatorClientScript javascript validator event options.
+ */
+ public function getClientValidation()
+ {
+ if(is_null($this->_clientScript))
+ $this->_clientScript = $this->createClientScript();
+ return $this->_clientScript;
+ }
+
+ /**
+ * @return TValidatorClientScript javascript validator event options.
+ */
+ protected function createClientScript()
+ {
+ return new TValidatorClientScript($this->getPage()->getClientScript());
+ }
/**
* Renders the javascript code to the end script.
@@ -446,4 +487,74 @@ abstract class TBaseValidator extends TLabel implements IValidator
parent::renderContents($writer);
}
}
+
+/**
+ * TValidatorClientScript class.
+ *
+ * @todo Add doc to quickstart and classes.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TValidatorClientScript extends TComponent
+{
+ private $_options;
+ private $_manager;
+ private $_effectsEnabled = false;
+
+ public function __construct($manager)
+ {
+ $this->_options = new TMap;
+ $this->_manager = $manager;
+ }
+
+ public function getOnValidate()
+ {
+ return $this->_options->itemAt['OnValidate'];
+ }
+
+ public function setOnValidate($javascript)
+ {
+ $this->_options->add('OnValidate', $this->ensureFunction($javascript));
+ }
+
+ public function setOnSuccess($javascript)
+ {
+ $this->_options->add('OnSuccess', $this->ensureFunction($javascript));
+ }
+
+ public function getOnSuccess()
+ {
+ return $this->_options->itemAt('OnSuccess');
+ }
+
+ public function setOnError($javascript)
+ {
+ $this->_options->add('OnError', $this->ensureFunction($javascript));
+ }
+
+ public function getOnError()
+ {
+ return $this->_options->itemAt('OnError');
+ }
+
+ public function getOptions()
+ {
+ return $this->_options->toArray();
+ }
+
+ private function ensureFunction($javascript)
+ {
+ if(TJavascript::isFunction($javascript))
+ return $javascript;
+ else
+ {
+ $code = "function(validator, invoker){ {$javascript} }";
+ return TJavascript::quoteFunction($code);
+ }
+ }
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TClientScript.php b/framework/Web/UI/WebControls/TClientScript.php
new file mode 100644
index 00000000..23aa1425
--- /dev/null
+++ b/framework/Web/UI/WebControls/TClientScript.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * TClientScript class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TClientScript class
+ *
+ * Allows importing of Prado Client Scripts from template via the
+ * {@link setUsingPradoScripts UsingPradoScripts} property. Multiple Prado
+ * client-scripts can be specified using comma delimited string of the
+ * javascript library to include on the page. For example,
+ *
+ * <code>
+ * <com:TClientScript UsingPradoScripts="effects, rico" />
+ * </code>
+ *
+ * @TODO May be use it to include stylesheets as well.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TClientScript extends TControl
+{
+ /**
+ * @return string comma delimited list of javascript libraries to included
+ * on the page.
+ */
+ public function getUsingPradoScripts()
+ {
+ return $this->getViewState('PradoScripts', '');
+ }
+
+ /**
+ * Include javascript library to the current page. The current supported
+ * libraries are: "prado", "effects", "ajax", "validator", "logger",
+ * "datepicker", "rico", "colorpicker". Library dependencies are
+ * automatically resolved.
+ *
+ * @param string comma delimited list of javascript libraries to include.
+ */
+ public function setUsingPradoScripts($value)
+ {
+ $this->setViewState('PradoScripts', $value, '');
+ }
+
+ /**
+ * Calls the client script manager to add each of the requested client
+ * script libraries.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $scripts = preg_split('/,|\s+/', $this->getUsingPradoScripts());
+ $cs = $this->getPage()->getClientScript();
+ foreach($scripts as $script)
+ {
+ $script = trim($script);
+ if(strlen($script) > 0)
+ $cs->registerPradoScript($script);
+ }
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TLiteral.php b/framework/Web/UI/WebControls/TLiteral.php
index f335499f..60e4a6f6 100644
--- a/framework/Web/UI/WebControls/TLiteral.php
+++ b/framework/Web/UI/WebControls/TLiteral.php
@@ -80,7 +80,7 @@ class TLiteral extends TControl
$writer->write($text);
}
else
- parent::renderContents($writer);
+ parent::render($writer);
}
}