From fb16cd829679f1459d3a6541d1bd4997c0c96d29 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 19 Jun 2007 19:07:57 +0000 Subject: Fixed the bug that causes TOutputCache to crash when a default button is set --- HISTORY | 1 + framework/Web/UI/TClientScriptManager.php | 48 ++++++++++++++++++------------- framework/Web/UI/TControl.php | 10 +++++++ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/HISTORY b/HISTORY index ad24ad3c..71f2fa86 100644 --- a/HISTORY +++ b/HISTORY @@ -7,6 +7,7 @@ BUG: Ticket#651 - TUserManager Roles names (from config) should be trimmed (Qian BUG: Ticket#652 - OFFSET must be specified together with LIMIT for TScaffoldView (Qiang) BUG: Ticket#653 - TUrlMapping: ServiceId irgnored in URL-Map (Qiang) BUG: TWizard Sidebar using TDataListItemRenderer has error (Qiang) +BUG: TOutputCache crashes when a default button is set (Qiang) BUG: Ticket#654 - TAssetManager::copyDirectory() do not run closedir on an invalid resource (Knut) BUG: Ticket#655 - TAssetManager::publishTarFile() exception for 'assetmanager_tarchecksum_invalid' is not thrown on BSD systems (Knut) ENH: Ticket#625 - Added @ to represent authenticated users in auth rules (Qiang) diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 817127f0..efb8ec17 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -268,23 +268,45 @@ class TClientScriptManager extends TApplicationComponent /** * Register a default button to panel. When the $panel is in focus and * the 'enter' key is pressed, the $button will be clicked. - * @param TControl panel to register the default button action - * @param TControl button to trigger a postback + * @param TControl|string panel (or its unique ID) to register the default button action + * @param TControl|string button (or its unique ID) to trigger a postback */ public function registerDefaultButton($panel, $button) { - $button->setIsDefaultButton(true); - $options = TJavaScript::encode($this->getDefaultButtonOptions($panel, $button)); + $panelID=is_string($panel)?$panel:$panel->getUniqueID(); + + if(is_string($button)) + $buttonID=$button; + else + { + $button->setIsDefaultButton(true); + $buttonID=$button->getUniqueID(); + } + $options = TJavaScript::encode($this->getDefaultButtonOptions($panelID, $buttonID)); $code = "new Prado.WebUI.DefaultButton($options);"; - $this->_endScripts['prado:'.$panel->getClientID()]=$code; + $this->_endScripts['prado:'.$panelID]=$code; $this->_hiddenFields[TPage::FIELD_POSTBACK_TARGET]=''; $this->registerPradoScriptInternal('prado'); - $params=func_get_args(); + $params=array($panelID,$buttonID); $this->_page->registerCachingAction('Page.ClientScript','registerDefaultButton',$params); } + /** + * @param string the unique ID of the container control + * @param string the unique ID of the button control + * @return array default button options. + */ + protected function getDefaultButtonOptions($panelID, $buttonID) + { + $options['Panel'] = TControl::convertUniqueIdToClientId($panelID); + $options['Target'] = TControl::convertUniqueIdToClientId($buttonID); + $options['EventTarget'] = $buttonID; + $options['Event'] = 'click'; + return $options; + } + /** * Registers the control to receive default focus. * @param string the client ID of the control to receive default focus @@ -301,20 +323,6 @@ class TClientScriptManager extends TApplicationComponent $this->_page->registerCachingAction('Page.ClientScript','registerFocusControl',$params); } - /** - * @param TControl container control - * @param IButtonControl button control - * @return array default button options. - */ - protected function getDefaultButtonOptions($panel, $button) - { - $options['Panel'] = $panel->getClientID(); - $options['Target'] = $button->getClientID(); - $options['EventTarget'] = $button->getUniqueID(); - $options['Event'] = 'click'; - return $options; - } - /** * Registers a CSS file to be rendered in the page head * @param string a unique key identifying the file diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index dcfcec65..bb4874ab 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -414,6 +414,16 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable return strtr($this->getUniqueID(),self::ID_SEPARATOR,self::CLIENT_ID_SEPARATOR); } + /** + * Converts a unique ID to a client ID. + * @param string the unique ID of a control + * @return string the client ID of the control + */ + public static function convertUniqueIdToClientId($uniqueID) + { + return strtr($uniqueID,self::ID_SEPARATOR,self::CLIENT_ID_SEPARATOR); + } + /** * @return string the skin ID of this control, '' if not set */ -- cgit v1.2.3