From 6801f262e4955fcb7fa48bc88ef64df786f0c650 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 3 Nov 2013 19:33:34 +0100 Subject: Fixed evaluation of end-scripts on callback Aka: fix js event creation on callbacks --- framework/Web/Javascripts/TJavaScript.php | 13 +++++++++++++ framework/Web/Javascripts/source/prado/prado.js | 10 +++++++++- framework/Web/UI/ActiveControls/TActivePageAdapter.php | 2 +- .../Web/UI/ActiveControls/TCallbackClientScript.php | 11 ++++++++++- framework/Web/UI/TClientScriptManager.php | 16 ++++++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) (limited to 'framework/Web') diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php index 0f6fef1c..8cfbc9ba 100644 --- a/framework/Web/Javascripts/TJavaScript.php +++ b/framework/Web/Javascripts/TJavaScript.php @@ -59,6 +59,19 @@ class TJavaScript return ''; } + /** + * Renders a list of javascript code + * @param array javascript blocks + * @return string rendering result + */ + public static function renderScriptBlocksCallback($scripts) + { + if(count($scripts)) + return implode("\n",$scripts)."\n"; + else + return ''; + } + /** * Renders javascript block * @param string javascript block diff --git a/framework/Web/Javascripts/source/prado/prado.js b/framework/Web/Javascripts/source/prado/prado.js index 6cc30c2c..25550bca 100644 --- a/framework/Web/Javascripts/source/prado/prado.js +++ b/framework/Web/Javascripts/source/prado/prado.js @@ -524,9 +524,17 @@ Prado.Element = * Evaluate a javascript snippet from a string. * @function ? * @param {string} content - String containing the script + * @param {string} boundary - Boundary containing the script */ - evaluateScript : function(content) + evaluateScript : function(content, boundary) { + if(boundary) + { + var result = this.extractContent(boundary); + if(result != null) + content = result; + } + try { jQuery.globalEval(content); diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php index 03fe2f16..c594ed42 100644 --- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php +++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php @@ -198,7 +198,7 @@ class TActivePageAdapter extends TControlAdapter if($this->getPage()->getClientScript()->hasEndScripts()) { $writer = $response->createHtmlWriter(); - $this->getPage()->getClientScript()->renderEndScripts($writer); + $this->getPage()->getClientScript()->renderEndScriptsCallback($writer); $this->getPage()->getCallbackClient()->evaluateScript($writer); } diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php index a25e7f41..96c8d38e 100644 --- a/framework/Web/UI/ActiveControls/TCallbackClientScript.php +++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php @@ -452,7 +452,16 @@ class TCallbackClientScript extends TApplicationComponent */ public function evaluateScript($writer) { - $this->callClientFunction('Prado.Element.evaluateScript', array($writer)); + if($writer instanceof THtmlWriter) + { + $boundary = $this->getResponseContentBoundary($writer); + $content = null; + } else { + $boundary = null; + $content = $writer; + } + + $this->callClientFunction('Prado.Element.evaluateScript', array($content, $boundary)); } /** diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 5f9ea8b4..80a71ea0 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -697,6 +697,22 @@ class TClientScriptManager extends TApplicationComponent $writer->write(TJavaScript::renderScriptBlocks($this->_endScripts)); } + /** + * @param THtmlWriter writer for the rendering purpose + */ + public function renderBeginScriptsCallback($writer) + { + $writer->write(TJavaScript::renderScriptBlocksCallback($this->_beginScripts)); + } + + /** + * @param THtmlWriter writer for the rendering purpose + */ + public function renderEndScriptsCallback($writer) + { + $writer->write(TJavaScript::renderScriptBlocksCallback($this->_endScripts)); + } + public function renderHiddenFieldsBegin($writer) { $this->renderHiddenFieldsInt($writer,true); -- cgit v1.2.3