summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorxue <>2006-06-11 22:01:52 +0000
committerxue <>2006-06-11 22:01:52 +0000
commitf30c38fcc9d6cdfa7aafa5078a58645192c11974 (patch)
tree51817c56b7295386e90fea5bf0f9fbd776a84bff /framework/Web
parent233ad780df391ed4af569929c30a1370d2b440ef (diff)
Prado js files are not rendered at the beginning of the form
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/UI/TClientScriptManager.php95
-rw-r--r--framework/Web/UI/TForm.php27
-rw-r--r--framework/Web/UI/TPage.php52
-rw-r--r--framework/Web/UI/WebControls/TImageButton.php2
-rw-r--r--framework/Web/UI/WebControls/TImageMap.php12
-rw-r--r--framework/Web/UI/WebControls/TListControl.php14
6 files changed, 97 insertions, 105 deletions
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index cab4d288..a4644e26 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -72,9 +72,9 @@ class TClientScriptManager extends TApplicationComponent
*/
private $_registeredPradoScripts=array();
/**
- * @var array registered PRADO script files
+ * @var array published PRADO script files
*/
- private $_registeredPradoFiles=array();
+ private $_publishedPradoFiles=array();
/**
* Client-side javascript library dependencies
* @var array
@@ -119,24 +119,24 @@ class TClientScriptManager extends TApplicationComponent
$this->registerPradoScriptInternal($name);
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerPradoScript',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerPradoScript',$params);
}
private function registerPradoScriptInternal($name)
{
if(!isset($this->_registeredPradoScripts[$name]))
{
- $this->_registeredPradoScripts[$name]=true;
- if(!isset(self::$_pradoScripts[$name]))
+ if(isset(self::$_pradoScripts[$name]))
+ $this->_registeredPradoScripts[$name]=true;
+ else
throw new TInvalidOperationException('csmanager_pradoscript_invalid',$name);
$basePath=Prado::getFrameworkPath().'/'.self::SCRIPT_PATH;
foreach(self::$_pradoScripts[$name] as $script)
{
- if(!isset($this->_registeredPradoFiles[$script]))
+ if(!isset($this->_publishedPradoFiles[$script]))
{
$this->publishFilePath($basePath.'/'.$script.'.js');
- $this->_registeredPradoFiles[$script]=false;
+ $this->_publishedPradoFiles[$script]=true;
}
}
}
@@ -144,15 +144,7 @@ class TClientScriptManager extends TApplicationComponent
protected function renderPradoScripts($writer)
{
- $files='';
- foreach($this->_registeredPradoFiles as $file=>$rendered)
- {
- if(!$rendered)
- {
- $files.=','.$file;
- $this->_registeredPradoFiles[$file]=true;
- }
- }
+ $files=implode(',',array_keys($this->_publishedPradoFiles));
if($files!=='')
{
$basePath=Prado::getFrameworkPath().'/'.self::SCRIPT_PATH;
@@ -189,8 +181,7 @@ class TClientScriptManager extends TApplicationComponent
$this->registerPradoScriptInternal('ajax');
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerCallbackControl',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerCallbackControl',$params);
}
/**
@@ -211,8 +202,7 @@ class TClientScriptManager extends TApplicationComponent
$this->registerPradoScriptInternal('prado');
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerPostBackControl',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerPostBackControl',$params);
}
/**
@@ -230,8 +220,7 @@ class TClientScriptManager extends TApplicationComponent
$this->registerPradoScriptInternal('prado');
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerDefaultButton',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerDefaultButton',$params);
}
/**
@@ -244,8 +233,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_endScripts['prado:focus']='Prado.Focus.setFocus("'.TJavaScript::quoteString($target).'");';
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerFocusControl',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerFocusControl',$params);
}
/**
@@ -271,8 +259,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_styleSheetFiles[$key]=$url;
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerStyleSheetFile',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerStyleSheetFile',$params);
}
/**
@@ -285,8 +272,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_styleSheets[$key]=$css;
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerStyleSheet',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerStyleSheet',$params);
}
/**
@@ -299,8 +285,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_headScriptFiles[$key]=$url;
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerHeadScriptFile',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerHeadScriptFile',$params);
}
/**
@@ -313,8 +298,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_headScripts[$key]=$script;
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerHeadScript',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerHeadScript',$params);
}
/**
@@ -327,8 +311,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_scriptFiles[$key]=$url;
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerScriptFile',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerScriptFile',$params);
}
/**
@@ -341,8 +324,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_beginScripts[$key]=$script;
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerBeginScript',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerBeginScript',$params);
}
/**
@@ -355,8 +337,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_endScripts[$key]=$script;
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerEndScript',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerEndScript',$params);
}
/**
@@ -370,8 +351,7 @@ class TClientScriptManager extends TApplicationComponent
$this->_hiddenFields[$name]=$value;
$params=func_get_args();
- foreach($this->_page->getCachingStack() as $item)
- $item->registerAction('Page.ClientScript','registerHiddenField',$params);
+ $this->_page->registerCachingAction('Page.ClientScript','registerHiddenField',$params);
}
/**
@@ -488,17 +468,8 @@ class TClientScriptManager extends TApplicationComponent
public function renderScriptFiles($writer)
{
$this->renderPradoScripts($writer);
- $files=array();
- foreach($this->_scriptFiles as $key=>$file)
- {
- if($file!==true)
- {
- $files[]=$file;
- $this->_scriptFiles[$key]=true;
- }
- }
- if(!empty($files))
- $writer->write(TJavaScript::renderScriptFiles($files));
+ if(!empty($this->_scriptFiles))
+ $writer->write(TJavaScript::renderScriptFiles($this->_scriptFiles));
}
/**
@@ -525,20 +496,14 @@ class TClientScriptManager extends TApplicationComponent
$str='';
foreach($this->_hiddenFields as $name=>$value)
{
- if($value!==true)
+ if(is_array($value))
{
- if(is_array($value))
- {
- foreach($value as $v)
- $str.='<input type="hidden" name="'.$name.'[]" id="'.$name.'" value="'.THttpUtility::htmlEncode($value)."\" />\n";
- }
- else
- {
- $str.='<input type="hidden" name="'.$name.'" id="'.$name.'" value="'.THttpUtility::htmlEncode($value)."\" />\n";
- }
- // set hidden field value to true to indicate this field is rendered
- // Note, hidden field rendering is invoked twice (at the beginning and ending of TForm)
- $this->_hiddenFields[$name]=true;
+ foreach($value as $v)
+ $str.='<input type="hidden" name="'.$name.'[]" id="'.$name.'" value="'.THttpUtility::htmlEncode($value)."\" />\n";
+ }
+ else
+ {
+ $str.='<input type="hidden" name="'.$name.'" id="'.$name.'" value="'.THttpUtility::htmlEncode($value)."\" />\n";
}
}
if($str!=='')
diff --git a/framework/Web/UI/TForm.php b/framework/Web/UI/TForm.php
index 948dea3e..e70d894a 100644
--- a/framework/Web/UI/TForm.php
+++ b/framework/Web/UI/TForm.php
@@ -70,12 +70,33 @@ class TForm extends TControl
*/
public function render($writer)
{
- $this->addAttributesToRender($writer);
- $writer->renderBeginTag('form');
$page=$this->getPage();
$page->beginFormRender($writer);
- $this->renderChildren($writer);
+ $textWriter=new TTextWriter;
+ $this->renderChildren(new THtmlWriter($textWriter));
+ $content=$textWriter->flush();
$page->endFormRender($writer);
+
+ $this->addAttributesToRender($writer);
+ $writer->renderBeginTag('form');
+
+ if($page->getClientSupportsJavaScript())
+ {
+ $cs=$page->getClientScript();
+ $cs->renderHiddenFields($writer);
+ $cs->renderScriptFiles($writer);
+ $cs->renderBeginScripts($writer);
+
+ $writer->write($content);
+
+ $cs->renderEndScripts($writer);
+ }
+ else
+ {
+ $cs->renderHiddenFields($writer);
+ $writer->write($content);
+ }
+
$writer->renderEndTag();
}
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 2337c20b..a1d64765 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -877,11 +877,7 @@ class TPage extends TTemplateControl
throw new TConfigurationException('page_form_duplicated');
$this->_formRendered=true;
$this->_inFormRender=true;
- $cs=$this->getClientScript();
- $cs->registerHiddenField(self::FIELD_PAGESTATE,$this->getClientState());
- //$cs->renderHiddenFields($writer);
- //$cs->renderScriptFiles($writer);
- $cs->renderBeginScripts($writer);
+ $this->getClientScript()->registerHiddenField(self::FIELD_PAGESTATE,$this->getClientState());
}
/**
@@ -889,25 +885,16 @@ class TPage extends TTemplateControl
*/
public function endFormRender($writer)
{
- $cs=$this->getClientScript();
- if($this->getClientSupportsJavaScript())
+ if($this->_focus)
{
- if($this->_focus)
- {
- if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true))
- $focus=$this->_focus->getClientID();
- else
- $focus=$this->_focus;
- $cs->registerFocusControl($focus);
- }
- else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null)
- $cs->registerFocusControl($lastFocus);
- $cs->renderHiddenFields($writer);
- $cs->renderScriptFiles($writer);
- $cs->renderEndScripts($writer);
+ if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true))
+ $focus=$this->_focus->getClientID();
+ else
+ $focus=$this->_focus;
+ $this->getClientScript()->registerFocusControl($focus);
}
- else
- $cs->renderHiddenFields($writer);
+ else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null)
+ $cs->registerFocusControl($lastFocus);
$this->_inFormRender=false;
}
@@ -1087,6 +1074,27 @@ class TPage extends TTemplateControl
$this->_pagePath=$value;
}
+ /**
+ * Registers an action associated with the content being cached.
+ * The registered action will be replayed if the content stored
+ * in the cache is served to end-users.
+ * @param string context of the action method. This is a property-path
+ * referring to the context object (e.g. Page, Page.ClientScript).
+ * @param string method name of the context object
+ * @param array list of parameters to be passed to the action method
+ */
+ public function registerCachingAction($context,$funcName,$funcParams)
+ {
+ if($this->_cachingStack)
+ {
+ foreach($this->_cachingStack as $cache)
+ $cache->registerAction($context,$funcName,$funcParams);
+ }
+ }
+
+ /**
+ * @return TStack stack of {@link TOutputCache} objects
+ */
public function getCachingStack()
{
if(!$this->_cachingStack)
diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php
index df8ace43..f7f6408a 100644
--- a/framework/Web/UI/WebControls/TImageButton.php
+++ b/framework/Web/UI/WebControls/TImageButton.php
@@ -88,7 +88,7 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven
if(($uniqueID=$this->getUniqueID())!=='')
$writer->addAttribute('name',$uniqueID);
if($this->getEnabled(true))
- $this->renderClientControlScript($writer);
+ $this->renderClientControlScript($writer);
else if($this->getEnabled()) // in this case, parent will not render 'disabled'
$writer->addAttribute('disabled','disabled');
parent::addAttributesToRender($writer);
diff --git a/framework/Web/UI/WebControls/TImageMap.php b/framework/Web/UI/WebControls/TImageMap.php
index be7bfea9..b6acf39e 100644
--- a/framework/Web/UI/WebControls/TImageMap.php
+++ b/framework/Web/UI/WebControls/TImageMap.php
@@ -94,6 +94,7 @@ class TImageMap extends TImage implements IPostBackEventHandler
$i=0;
$options['EventTarget'] = $this->getUniqueID();
$options['StopEvent'] = true;
+ $cs=$this->getPage()->getClientScript();
foreach($hotspots as $hotspot)
{
if($hotspot->getHotSpotMode()==='NotSet')
@@ -109,7 +110,7 @@ class TImageMap extends TImage implements IPostBackEventHandler
$options['EventParameter']="$i";
$options['CausesValidation']=$hotspot->getCausesValidation();
$options['ValidationGroup']=$hotspot->getValidationGroup();
- $cs->renderClientControlScript($writer,$options);
+ $cs->registerPostBackControl('Prado.WebUI.TImageMap',$options);
}
$hotspot->render($writer);
$writer->writeLine();
@@ -120,15 +121,6 @@ class TImageMap extends TImage implements IPostBackEventHandler
}
/**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer,$options)
- {
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl('Prado.WebUI.TImageMap',$options);
- }
-
- /**
* Raises the postback event.
* This method is required by {@link IPostBackEventHandler} interface.
* This method is mainly used by framework and control developers.
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index 2c42c462..ccb400dc 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -116,10 +116,7 @@ abstract class TListControl extends TDataBoundControl
if($this->getEnabled(true))
{
if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- {
- $writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
+ $this->renderClientControlScript($writer);
}
else if($this->getEnabled())
$writer->addAttribute('disabled','disabled');
@@ -127,6 +124,15 @@ abstract class TListControl extends TDataBoundControl
}
/**
+ * Renders the javascript for list control.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
* Gets the name of the javascript class responsible for performing postback for this control.
* This method overrides the parent implementation.
* @return string the javascript class name