From ec46fdc945f591e910051aca0457097825afd34c Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 6 Dec 2005 22:53:07 +0000 Subject: --- framework/Web/Javascripts/base/prado.js | 21 ++++++++++ framework/Web/Javascripts/js/base.js | 17 ++++++++ framework/Web/UI/TClientScriptManager.php | 6 +++ framework/Web/UI/WebControls/TPanel.php | 66 ++++++++++++++++++++++++++++--- 4 files changed, 104 insertions(+), 6 deletions(-) (limited to 'framework/Web') diff --git a/framework/Web/Javascripts/base/prado.js b/framework/Web/Javascripts/base/prado.js index 81f51e41..b1e87634 100644 --- a/framework/Web/Javascripts/base/prado.js +++ b/framework/Web/Javascripts/base/prado.js @@ -1,3 +1,24 @@ Prado = Class.create(); Prado.version = '3.0a'; + +Prado.DefaultButton = Class.create(); + +Prado.DefaultButton.buttonFired = false; +Prado.DefaultButton.fire = function(event, target) +{ + if (!Prado.DefaultButton.buttonFired && event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) + { + var defaultButton = document.getElementById ? document.getElementById(target) : document.all[target]; + if (defaultButton && typeof(defaultButton.click) != "undefined") + { + Prado.DefaultButton.buttonFired = true; + defaultButton.click(); + event.cancelBubble = true; + if (event.stopPropagation) + event.stopPropagation(); + return false; + } + } + return true; +} diff --git a/framework/Web/Javascripts/js/base.js b/framework/Web/Javascripts/js/base.js index d16db163..1f86b1c1 100644 --- a/framework/Web/Javascripts/js/base.js +++ b/framework/Web/Javascripts/js/base.js @@ -841,6 +841,23 @@ return _7; Prado=Class.create(); Prado.version="3.0a"; +Prado.DefaultButton=Class.create(); +Prado.DefaultButton.buttonFired=false; +Prado.DefaultButton.fire=function(_1,_2){ +if(!Prado.DefaultButton.buttonFired&&_1.keyCode==13&&!(_1.srcElement&&(_1.srcElement.tagName.toLowerCase()=="textarea"))){ +var _3=document.getElementById?document.getElementById(_2):document.all[_2]; +if(_3&&typeof (_3.click)!="undefined"){ +Prado.DefaultButton.buttonFired=true; +_3.click(); +_1.cancelBubble=true; +if(_1.stopPropagation){ +_1.stopPropagation(); +} +return false; +} +} +return true; +}; Prado.doPostBack=function(_1,_2,_3,_4,_5,_6,_7,_8){ if(typeof (_4)=="undefined"){ diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 03ac8479..ace11064 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -195,6 +195,12 @@ class TClientScriptManager extends TComponent } } + public function registerDefaultButtonScript($button) + { + $this->registerScriptInclude('prado:base',$this->publishScriptFile('base.js')); + return 'return Prado.DefaultButton.fire(event,\''.$button->getClientID().'\')'; + } + public function registerValidationScript() { } diff --git a/framework/Web/UI/WebControls/TPanel.php b/framework/Web/UI/WebControls/TPanel.php index 5cdfa307..22e41c20 100644 --- a/framework/Web/UI/WebControls/TPanel.php +++ b/framework/Web/UI/WebControls/TPanel.php @@ -14,7 +14,20 @@ * TPanel class * * TPanel represents a component that acts as a container for other component. - * It is especially useful when you want to generate components programmatically or hide/show a group of components. + * It is especially useful when you want to generate components programmatically + * or hide/show a group of components. + * + * By default, TPanel displays a <div> element on a page. + * Children of TPanel are displayed as the body content of the element. + * The property {@link setWrap Wrap} can be used to set whether the body content + * should wrap or not. {@link setHorizontalAlign HorizontalAlign} governs how + * the content is aligned horizontally, and {@link getDirection Direction} indicates + * the content direction (left to right or right to left). You can set + * {@link setBackImageUrl BackImageUrl} to give a background image to the panel, + * and you can ste {@link setGroupingText GroupingText} so that the panel is + * displayed as a field set with a legend text. Finally, you can specify + * a default button to be fired when users press 'return' key within the panel + * by setting the {@link setDefaultButton DefaultButton} property. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -23,7 +36,11 @@ */ class TPanel extends TWebControl { + /** + * @var string ID path to the default button + */ private $_defaultButton=''; + /** * @return string tag name of the panel */ @@ -35,13 +52,20 @@ class TPanel extends TWebControl /** * Adds attributes to renderer. * @param THtmlWriter the renderer + * @throws TInvalidDataValueException if default button is not right. */ protected function addAttributesToRender($writer) { parent::addAttributesToRender($writer); if(($url=trim($this->getBackImageUrl()))!=='') $writer->addStyleAttribute('background-image','url('.$url.')'); - //this.AddScrollingAttribute(this.ScrollBars, writer); + switch($this->getScrollBars()) + { + case 'Horizontal': $writer->addStyleAttribute('overflow-x','scroll'); break; + case 'Vertical': $writer->addStyleAttribute('overflow-y','scroll'); break; + case 'Both': $writer->addStyleAttribute('overflow','scroll'); break; + case 'Auto': $writer->addStyleAttribute('overflow','auto'); break; + } if(($align=$this->getHorizontalAlign())!=='') $writer->addStyleAttribute('text-align',$align); if(!$this->getWrap()) @@ -51,9 +75,12 @@ class TPanel extends TWebControl if(($butt=$this->getDefaultButton())!=='') { if(($button=$this->findControl($butt))===null) - throw new TInvalidOperationException('panel_defaultbutton_invalid'); + throw new TInvalidDataValueException('panel_defaultbutton_invalid',$butt); else - $this->getPage()->getClientScript()->registerDefaultButtonScript($button,$writer); + { + $onkeypress=$this->getPage()->getClientScript()->registerDefaultButtonScript($button); + $writer->addAttribute('onkeypress',$onkeypress); + } } } @@ -75,7 +102,7 @@ class TPanel extends TWebControl } /** - * @return string the horizontal alignment of the contents within the panel. + * @return string the horizontal alignment of the contents within the panel, defaults to empty string (meaning not set). */ public function getHorizontalAlign() { @@ -128,11 +155,21 @@ class TPanel extends TWebControl $this->setViewState('Direction',$value,''); } + /** + * @return string the ID path to the default button. Defaults to empty. + */ public function getDefaultButton() { return $this->_defaultButton; } + /** + * Specifies the default button for the panel. + * The default button will be fired (clicked) whenever a user enters 'return' + * key within the panel. + * The button must be locatable via the function call {@link TControl::findControl findControl}. + * @param string the ID path to the default button. + */ public function setDefaultButton($value) { $this->_defaultButton=$value; @@ -154,6 +191,23 @@ class TPanel extends TWebControl $this->setViewState('GroupingText',$value,''); } + /** + * @return string the visibility and position of scroll bars in a panel control, defaults to None. + */ + public function getScrollBars() + { + return $this->getViewState('ScrollBars','None'); + } + + /** + * @param string the visibility and position of scroll bars in a panel control. + * Valid values include None, Auto, Both, Horizontal and Vertical. + */ + public function setScrollBars($value) + { + $this->setViewState('ScrollBars',TPropertyValue::ensureEnum($value,array('None','Auto','Both','Horizontal','Vertical')),'None'); + } + /** * Renders the openning tag for the control (including attributes) * @param THtmlWriter the writer used for the rendering purpose @@ -176,7 +230,7 @@ class TPanel extends TWebControl */ protected function renderEndTag($writer) { - if(($text=$this->getGroupingText())!=='') + if($this->getGroupingText()!=='') $writer->renderEndTag(); parent::renderEndTag($writer); } -- cgit v1.2.3