diff options
| -rw-r--r-- | .gitattributes | 4 | ||||
| -rw-r--r-- | HISTORY | 1 | ||||
| -rw-r--r-- | demos/quickstart/protected/pages/Controls/Conditional.page | 39 | ||||
| -rw-r--r-- | demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.page | 14 | ||||
| -rw-r--r-- | demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php | 7 | ||||
| -rw-r--r-- | demos/quickstart/protected/pages/Controls/Standard.page | 6 | ||||
| -rw-r--r-- | demos/quickstart/protected/pages/GettingStarted/NewFeatures.page | 1 | ||||
| -rw-r--r-- | framework/Exceptions/messages/messages.txt | 4 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TConditional.php | 142 | 
9 files changed, 216 insertions, 2 deletions
| diff --git a/.gitattributes b/.gitattributes index d8bbf559..38b0147b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1334,6 +1334,7 @@ demos/quickstart/protected/pages/Controls/CheckBox.page -text  demos/quickstart/protected/pages/Controls/ClientScript.page -text  demos/quickstart/protected/pages/Controls/ClientScriptLoader.page -text  demos/quickstart/protected/pages/Controls/ColorPicker.page -text +demos/quickstart/protected/pages/Controls/Conditional.page -text  demos/quickstart/protected/pages/Controls/Data.page -text  demos/quickstart/protected/pages/Controls/DataGrid.page -text  demos/quickstart/protected/pages/Controls/DataList.page -text @@ -1387,6 +1388,8 @@ demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page  demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php -text  demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page -text  demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php -text +demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.page -text +demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php -text  demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.page -text  demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.php -text  demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.page -text @@ -2526,6 +2529,7 @@ framework/Web/UI/WebControls/TClientScript.php -text  framework/Web/UI/WebControls/TClientScriptLoader.php -text  framework/Web/UI/WebControls/TColorPicker.php -text  framework/Web/UI/WebControls/TCompareValidator.php -text +framework/Web/UI/WebControls/TConditional.php -text  framework/Web/UI/WebControls/TContent.php -text  framework/Web/UI/WebControls/TContentPlaceHolder.php -text  framework/Web/UI/WebControls/TCustomValidator.php -text @@ -32,6 +32,7 @@ NEW: Added TKeyboard (Qiang)  NEW: Added TCaptcha and TCaptchaValidator (Qiang)  NEW: Added TCachePageStatePersister (Qiang)  NEW: Added TSlider (Christophe) +NEW: Added TConditional (Qiang)  NEW: Added Indonesian translation to QuickStart, requirements and error messages (Zaenal Mutaqin)  NEW: Added French translation to the blog tutorial (Eric Marchetti) diff --git a/demos/quickstart/protected/pages/Controls/Conditional.page b/demos/quickstart/protected/pages/Controls/Conditional.page new file mode 100644 index 00000000..e8ea4a65 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Conditional.page @@ -0,0 +1,39 @@ +<com:TContent ID="body" >
 +
 +<h1>TConditional</h1>
 +<com:DocLink ClassPath="System.Web.UI.WebControls.TConditional" />
 +
 +<p class="block-content">
 +<tt>TConditional</tt> displays appropriate content based on the evaluation result
 +of a PHP expression specified via <tt>Condition</tt>.
 +If the result is true, it instantiates the template <tt>TrueTemplate</tt>;
 +otherwise, the template <tt>FalseTemplate</tt> is instantiated.
 +The PHP expression is evaluated right before the <tt>onInit</tt> stage of the control lifecycle.
 +</p>
 +
 +<p class="block-content">
 +Since <tt>TConditional</tt> evaluates <tt>Condition</tt> at a very early stage, it is recommended
 +you set <tt>Condition</tt> in template only and the expression should not refer to
 +objects that are available on or after the <tt>onInit</tt> lifecycle.
 +</p>
 +
 +<p>
 +<tt>TConditional</tt> is very light. It instantiates either <tt>TrueTemplate</tt>
 +<tt>FalseTemplate</tt>, but never both. And the condition is evaluated only once.
 +A typical usage of TConditional is shown as following:
 +</p>
 +
 +<com:TTextHighlighter Language="prado" CssClass="source">
 +<com:TConditional Condition="$this->User->IsGuest">
 +	<prop:TrueTemplate>
 +		<a href="path/to/login">Login</a>
 +	</prop:TrueTemplate>
 +	<prop:FalseTemplate>
 +		<a href="path/to/logout">Logout</a>
 +	</prop:FalseTemplate>
 +</com:TConditional>
 +</com:TTextHighlighter>
 +
 +<com:RunBar PagePath="Controls.Samples.TConditional.Home" />
 +
 +<div class="last-modified">$Id$</div></com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.page new file mode 100644 index 00000000..0c099551 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.page @@ -0,0 +1,14 @@ +<com:TContent ID="body">
 +<h1>TConditional Samples</h1>
 +
 +<com:TConditional Condition="Prado::getVersion()==='3.1.1'">
 +<prop:TrueTemplate>
 +  <com:TLabel Text="You are using PRADO 3.1.1" />
 +</prop:TrueTemplate>
 +<prop:FalseTemplate>
 +  <com:TLabel Text="You are using PRADO <%= Prado::getVersion() %>" />
 +</prop:FalseTemplate>
 +</com:TConditional>
 +
 +<div class="last-modified">$Id$</div>
 +</com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php new file mode 100644 index 00000000..badbca73 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php @@ -0,0 +1,7 @@ +<?php
 +
 +class Home extends TPage
 +{
 +}
 +
 +?>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Standard.page b/demos/quickstart/protected/pages/Controls/Standard.page index 2b8dd7ab..3b6079d6 100644 --- a/demos/quickstart/protected/pages/Controls/Standard.page +++ b/demos/quickstart/protected/pages/Controls/Standard.page @@ -28,6 +28,10 @@    </li>
    <li>
 +  <a href="?page=Controls.Conditional">TConditional</a> displays content corresponding to true or false result of a PHP expression.
 +  </li>
 +
 +  <li>
    <a href="?page=Controls.DatePicker">TDatePicker</a> represents an input field taking date values via a calendar dialog.
    </li>
 @@ -122,7 +126,7 @@    <li>
    <a href="?page=Controls.Slider">TSlider</a> represents a Slider control
    </li>
 -  
 +
    <li>
    <a href="?page=Controls.Statements">TStatements</a> accepts a few PHP statements and displays their standard output on the Web page.
    </li>
 diff --git a/demos/quickstart/protected/pages/GettingStarted/NewFeatures.page b/demos/quickstart/protected/pages/GettingStarted/NewFeatures.page index 939dd139..adc19fc7 100644 --- a/demos/quickstart/protected/pages/GettingStarted/NewFeatures.page +++ b/demos/quickstart/protected/pages/GettingStarted/NewFeatures.page @@ -12,6 +12,7 @@ This page summarizes the main new features that are introduced in each PRADO rel  <li>Added a new control <a href="?page=Controls.Keyboard">TKeyboard</a> that displays a virtual keyboard for text input.</li>
  <li>Added a new control <a href="?page=Controls.Captcha">TCaptcha</a> that displays a CAPTCHA to keep spammers from signing up for certain accounts online. A related validator <tt>TCaptchaValidator</tt> is also implemented.</li>  <li>Added a new control <a href="?page=Controls.Slider">TSlider</a> that displays a slider which can be used for numeric input.</li>
 +<li>Added a new control <a href="?page=Controls.Conditional">TConditional</a> that conditionally displays one of the two kinds of content.</li>
  <li>Added Oracle DB support to Active Record.</li>
  <li>Added support to TDataGrid to allow grouping consecutive cells with the same content.</li>
  <li>Added support to allow configuring page properties and authorization rules using <a href="?page=Configurations.PageConfig">relative page paths</a> in application and page configurations. Added support to allow <a href="?page=Advanced.Auth">authorization</a> based on remote host address.</li>
 diff --git a/framework/Exceptions/messages/messages.txt b/framework/Exceptions/messages/messages.txt index a105f359..086bdb06 100644 --- a/framework/Exceptions/messages/messages.txt +++ b/framework/Exceptions/messages/messages.txt @@ -449,4 +449,6 @@ slider_handle_class_invalid				= TSlider.HandleClass '{0}' is not a valid user c  cachepagestatepersister_cachemoduleid_invalid = TCachePageStatePersister.CacheModuleID '{0}' does not point to a valid cache module.  cachepagestatepersister_cache_required  = TCachePageStatePersister requires a cache module to be loaded.  cachepagestatepersister_timeout_invalid = TCachePageStatePersister.Timeout must be an integer no less than zero. -cachepagestatepersister_pagestate_corrupted = Page state is corrupted.
