From 407aa2ff5d56859fcd1f47b85b4c4180d035c428 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sat, 21 Jan 2006 02:07:59 +0000 Subject: Fixed DefaultButton and TLinkButton --- framework/Web/UI/TClientScriptManager.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'framework/Web/UI/TClientScriptManager.php') diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 535e85b2..be6611cd 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -1,6 +1,6 @@ _trackFocus=$value; } } - +*/ Prado::using('System.Web.Javascripts.*'); class TClientScriptManager extends TComponent @@ -133,6 +133,33 @@ class TClientScriptManager extends TComponent return $options->toJavascript(); } + /** + * 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 + */ + public function registerDefaultButton($panel, $button) + { + $serializer = new TJavascriptSerializer( + $this->getDefaultButtonOptions($panel, $button)); + $options = $serializer->toJavascript(); + $code = "new Prado.WebUI.DefaultButton($options);"; + $scripts = $this->_page->getClientScript(); + $scripts->registerEndScript("prado:".$panel->getClientID(), $code); + } + + /** + * @return array default button options. + */ + protected function getDefaultButtonOptions($panel, $button) + { + $options['Panel'] = $panel->getClientID(); + $options['Target'] = $button->getClientID(); + $options['Event'] = 'click'; + return $options; + } + /** * Register client scripts. -- cgit v1.2.3