From 15f6747485b5912f657c2c0fce8f41c01c70d2ad Mon Sep 17 00:00:00 2001 From: "ctrlaltca@gmail.com" <> Date: Fri, 24 Jun 2011 22:12:36 +0000 Subject: merged in the patch for progressive rendering from #235; unit tests doesn't evidence any regression, but of course more proper testing is needed --- .../UI/ActiveControls/TActiveControlAdapter.php | 10 +++- framework/Web/UI/ActiveControls/TDraggable.php | 19 ++++-- framework/Web/UI/ActiveControls/TDropContainer.php | 13 ++++- framework/Web/UI/TClientScriptManager.php | 67 +++++++++++++++++++--- framework/Web/UI/TForm.php | 28 +++++---- framework/Web/UI/THtmlWriter.php | 3 +- framework/Web/UI/TPage.php | 27 ++++++++- framework/Web/UI/WebControls/TBaseValidator.php | 3 +- framework/Web/UI/WebControls/THtmlArea.php | 18 ++++-- 9 files changed, 154 insertions(+), 34 deletions(-) (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php index e8f947af..99c5e71e 100644 --- a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php +++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php @@ -75,6 +75,15 @@ class TActiveControlAdapter extends TControlAdapter $this->_activeControlType = $type; } + /** + * Publish the ajax script + */ + public function onPreRender($param) + { + parent::onPreRender($param); + $this->getPage()->getClientScript()->registerPradoScript('ajax'); + } + /** * Renders the callback client scripts. */ @@ -93,7 +102,6 @@ class TActiveControlAdapter extends TControlAdapter $key = 'Prado.CallbackRequest.addPostLoaders'; if(!$cs->isEndScriptRegistered($key)) { - $cs->registerPradoScript('ajax'); $data = $this->getPage()->getPostDataLoaders(); if(count($data) > 0) { diff --git a/framework/Web/UI/ActiveControls/TDraggable.php b/framework/Web/UI/ActiveControls/TDraggable.php index 34d8c548..10e78b9b 100755 --- a/framework/Web/UI/ActiveControls/TDraggable.php +++ b/framework/Web/UI/ActiveControls/TDraggable.php @@ -136,6 +136,20 @@ class TDraggable extends TPanel $this->setViewState('Constraint', TPropertyValue::ensureEnum($value, 'TDraggableConstraint'), TDraggableConstraint::None); } + /** + * Registers clientscripts + * + * This method overrides the parent implementation and is invoked before render. + * @param mixed event parameter + */ + public function onPreRender($param) + { + parent::onPreRender($param); + if ($this->getGhosting()==TDraggableGhostingOptions::SuperGhosting) + $cs->registerPradoScript('dragdropextra'); + else + $cs->registerPradoScript('dragdrop'); + } /** * Ensure that the ID attribute is rendered and registers the javascript code @@ -145,11 +159,6 @@ class TDraggable extends TPanel { parent::addAttributesToRender($writer); $writer->addAttribute('id',$this->getClientID()); - $cs=$this->getPage()->getClientScript(); - if ($this->getGhosting()==TDraggableGhostingOptions::SuperGhosting) - $cs->registerPradoScript('dragdropextra'); - else - $cs->registerPradoScript('dragdrop'); $options=TJavascript::encode($this->getPostBackOptions()); $class=$this->getClientClassName(); $code="new {$class}('{$this->getClientId()}', {$options}) "; diff --git a/framework/Web/UI/ActiveControls/TDropContainer.php b/framework/Web/UI/ActiveControls/TDropContainer.php index 915aa8f9..e6933147 100755 --- a/framework/Web/UI/ActiveControls/TDropContainer.php +++ b/framework/Web/UI/ActiveControls/TDropContainer.php @@ -172,6 +172,17 @@ class TDropContainer extends TPanel implements IActiveControl, ICallbackEventHan return 'Prado.WebUI.DropContainer'; } + /** + * Registers clientscripts + * + * This method overrides the parent implementation and is invoked before render. + * @param mixed event parameter + */ + public function onPreRender($param) + { + parent::onPreRender($param); + $this->getPage()->getClientScript()->registerPradoScript('dragdrop'); + } /** * Ensure that the ID attribute is rendered and registers the javascript code @@ -182,8 +193,6 @@ class TDropContainer extends TPanel implements IActiveControl, ICallbackEventHan parent::addAttributesToRender($writer); $writer->addAttribute('id',$this->getClientID()); - $this->getPage()->getClientScript()->registerPradoScript('dragdrop'); - $this->getActiveControl()->registerCallbackClientScript( $this->getClientClassName(), $this->getPostBackOptions()); } diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 8f246d3d..eec347eb 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -82,6 +82,12 @@ class TClientScriptManager extends TApplicationComponent */ private static $_pradoPackages; + private $_renderedHiddenFields; + + private $_renderedScriptFiles; + + private $_renderedPradoScripts; + /** * Constructor. * @param TPage page that owns this client script manager @@ -118,6 +124,7 @@ class TClientScriptManager extends TApplicationComponent */ private function registerPradoScriptInternal($name) { + // $this->checkIfNotInRender(); if(!isset($this->_registeredPradoScripts[$name])) { if(self::$_pradoScripts === null) @@ -149,9 +156,11 @@ class TClientScriptManager extends TApplicationComponent * Renders the HTML tags for PRADO js files * @param THtmlWriter writer */ - protected function renderPradoScripts($writer) + protected function renderPradoScriptsInt($writer, $initial) { - if(($packages=array_keys($this->_registeredPradoScripts))!==array()) + if($initial) $this->_renderedPradoScripts = array(); + $addedScripts = array_diff($this->_registeredPradoScripts,$this->_renderedPradoScripts); + if(($packages=array_keys($addedScripts))!==array()) { if (Prado::getApplication()->getMode()!==TApplicationMode::Debug) { @@ -178,6 +187,7 @@ class TClientScriptManager extends TApplicationComponent } $writer->write(TJavaScript::renderScriptFiles($packagesUrl)); } + $this->_renderedPradoScripts = $this->_registeredPradoScripts; } } @@ -420,6 +430,7 @@ class TClientScriptManager extends TApplicationComponent */ public function registerHeadScriptFile($key,$url) { + $this->checkIfNotInRender(); $this->_headScriptFiles[$key]=$url; $params=func_get_args(); @@ -433,6 +444,7 @@ class TClientScriptManager extends TApplicationComponent */ public function registerHeadScript($key,$script) { + $this->checkIfNotInRender(); $this->_headScripts[$key]=$script; $params=func_get_args(); @@ -446,6 +458,7 @@ class TClientScriptManager extends TApplicationComponent */ public function registerScriptFile($key,$url) { + $this->checkIfNotInRender(); $this->_scriptFiles[$key]=$url; $params=func_get_args(); @@ -459,6 +472,7 @@ class TClientScriptManager extends TApplicationComponent */ public function registerBeginScript($key,$script) { + $this->checkIfNotInRender(); $this->_beginScripts[$key]=$script; $params=func_get_args(); @@ -486,6 +500,7 @@ class TClientScriptManager extends TApplicationComponent */ public function registerHiddenField($name,$value) { + $this->checkIfNotInRender(); $this->_hiddenFields[$name]=$value; $params=func_get_args(); @@ -621,14 +636,30 @@ class TClientScriptManager extends TApplicationComponent $writer->write(TJavaScript::renderScriptBlocks($this->_headScripts)); } + public function renderScriptFilesBegin($writer) + { + $this->renderScriptFilesInt($writer,true); + } + + public function renderScriptFilesEnd($writer) + { + $this->renderScriptFilesInt($writer,false); + } + /** * @param THtmlWriter writer for the rendering purpose */ - public function renderScriptFiles($writer) + public function renderScriptFilesInt($writer, $initial) { - $this->renderPradoScripts($writer); + if ($initial) $this->_renderedScriptFiles = array(); + $this->renderPradoScriptsInt($writer, $initial); if(!empty($this->_scriptFiles)) - $writer->write(TJavaScript::renderScriptFiles($this->_scriptFiles)); + { + $addedScripts = array_diff($this->_scriptFiles,$this->_renderedScriptFiles); + if (count($addedScripts)>0) + $writer->write(TJavaScript::renderScriptFiles($addedScripts)); + $this->_renderedScriptFiles = $this->_scriptFiles; + } } /** @@ -647,14 +678,26 @@ class TClientScriptManager extends TApplicationComponent $writer->write(TJavaScript::renderScriptBlocks($this->_endScripts)); } + public function renderHiddenFieldsBegin($writer) + { + $this->renderHiddenFieldsInt($writer,true); + } + + public function renderHiddenFieldsEnd($writer) + { + $this->renderHiddenFieldsInt($writer,false); + } + /** * @param THtmlWriter writer for the rendering purpose */ - public function renderHiddenFields($writer) - { + protected function renderHiddenFieldsInt($writer, $initial) + { + if ($initial) $this->_renderedHiddenFields = array(); $str=''; foreach($this->_hiddenFields as $name=>$value) { + if (in_array($name,$this->_renderedHiddenFields)) continue; $id=strtr($name,':','_'); if(is_array($value)) { @@ -665,10 +708,20 @@ class TClientScriptManager extends TApplicationComponent { $str.='\n"; } + $this->_renderedHiddenFields[] = $name; } if($str!=='') $writer->write("
\n"); } + + /** + * Checks whether page rendering has not begun yet + */ + protected function checkIfNotInRender() + { + if ($form = $this->_page->InFormRender) + throw new Exception('Operation invalid when page is already rendering'); + } } /** diff --git a/framework/Web/UI/TForm.php b/framework/Web/UI/TForm.php index 561b59cb..f1e8df5a 100644 --- a/framework/Web/UI/TForm.php +++ b/framework/Web/UI/TForm.php @@ -4,7 +4,7 @@ * * @author Qiang Xue