diff options
Diffstat (limited to 'framework/Web/UI')
-rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 48 | ||||
-rw-r--r-- | framework/Web/UI/TControl.php | 10 |
2 files changed, 38 insertions, 20 deletions
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,24 +268,46 @@ 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 */ @@ -302,20 +324,6 @@ class TClientScriptManager extends TApplicationComponent } /** - * @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 * @param string URL to the CSS 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 @@ -415,6 +415,16 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable }
/**
+ * 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
*/
public function getSkinID()
|