summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/TJavaScript.php68
-rw-r--r--framework/Web/UI/TClientScriptManager.php30
-rw-r--r--framework/Web/UI/TPage.php209
-rw-r--r--framework/Web/UI/WebControls/THead.php6
4 files changed, 162 insertions, 151 deletions
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php
index 02dfdd6a..47d506fb 100644
--- a/framework/Web/Javascripts/TJavaScript.php
+++ b/framework/Web/Javascripts/TJavaScript.php
@@ -1,26 +1,25 @@
<?php
-
/**
- * TJavascript class file. Javascript utilties, converts basic PHP types into
- * appropriate javascript types.
- *
- * Example:
- * <code>
- * $options['onLoading'] = "doit";
- * $options['onComplete'] = "more";
- * $js = new TJavascriptSerializer($options);
- * echo $js->toMap();
- * //expects the following javascript code
- * // {'onLoading':'doit','onComplete':'more'}
- * </code>
+ * TJavaScript class file
*
- * For higher complexity data structures use TJSON to serialize and unserialize.
+ * @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.Javascripts
+ */
+
+/**
+ * TJavaScript class.
*
- * Namespace: System.Web.UI
+ * TJavaScript is a utility class containing commonly used javascript-related
+ * functions.
*
* @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.3 $ $Date: 2005/11/10 23:43:26 $
- * @package System.Web.UI
+ * @version $Revision: $ $Date: $
+ * @package System.Web.Javascripts
+ * @since 3.0
*/
class TJavaScript
{
@@ -72,7 +71,7 @@ class TJavaScript
return $str;
}
- public static function quoteJavaScriptString($js,$forUrl=false)
+ public static function quoteString($js,$forUrl=false)
{
if($forUrl)
return strtr($js,array('%'=>'%25',"\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\'));
@@ -80,18 +79,21 @@ class TJavaScript
return strtr($js,array("\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\'));
}
- public static function trimJavaScriptString($js)
- {
- if($js!=='' && $js!==null)
- {
- $js=trim($js);
- if(($pos=strpos($js,'javascript:'))===0)
- $js=substr($js,11);
- $js=rtrim($js,';').';';
- }
- return $js;
- }
-
+ /**
+ * Encodes a PHP variable into javascript representation.
+ *
+ * Example:
+ * <code>
+ * $options['onLoading'] = "doit";
+ * $options['onComplete'] = "more";
+ * $js = new TJavascriptSerializer($options);
+ * echo $js->toMap();
+ * //expects the following javascript code
+ * // {'onLoading':'doit','onComplete':'more'}
+ * </code>
+ *
+ * For higher complexity data structures use TJSON to serialize and unserialize.
+ */
public static function encode($value,$toMap=true)
{
if(is_string($value))
@@ -103,7 +105,7 @@ class TJavaScript
if(($first==='[' && $last===']') || ($first==='{' && $last==='}'))
return $value;
}
- return "'".self::quoteJavaScriptString($value)."'";
+ return "'".self::quoteString($value)."'";
}
else if(is_bool($value))
return $value?'true':'false';
@@ -142,13 +144,13 @@ class TJavaScript
return '';
}
- public static function encodeJSON($value)
+ public static function jsonEncode($value)
{
Prado::using('System.Web.Javascripts.TJSON');
return TJSON::encode($value);
}
- public static function decodeJSON($value)
+ public static function jsonDecode($value)
{
Prado::using('System.Web.Javascripts.TJSON');
return TJSON::decode($value);
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 180106ce..2fe67308 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -75,7 +75,6 @@ class TClientScriptManager extends TApplicationComponent
* @var array registered PRADO script files
*/
private $_registeredPradoFiles=array();
-
/**
* Client-side javascript library dependencies
* @var array
@@ -420,36 +419,11 @@ class TClientScriptManager extends TApplicationComponent
$writer->write("<div>\n".$str."</div>\n");
}
-/* public function registerClientEvent($control, $event, $code)
- {
- if(empty($code)) return;
- $this->registerPradoScript("prado");
- $script= "Event.observe('{$control->ClientID}', '{$event}', function(e){ {$code} });";
- $key = "prado:{$control->ClientID}:{$event}";
- $this->registerEndScript($key, $script);
- }
-
public function registerFocusScript($target)
{
- if(!$this->_focusScriptRegistered)
- {
- $this->_focusScriptRegistered=true;
- $this->registerPradoScript('prado');
- $this->registerEndScript('prado:focus','Prado.Focus.setFocus("'.THttpUtility::quoteJavaScriptString($target).'");');
- }
- }
-
- public function registerScrollScript($x,$y)
- {
- if(!$this->_scrollScriptRegistered)
- {
- $this->_scrollScriptRegistered=true;
- $this->registerHiddenField(TPage::FIELD_SCROLL_X,$x);
- $this->registerHiddenField(TPage::FIELD_SCROLL_Y,$y);
- // TBD, need scroll.js
- }
+ $this->registerPradoScript('prado');
+ $this->registerEndScript('prado:focus','Prado.Focus.setFocus("'.TJavaScript::quoteString($target).'");');
}
-*/
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 88606250..bbfca2fe 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -10,7 +10,6 @@
* @package System.Web.UI
*/
-//Prado::using('System.Web.UI.*');
Prado::using('System.Web.UI.WebControls.*');
Prado::using('System.Web.UI.TControl');
Prado::using('System.Web.UI.WebControls.TWebControl');
@@ -28,12 +27,15 @@ Prado::using('System.Web.UI.TClientScriptManager');
*/
class TPage extends TTemplateControl
{
+ /**
+ * system post fields
+ */
const FIELD_POSTBACK_TARGET='PRADO_POSTBACK_TARGET';
const FIELD_POSTBACK_PARAMETER='PRADO_POSTBACK_PARAMETER';
const FIELD_LASTFOCUS='PRADO_LASTFOCUS';
const FIELD_PAGESTATE='PRADO_PAGESTATE';
- const FIELD_SCROLLX='PRADO_SCROLLX';
- const FIELD_SCROLLY='PRADO_SCROLLY';
+ const FIELD_CALLBACK_ID='PRADO_CALLBACK_ID';
+ const FIELD_CALLBACK_PARAMETER='PRADO_CALLBACK_PARAMETER';
/**
* @var array system post fields
*/
@@ -42,9 +44,8 @@ class TPage extends TTemplateControl
'PRADO_POSTBACK_PARAMETER'=>true,
'PRADO_LASTFOCUS'=>true,
'PRADO_PAGESTATE'=>true,
- 'PRADO_SCROLLX'=>true,
- 'PRADO_SCROLLY'=>true,
- '__PREVPAGE','__CALLBACKID','__CALLBACKPARAM'
+ 'PRADO_CALLBACK_ID'=>true,
+ 'PRADO_CALLBACK_PARAMETER'=>true
);
/**
* @var TForm form instance
@@ -55,10 +56,6 @@ class TPage extends TTemplateControl
*/
private $_head=null;
/**
- * @var string template file name
- */
- private $_templateFile=null;
- /**
* @var array list of registered validators
*/
private $_validators=array();
@@ -103,11 +100,11 @@ class TPage extends TTemplateControl
*/
private $_postBackEventTarget=null;
/**
- * @var mixed postback event parameter
+ * @var string postback event parameter
*/
private $_postBackEventParameter=null;
/**
- * @var boolean whether form has rendered
+ * @var boolean whether the form has been rendered
*/
private $_formRendered=false;
/**
@@ -118,21 +115,26 @@ class TPage extends TTemplateControl
* @var TControl|string the control or the ID of the element on the page to be focused when the page is sent back to user
*/
private $_focus=null;
+ /**
+ * @var string page path to this page
+ */
private $_pagePath='';
/**
- * @var boolean whether or not to maintain page scroll position
+ * @var boolean whether page state should be HMAC validated
*/
- private $_maintainScrollPosition=false;
-
- private $_maxPageStateFieldLength=10;
- private $_enableViewStateMac=true;
- private $_isCrossPagePostBack=false;
- private $_previousPagePath='';
-
- private $_statePersisterClass='System.Web.UI.TPageStatePersister';
- private $_statePersister=null;
private $_enableStateValidation=true;
+ /**
+ * @var boolean whether page state should be encrypted
+ */
private $_enableStateEncryption=false;
+ /**
+ * @var string page state persister class name
+ */
+ private $_statePersisterClass='System.Web.UI.TPageStatePersister';
+ /**
+ * @var mixed page state persister
+ */
+ private $_statePersister=null;
/**
* Constructor.
@@ -146,7 +148,6 @@ class TPage extends TTemplateControl
/**
* Runs through the page lifecycles.
- * This method runs through the page lifecycles.
* @param THtmlTextWriter the HTML writer
*/
public function run($writer)
@@ -156,8 +157,10 @@ class TPage extends TTemplateControl
Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
$this->onPreInit(null);
+
Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
$this->initRecursive();
+
Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
$this->onInitComplete(null);
@@ -208,6 +211,14 @@ class TPage extends TTemplateControl
}
/**
+ * @return TForm the form on the page
+ */
+ public function getForm()
+ {
+ return $this->_form;
+ }
+
+ /**
* Registers a TForm instance to the page.
* Note, a page can contain at most one TForm instance.
* @param TForm the form on the page
@@ -222,14 +233,6 @@ class TPage extends TTemplateControl
}
/**
- * @return TForm the form on the page
- */
- public function getForm()
- {
- return $this->_form;
- }
-
- /**
* Returns a list of registered validators.
* If validation group is specified, only the validators in that group will be returned.
* @param string validation group
@@ -255,19 +258,27 @@ class TPage extends TTemplateControl
* Performs input validation.
* This method will invoke the registered validators to perform the actual validation.
* If validation group is specified, only the validators in that group will be invoked.
- * @param string validation group
+ * @param string validation group. If null, all validators will perform validation.
*/
- public function validate($validationGroup='')
+ public function validate($validationGroup=null)
{
+ Prado::trace("Page validate()",'System.Web.UI.TPage');
$this->_validated=true;
if($this->_validators && $this->_validators->getCount())
{
- Prado::trace("Page validate",'System.Web.UI.TPage');
- foreach($this->_validators as $validator)
+ if($validationGroup===null)
{
- if($validator->getValidationGroup()===$validationGroup)
+ foreach($this->_validators as $validator)
$validator->validate();
}
+ else
+ {
+ foreach($this->_validators as $validator)
+ {
+ if($validator->getValidationGroup()===$validationGroup)
+ $validator->validate();
+ }
+ }
}
}
@@ -306,7 +317,6 @@ class TPage extends TTemplateControl
/**
* Sets the theme to be used for the page.
* @param string|TTheme the theme name or the theme object to be used for the page.
- * @throws TInvalidDataTypeException if the parameter is neither a string nor a TTheme object
*/
public function setTheme($value)
{
@@ -327,7 +337,6 @@ class TPage extends TTemplateControl
/**
* Sets the stylesheet theme to be used for the page.
* @param string|TTheme the stylesheet theme name or the stylesheet theme object to be used for the page.
- * @throws TInvalidDataTypeException if the parameter is neither a string nor a TTheme object
*/
public function setStyleSheetTheme($value)
{
@@ -372,7 +381,7 @@ class TPage extends TTemplateControl
* You may override this method to provide additional initialization that
* should be done before {@link onInit OnInit} (e.g. setting {@link setTheme Theme} or
* {@link setStyleSheetTheme StyleSheetTheme}).
- * Remember to call the parent implementation to ensure PreInit event is raised.
+ * Remember to call the parent implementation to ensure OnPreInit event is raised.
* @param mixed event parameter
*/
public function onPreInit($param)
@@ -385,7 +394,7 @@ class TPage extends TTemplateControl
* This method is invoked right after {@link onInit OnInit} stage and before {@link onLoad OnLoad} stage.
* You may override this method to provide additional initialization that
* should be done after {@link onInit OnInit}.
- * Remember to call the parent implementation to ensure InitComplete event is raised.
+ * Remember to call the parent implementation to ensure OnInitComplete event is raised.
* @param mixed event parameter
*/
public function onInitComplete($param)
@@ -398,7 +407,7 @@ class TPage extends TTemplateControl
* This method is invoked right before {@link onLoad OnLoad} stage.
* You may override this method to provide additional page loading logic that
* should be done before {@link onLoad OnLoad}.
- * Remember to call the parent implementation to ensure PreLoad event is raised.
+ * Remember to call the parent implementation to ensure OnPreLoad event is raised.
* @param mixed event parameter
*/
public function onPreLoad($param)
@@ -411,7 +420,7 @@ class TPage extends TTemplateControl
* This method is invoked right after {@link onLoad OnLoad} stage.
* You may override this method to provide additional page loading logic that
* should be done after {@link onLoad OnLoad}.
- * Remember to call the parent implementation to ensure LoadComplete event is raised.
+ * Remember to call the parent implementation to ensure OnLoadComplete event is raised.
* @param mixed event parameter
*/
public function onLoadComplete($param)
@@ -424,7 +433,7 @@ class TPage extends TTemplateControl
* This method is invoked right after {@link onPreRender OnPreRender} stage.
* You may override this method to provide additional preparation for page rendering
* that should be done after {@link onPreRender OnPreRender}.
- * Remember to call the parent implementation to ensure PreRenderComplete event is raised.
+ * Remember to call the parent implementation to ensure OnPreRenderComplete event is raised.
* @param mixed event parameter
*/
public function onPreRenderComplete($param)
@@ -451,7 +460,7 @@ class TPage extends TTemplateControl
* Raises OnSaveStateComplete event.
* This method is invoked right after {@link onSaveState OnSaveState} stage.
* You may override this method to provide additional logic after page state is saved.
- * Remember to call the parent implementation to ensure SaveStateComplete event is raised.
+ * Remember to call the parent implementation to ensure OnSaveStateComplete event is raised.
* @param mixed event parameter
*/
public function onSaveStateComplete($param)
@@ -529,6 +538,9 @@ class TPage extends TTemplateControl
/**
* Registers a control for loading post data in the next postback.
+ * This method needs to be invoked if the control to load post data
+ * may not have a post variable in some cases. For example, a checkbox,
+ * if not checked, will not have a post value.
* @param TControl control registered for loading post data
*/
public function registerRequiresPostData(TControl $control)
@@ -560,17 +572,20 @@ class TPage extends TTemplateControl
}
/**
- * @return mixed postback event parameter
+ * @return string postback event parameter
*/
public function getPostBackEventParameter()
{
if($this->_postBackEventParameter===null)
- $this->_postBackEventParameter=$this->_postData->itemAt(self::FIELD_POSTBACK_PARAMETER);
+ {
+ if(($this->_postBackEventParameter=$this->_postData->itemAt(self::FIELD_POSTBACK_PARAMETER))===null)
+ $this->_postBackEventParameter='';
+ }
return $this->_postBackEventParameter;
}
/**
- * @param mixed postback event parameter
+ * @param string postback event parameter
*/
public function setPostBackEventParameter($value)
{
@@ -578,14 +593,6 @@ class TPage extends TTemplateControl
}
/**
- * Registers a control as the
- */
- public function registerAutoPostBackControl(TControl $control)
- {
- $this->_autoPostBackControl=$control;
- }
-
- /**
* Processes post data.
* @param TMap post data to be processed
* @param boolean whether this method is invoked before {@link onLoad OnLoad}.
@@ -638,7 +645,7 @@ class TPage extends TTemplateControl
}
/**
- * Raises OnPostBack event.
+ * Raises PostBack event.
*/
private function raisePostBackEvent()
{
@@ -656,16 +663,16 @@ class TPage extends TTemplateControl
public function ensureRenderInForm($control)
{
if(!$this->_inFormRender)
- throw new TConfigurationException('page_control_outofform',get_class($control),$control->getID(false));
+ throw new TConfigurationException('page_control_outofform',get_class($control),$control->getUniqueID());
}
/**
- * @internal This method is invoked by TForm at the beginning of its rendering
+ * @internal This method is invoked by TForm at the beginning of its rendering
*/
public function beginFormRender($writer)
{
if($this->_formRendered)
- throw new TConfigurationException('page_singleform_required');
+ throw new TConfigurationException('page_form_duplicated');
$this->_formRendered=true;
$this->_inFormRender=true;
$cs=$this->getClientScript();
@@ -690,15 +697,7 @@ class TPage extends TTemplateControl
}
else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null)
$cs->registerFocusScript($lastFocus);
- if($this->_maintainScrollPosition && $this->_postData)
- {
- $x=TPropertyValue::ensureInteger($this->_postData->itemAt(self::PRADO_SCROLLX));
- $y=TPropertyValue::ensureInteger($this->_postData->itemAt(self::PRADO_SCROLLY));
- $cs->registerScrollScript($x,$y);
- }
$cs->renderHiddenFields($writer);
- //$cs->renderArrayDeclarations($writer);
- //$cs->renderExpandoAttributes($writer);
$cs->renderScriptFiles($writer);
$cs->renderEndScripts($writer);
}
@@ -717,36 +716,28 @@ class TPage extends TTemplateControl
}
/**
- * @return boolean (TBD) whether to keep the page scroll position the same as users last see it
+ * @return boolean whether client supports javascript. Currently, this
+ * method always returns true. If future, we may add some browser capability
+ * detection functionality.
*/
- public function getMaintainScrollPosition()
- {
- return $this->_maintainScrollPosition;
- }
-
- /**
- * @param boolean (TBD) whether to keep the page scroll position the same as users last see it
- */
- public function setMaintainScrollPosition($value)
- {
- $this->_maintainScrollPosition=TPropertyValue::ensureBoolean($value);
- }
-
public function getClientSupportsJavaScript()
{
// todo
return true;
}
- protected function initializeCulture()
- {
- }
-
+ /**
+ * @return THead page head, null if not available
+ */
public function getHead()
{
return $this->_head;
}
+ /**
+ * @param THead page head
+ * @throws TInvalidOperationException if a head already exists
+ */
public function setHead(THead $value)
{
if($this->_head)
@@ -754,26 +745,41 @@ class TPage extends TTemplateControl
$this->_head=$value;
}
+ /**
+ * @return string page title.
+ */
public function getTitle()
{
return $this->getViewState('Title','');
}
+ /**
+ * @param string page title. This will override the title set in {@link getHead Head}.
+ */
public function setTitle($value)
{
$this->setViewState('Title',$value,'');
}
+ /**
+ * @return string class name of the page state persister. Defaults to TPageStatePersister.
+ */
public function getStatePersisterClass()
{
return $this->_statePersisterClass;
}
+ /**
+ * @param string class name of the page state persister.
+ */
public function setStatePersisterClass($value)
{
$this->_statePersisterClass=$value;
}
+ /**
+ * @return IPageStatePersister page state persister
+ */
public function getStatePersister()
{
if($this->_statePersister===null)
@@ -786,37 +792,66 @@ class TPage extends TTemplateControl
return $this->_statePersister;
}
+ /**
+ * @return boolean whether page state should be HMAC validated. Defaults to true.
+ */
public function getEnableStateValidation()
{
return $this->_enableStateValidation;
}
+ /**
+ * @param boolean whether page state should be HMAC validated.
+ */
public function setEnableStateValidation($value)
{
$this->_enableStateValidation=TPropertyValue::ensureBoolean($value);
}
+ /**
+ * @return boolean whether page state should be encrypted. Defaults to false.
+ */
public function getEnableStateEncryption()
{
return $this->_enableStateEncryption;
}
+ /**
+ * @param boolean whether page state should be encrypted.
+ */
public function setEnableStateEncryption($value)
{
$this->_enableStateEncryption=TPropertyValue::ensureBoolean($value);
}
+ /**
+ * @return string the requested page path for this page
+ */
public function getPagePath()
{
return $this->_pagePath;
}
+ /**
+ * @param string the requested page path for this page
+ */
public function setPagePath($value)
{
$this->_pagePath=$value;
}
}
+/**
+ * IPageStatePersister interface.
+ *
+ * IPageStatePersister interface is required for all page state persister
+ * classes.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.0
+ */
interface IPageStatePersister
{
/**
@@ -829,12 +864,12 @@ interface IPageStatePersister
public function setPage(TPage $page);
/**
* Saves state to persistent storage.
- * @param string state to be stored
+ * @param mixed state to be stored
*/
public function save($state);
/**
* Loads page state from persistent storage
- * @return string the restored state
+ * @return mixed the restored state
*/
public function load();
}
diff --git a/framework/Web/UI/WebControls/THead.php b/framework/Web/UI/WebControls/THead.php
index 3c52b666..3a949e34 100644
--- a/framework/Web/UI/WebControls/THead.php
+++ b/framework/Web/UI/WebControls/THead.php
@@ -7,7 +7,7 @@
* @copyright Copyright &copy; 2005 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
+ * @package System.Web.UI
*/
/**
@@ -30,7 +30,7 @@
*
* @author Marcus Nyeholt <tanus@users.sourceforge.net> and Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
+ * @package System.Web.UI
* @since 3.0
*/
class THead extends TControl
@@ -113,7 +113,7 @@ class THead extends TControl
$cs->renderStyleSheetFiles($writer);
$cs->renderStyleSheets($writer);
$cs->renderScriptFiles($writer);
- //$cs->renderHeadScripts($writer);
+ $cs->renderHeadScripts($writer);
parent::render($writer);
$writer->write("</head>\n");
}