summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorxue <>2005-12-06 22:53:07 +0000
committerxue <>2005-12-06 22:53:07 +0000
commitec46fdc945f591e910051aca0457097825afd34c (patch)
treeb79765ec299229678242267a7bfdf7e3c3f31349 /framework/Web
parent03142d666493516ca86dede5380344f8c05b7633 (diff)
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/base/prado.js21
-rw-r--r--framework/Web/Javascripts/js/base.js17
-rw-r--r--framework/Web/UI/TClientScriptManager.php6
-rw-r--r--framework/Web/UI/WebControls/TPanel.php66
4 files changed, 104 insertions, 6 deletions
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 &lt;div&gt; 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 <qiang.xue@gmail.com>
* @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;
@@ -155,6 +192,23 @@ class TPanel extends TWebControl
}
/**
+ * @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);
}