diff options
| author | xue <> | 2005-12-06 22:53:07 +0000 | 
|---|---|---|
| committer | xue <> | 2005-12-06 22:53:07 +0000 | 
| commit | ec46fdc945f591e910051aca0457097825afd34c (patch) | |
| tree | b79765ec299229678242267a7bfdf7e3c3f31349 | |
| parent | 03142d666493516ca86dede5380344f8c05b7633 (diff) | |
| -rw-r--r-- | demos/controls/protected/pages/LoginPage.php | 5 | ||||
| -rw-r--r-- | demos/controls/protected/pages/LoginPage.tpl | 3 | ||||
| -rw-r--r-- | framework/Exceptions/messages.txt | 4 | ||||
| -rw-r--r-- | framework/TComponent.php | 4 | ||||
| -rw-r--r-- | framework/Web/Javascripts/base/prado.js | 21 | ||||
| -rw-r--r-- | framework/Web/Javascripts/js/base.js | 17 | ||||
| -rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 6 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TPanel.php | 66 | 
8 files changed, 116 insertions, 10 deletions
diff --git a/demos/controls/protected/pages/LoginPage.php b/demos/controls/protected/pages/LoginPage.php index 3b5cc3f9..f29ed540 100644 --- a/demos/controls/protected/pages/LoginPage.php +++ b/demos/controls/protected/pages/LoginPage.php @@ -10,6 +10,11 @@ class LoginPage extends TPage  		else
  			$this->error->Text='login failed';
  	}
 +
 +	public function defaultClicked($sender,$param)
 +	{
 +		$sender->Text="Clicked";
 +	}
  }
  ?>
\ No newline at end of file diff --git a/demos/controls/protected/pages/LoginPage.tpl b/demos/controls/protected/pages/LoginPage.tpl index db687e00..0030dfb2 100644 --- a/demos/controls/protected/pages/LoginPage.tpl +++ b/demos/controls/protected/pages/LoginPage.tpl @@ -2,13 +2,14 @@  <com:TContent id="body" >
  <com:TForm>
  <div>
 -<com:TPanel GroupingText="Login" Width="270px" HorizontalAlign="center">
 +<com:TPanel DefaultButton="defButton" GroupingText="Login" Width="270px" HorizontalAlign="center" ScrollBars="Both">
  <com:TLabel Text="Username" AssociatedControlID="username"/>
  <com:TTextBox ID="username" /><br/>
  <com:TLabel Text="Password" AssociatedControlID="password"/>
  <com:TTextBox ID="password" TextMode="Password" /><br/>
  <com:TButton Text="Login" Click="login" />
  <com:TLabel ID="error" />
 +<com:TButton ID="defButton" Text="Default Button" Click="defaultClicked" />
  </com:TPanel>
  </div>
  </com:TForm>
 diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index e706ebbf..b55e536c 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -139,4 +139,6 @@ label_associatedcontrol_invalid			= TLabel.AssociatedControl '%s' cannot be foun  hiddenfield_focus_unsupported			= THiddenField does not support setting input focus.
  hiddenfield_theming_unsupported			= THiddenField does not support theming.
 -hiddenfield_skinid_unsupported			= THiddenField does not support control skin.
\ No newline at end of file +hiddenfield_skinid_unsupported			= THiddenField does not support control skin.
 +
 +panel_defaultbutton_invalid				= TPanel.DefaultButton '%s' does not refer to an existing button control.
\ No newline at end of file diff --git a/framework/TComponent.php b/framework/TComponent.php index 3934bfdc..c1b483c0 100644 --- a/framework/TComponent.php +++ b/framework/TComponent.php @@ -538,8 +538,8 @@ class TPropertyValue  	 */
  	public static function ensureEnum($value,$enum)
  	{
 -		if(($index=array_search($value,$enum))!==false)
 -			return $enum[$index];
 +		if(in_array($value,$enum))
 +			return $value;
  		else
  			throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,implode(' | ',$enum));
  	}
 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 <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);
  	}
  | 