\ No newline at end of file +cachepagestatepersister_pagestate_corrupted = Page state is corrupted. + +conditional_condition_invalid			= TConditional.Condition '{0}' is not a valid PHP expression: {1}
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TConditional.php b/framework/Web/UI/WebControls/TConditional.php new file mode 100644 index 00000000..70eedf6d --- /dev/null +++ b/framework/Web/UI/WebControls/TConditional.php @@ -0,0 +1,142 @@ +<?php
 +/**
 + * TConditional class file.
 + *
 + * @author Qiang Xue <qiang.xue@gmail.com>
 + * @link http://www.pradosoft.com/
 + * @copyright Copyright © 2005-2007 PradoSoft
 + * @license http://www.pradosoft.com/license/
 + * @version $Id$
 + * @package System.Web.UI.WebControls
 + */
 +
 +/**
 + * TConditional class.
 + *
 + * TConditional displays appropriate content based on the evaluation result
 + * of a PHP expression specified via {@link setCondition Condition}.
 + * If the result is true, it instantiates the template {@link getTrueTemplate TrueTemplate};
 + * otherwise, the template {@link getFalseTemplate FalseTemplate} is instantiated.
 + * The PHP expression is evaluated right before {@link onInit} stage of the control lifecycle.
 + *
 + * Since {@link setCondition Condition} is evaluated at a very early stage, it is recommended
 + * you set {@link setCondition Condition} in template and the expression should not refer to
 + * objects that are available on or after {@link onInit} lifecycle.
 + *
 + * A typical usage of TConditional is shown as following:
 + * <code>
 + * <com:TConditional Condition="$this->User->IsGuest">
 + *   <prop:TrueTemplate>
 + *     <a href="path/to/login">Login</a>
 + *   </prop:TrueTemplate>
 + *   <prop:FalseTemplate>
 + *     <a href="path/to/logout">Logout</a>
 + *   </prop:FalseTemplate>
 + * </com:TConditional>
 + * </code>
 + *
 + * TConditional is very light. It instantiates either {@link getTrueTemplate TrueTemplate}
 + * or {@link getFalseTemplate FalseTemplate}, but never both. And the condition is evaluated only once.
 + *
 + * @author Qiang Xue <qiang.xue@gmail.com>
 + * @version $Id$
 + * @package System.Web.UI.WebControls
 + * @since 3.1.1
 + */
 +class TConditional extends TControl
 +{
 +	private $_condition='true';
 +	private $_trueTemplate;
 +	private $_falseTemplate;
 +	private $_creatingChildren=false;
 +
 +	/**
 +	 * Processes an object that is created during parsing template.
 +	 * This method overrides the parent implementation by removing
 +	 * all contents enclosed in the template tag.
 +	 * @param string|TComponent text string or component parsed and instantiated in template
 +	 * @see createdOnTemplate
 +	 */
 +	public function addParsedObject($object)
 +	{
 +		if($this->_creatingChildren)
 +			parent::addParsedObject($object);
 +	}
 +
 +	/**
 +	 * Creates child controls.
 +	 * This method overrides the parent implementation. It evaluates {@link getCondition Condition}
 +	 * and instantiate the corresponding template.
 +	 */
 +	public function createChildControls()
 +	{
 +		$this->_creatingChildren=true;
 +		$result=true;
 +		try
 +		{
 +			$result=$this->evaluateExpression($this->_condition);
 +		}
 +		catch(Exception $e)
 +		{
 +			throw new TInvalidDataValueException('conditional_condition_invalid',$this->_condition,$e->getMessage());
 +		}
 +		if($result)
 +		{
 +			if($this->_trueTemplate)
 +				$this->_trueTemplate->instantiateIn($this);
 +		}
 +		else if($this->_falseTemplate)
 +			$this->_falseTemplate->instantiateIn($this);
 +		$this->_creatingChildren=false;
 +	}
 +
 +	/**
 +	 * @return string the PHP expression used for determining which template to use. Defaults to 'true', meaning using TrueTemplate.
 +	 */
 +	public function getCondition()
 +	{
 +		return $this->_condition;
 +	}
 +
 +	/**
 +	 * @param string the PHP expression used for determining which template to use.
 +	 */
 +	public function setCondition($value)
 +	{
 +		$this->_condition=TPropertyValue::ensureString($value);
 +	}
 +
 +	/**
 +	 * @return ITemplate the template applied when {@link getCondition Condition} is true.
 +	 */
 +	public function getTrueTemplate()
 +	{
 +		return $this->_trueTemplate;
 +	}
 +
 +	/**
 +	 * @param ITemplate the template applied when {@link getCondition Condition} is true.
 +	 */
 +	public function setTrueTemplate(ITemplate $value)
 +	{
 +		$this->_trueTemplate=$value;
 +	}
 +
 +	/**
 +	 * @return ITemplate the template applied when {@link getCondition Condition} is false.
 +	 */
 +	public function getFalseTemplate()
 +	{
 +		return $this->_falseTemplate;
 +	}
 +
 +	/**
 +	 * @param ITemplate the template applied when {@link getCondition Condition} is false.
 +	 */
 +	public function setFalseTemplate(ITemplate $value)
 +	{
 +		$this->_falseTemplate=$value;
 +	}
 +}
 +
 +?>
\ No newline at end of file | 
