From d2f675e58b1c42c8960907ee20490a391aec0ecc Mon Sep 17 00:00:00 2001
From: xue <>
Date: Wed, 7 Dec 2005 03:31:08 +0000
Subject:
---
framework/Web/Javascripts/base/prado.js | 36 +++++++-
framework/Web/Javascripts/js/base.js | 34 ++++++-
framework/Web/UI/TClientScriptManager.php | 37 ++++----
framework/Web/UI/TControl.php | 5 +-
framework/Web/UI/WebControls/TButton.php | 3 +-
framework/Web/UI/WebControls/TImageButton.php | 3 +-
framework/Web/UI/WebControls/TLinkButton.php | 2 +-
framework/Web/UI/WebControls/TTextBox.php | 126 ++++++++++++--------------
8 files changed, 145 insertions(+), 101 deletions(-)
(limited to 'framework/Web')
diff --git a/framework/Web/Javascripts/base/prado.js b/framework/Web/Javascripts/base/prado.js
index b1e87634..2174908f 100644
--- a/framework/Web/Javascripts/base/prado.js
+++ b/framework/Web/Javascripts/base/prado.js
@@ -2,17 +2,17 @@ Prado = Class.create();
Prado.version = '3.0a';
-Prado.DefaultButton = Class.create();
+Prado.Button = Class.create();
-Prado.DefaultButton.buttonFired = false;
-Prado.DefaultButton.fire = function(event, target)
+Prado.Button.buttonFired = false;
+Prado.Button.fireButton = function(event, target)
{
- if (!Prado.DefaultButton.buttonFired && event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea")))
+ if (!Prado.Button.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;
+ Prado.Button.buttonFired = true;
defaultButton.click();
event.cancelBubble = true;
if (event.stopPropagation)
@@ -22,3 +22,29 @@ Prado.DefaultButton.fire = function(event, target)
}
return true;
}
+
+Prado.TextBox = Class.create();
+
+Prado.TextBox.handleReturnKey = function(event)
+{
+ if (event.keyCode == 13)
+ {
+ var target;
+ if(typeof(event.target)!="undefined")
+ target=event.target;
+ else if(typeof(event.srcElement)!="undefined")
+ target=event.srcElement;
+ if((typeof(target)!="undefined") && (target!=null))
+ {
+ if(typeof(target.onchange)!="undefined")
+ {
+ target.onchange();
+ event.cancelBubble=true;
+ if(event.stopPropagation)
+ event.stopPropagation();
+ return false;
+ }
+ }
+ }
+ return true;
+}
\ No newline at end of file
diff --git a/framework/Web/Javascripts/js/base.js b/framework/Web/Javascripts/js/base.js
index 1f86b1c1..276c17bd 100644
--- a/framework/Web/Javascripts/js/base.js
+++ b/framework/Web/Javascripts/js/base.js
@@ -841,13 +841,13 @@ 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"))){
+Prado.Button=Class.create();
+Prado.Button.buttonFired=false;
+Prado.Button.fireButton=function(_1,_2){
+if(!Prado.Button.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;
+Prado.Button.buttonFired=true;
_3.click();
_1.cancelBubble=true;
if(_1.stopPropagation){
@@ -858,6 +858,30 @@ return false;
}
return true;
};
+Prado.TextBox=Class.create();
+Prado.TextBox.handleReturnKey=function(_4){
+if(_4.keyCode==13){
+var _5;
+if(typeof (_4.target)!="undefined"){
+_5=_4.target;
+}else{
+if(typeof (_4.srcElement)!="undefined"){
+_5=_4.srcElement;
+}
+}
+if((typeof (_5)!="undefined")&&(_5!=null)){
+if(typeof (_5.onchange)!="undefined"){
+_5.onchange();
+_4.cancelBubble=true;
+if(_4.stopPropagation){
+_4.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 ace11064..c42e664d 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -119,7 +119,7 @@ class TClientScriptManager extends TComponent
$opt.='"'.$options->getValidationGroup().'",';
}
else
- $opt.='"",';
+ $opt.='\'\',';
if($options->getActionUrl()!=='')
{
$flag=true;
@@ -139,10 +139,10 @@ class TClientScriptManager extends TComponent
if($options->getClientSubmit())
{
$flag=true;
- $opt.='true)';
+ $opt.='true';
}
else
- $opt.='false)';
+ $opt.='false';
if(!$flag)
return '';
$this->registerPostBackScript();
@@ -153,25 +153,28 @@ class TClientScriptManager extends TComponent
return $javascriptPrefix?'javascript:'.$postback:$postback;
}
- protected function registerPostBackScript()
+ public function registerPradoScript($scriptFile)
{
- if(!$this->_postBackScriptRegistered)
+ if(isset($this->_publishedScriptFiles[$scriptFile]))
+ $url=$this->_publishedScriptFiles[$scriptFile];
+ else
{
- $this->_postBackScriptRegistered=true;
- $this->registerHiddenField(TPage::FIELD_POSTBACK_TARGET,'');
- $this->registerHiddenField(TPage::FIELD_POSTBACK_PARAMETER,'');
- $this->registerScriptInclude('prado:base',$this->publishScriptFile('base.js'));
+ $url=$this->_page->getService()->getAssetManager()->publishFilePath(Prado::getFrameworkPath().'/'.self::SCRIPT_DIR.'/'.$scriptFile);
+ $this->_publishedScriptFiles[$scriptFile]=$url;
+ $this->registerScriptInclude('prado:'.$scriptFile,$url);
}
+ return $url;
}
- private function publishScriptFile($jsFile)
+ protected function registerPostBackScript()
{
- if(!isset($this->_publishedScriptFiles[$jsFile]))
+ if(!$this->_postBackScriptRegistered)
{
- $am=$this->_page->getService()->getAssetManager();
- $this->_publishedScriptFiles[$jsFile]=$am->publishFilePath(Prado::getFrameworkPath().'/'.self::SCRIPT_DIR.'/'.$jsFile);
+ $this->_postBackScriptRegistered=true;
+ $this->registerHiddenField(TPage::FIELD_POSTBACK_TARGET,'');
+ $this->registerHiddenField(TPage::FIELD_POSTBACK_PARAMETER,'');
+ $this->registerPradoScript('base.js');
}
- return $this->_publishedScriptFiles[$jsFile];
}
public function registerFocusScript($target)
@@ -179,7 +182,7 @@ class TClientScriptManager extends TComponent
if(!$this->_focusScriptRegistered)
{
$this->_focusScriptRegistered=true;
- $this->registerScriptInclude('prado:base',$this->publishScriptFile('base.js'));
+ $this->registerPradoScript('base.js');
$this->registerEndScript('prado:focus','Prado.Focus.setFocus("'.THttpUtility::quoteJavaScriptString($target).'");');
}
}
@@ -197,8 +200,8 @@ class TClientScriptManager extends TComponent
public function registerDefaultButtonScript($button)
{
- $this->registerScriptInclude('prado:base',$this->publishScriptFile('base.js'));
- return 'return Prado.DefaultButton.fire(event,\''.$button->getClientID().'\')';
+ $this->registerPradoScript('base.js');
+ return 'return Prado.Button.fireButton(event,\''.$button->getClientID().'\')';
}
public function registerValidationScript()
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index e568df65..ce343925 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -576,11 +576,14 @@ class TControl extends TComponent
/**
* Removes the named attribute.
* @param string the name of the attribute to be removed.
+ * @return string attribute value removed, empty string if attribute does not exist.
*/
public function removeAttribute($name)
{
if($attributes=$this->getViewState('Attributes',null))
- $attributes->remove($name);
+ return $attributes->remove($name);
+ else
+ return '';
}
/**
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php
index a9eac8ac..e7c40a75 100644
--- a/framework/Web/UI/WebControls/TButton.php
+++ b/framework/Web/UI/WebControls/TButton.php
@@ -81,8 +81,7 @@ class TButton extends TWebControl implements IPostBackEventHandler
if($this->getEnabled(true))
{
- $onclick='';
- $onclick=$this->hasAttribute('onclick')?$this->getAttributes()->remove('onclick'):'';
+ $onclick=$this->removeAttribute('onclick');
$onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
$onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),false);
if(!empty($onclick))
diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php
index 669e517e..33dfde75 100644
--- a/framework/Web/UI/WebControls/TImageButton.php
+++ b/framework/Web/UI/WebControls/TImageButton.php
@@ -96,8 +96,7 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven
if($this->getEnabled(true))
{
- $onclick='';
- $onclick=$this->hasAttribute('onclick')?$this->getAttributes()->remove('onclick'):'';
+ $onclick=$this->removeAttribute('onclick');
$onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
$onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),false);
if(!empty($onclick))
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php
index d3be1ade..dd2d8cb7 100644
--- a/framework/Web/UI/WebControls/TLinkButton.php
+++ b/framework/Web/UI/WebControls/TLinkButton.php
@@ -79,7 +79,7 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
{
$page=$this->getPage();
$page->ensureRenderInForm($this);
- $onclick=$this->hasAttribute('onclick')?$this->getAttributes()->remove('onclick'):'';
+ $onclick=$this->removeAttribute('onclick');
$onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
if(!empty($onclick))
$writer->addAttribute('onclick','javascript:'.$onclick);
diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php
index 4d4fcff6..3e5f0107 100644
--- a/framework/Web/UI/WebControls/TTextBox.php
+++ b/framework/Web/UI/WebControls/TTextBox.php
@@ -14,22 +14,26 @@
* TTextBox class
*
* TTextBox displays a text box on the Web page for user input.
- * The text displayed in the TTextBox control is determined by the Text property.
- * You can create a SingleLine, a MultiLine, or a Password text box
- * by setting the TextMode property.
- * If the TTextBox control is a multiline text box, the number of rows
- * it displays is determined by the Rows property, and the Wrap property
+ * The text displayed in the TTextBox control is determined by the
+ * {@link setText Text} property. You can create a SingleLine,
+ * a MultiLine, or a Password text box by setting
+ * the {@link setTextMode TextMode} property. If the TTextBox control
+ * is a multiline text box, the number of rows it displays is determined
+ * by the {@link setRows Rows} property, and the {@link setWrap Wrap} property
* can be used to determine whether to wrap the text in the component.
*
- * To specify the display width of the text box, in characters, set the Columns property.
- * To prevent the text displayed in the component from being modified,
- * set the ReadOnly property to true. If you want to limit the user input
- * to a specified number of characters, set the MaxLength property. To use AutoComplete
- * feature, set the AutoCompleteType property.
+ * To specify the display width of the text box, in characters, set
+ * the {@link setColumns Columns} property. To prevent the text displayed
+ * in the component from being modified, set the {@link setReadOnly ReadOnly}
+ * property to true. If you want to limit the user input to a specified number
+ * of characters, set the {@link setMaxLength MaxLength} property.
+ * To use AutoComplete feature, set the {@link setAutoCompleteType AutoCompleteType} property.
*
- * If AutoPostBack is set true, updating the text box and then changing the focus out of it
- * will cause postback action. And if CausesValidation is true, validation will also
- * be processed, which can be further restricted within a ValidationGroup.
+ * If {@link setAutoPostBack AutoPostBack} is set true, updating the text box
+ * and then changing the focus out of it will cause postback action.
+ * And if {@link setCausesValidation CausesValidation} is true, validation will
+ * also be processed, which can be further restricted within
+ * a {@link setValidationGroup ValidationGroup}.
*
* @author Qiang Xue
* @version $Revision: $ $Date: $
@@ -38,6 +42,11 @@
*/
class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
{
+ /**
+ * @var array list of auto complete types
+ */
+ private static $_autoCompleteTypes=array('BusinessCity','BusinessCountryRegion','BusinessFax','BusinessPhone','BusinessState','BusinessStreetAddress','BusinessUrl','BusinessZipCode','Cellular','Company','Department','Disabled','DisplayName','Email','FirstName','Gender','HomeCity','HomeCountryRegion','HomeFax','Homepage','HomePhone','HomeState','HomeStreetAddress','HomeZipCode','JobTitle','LastName','MiddleName','None','Notes','Office','Pager','Search');
+
/**
* @return string tag name of the textbox
*/
@@ -48,7 +57,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
/**
* Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional textbox specific attributes.
+ * This method overrides the parent implementation with additional textbox specific attributes.
* @param THtmlWriter the writer used for the rendering purpose
*/
protected function addAttributesToRender($writer)
@@ -59,10 +68,12 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
$writer->addAttribute('name',$uid);
if(($textMode=$this->getTextMode())==='MultiLine')
{
- if(($rows=$this->getRows())>0)
- $writer->addAttribute('rows',$rows);
- if(($cols=$this->getColumns())>0)
- $writer->addAttribute('cols',$cols);
+ if(($rows=$this->getRows())<=0)
+ $rows=2;
+ if(($cols=$this->getColumns())<=0)
+ $cols=20;
+ $writer->addAttribute('rows',"$rows");
+ $writer->addAttribute('cols',"$cols");
if(!$this->getWrap())
$writer->addAttribute('wrap','off');
}
@@ -98,9 +109,9 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
$writer->addAttribute('type','password');
}
if(($cols=$this->getColumns())>0)
- $writer->addAttribute('size',$cols);
+ $writer->addAttribute('size',"$cols");
if(($maxLength=$this->getMaxLength())>0)
- $writer->addAttribute('maxlength',$maxLength);
+ $writer->addAttribute('maxlength',"$maxLength");
}
if($this->getReadOnly())
$writer->addAttribute('readonly','readonly');
@@ -108,30 +119,25 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
$writer->addAttribute('disabled','disabled');
if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
{
- $onchange='';
- $onkeypress='if (WebForm_TextBoxKeyHandler() == false) return false;';
- if($this->getHasAttributes())
+ $option=new TPostBackOptions();
+ if($this->getCausesValidation() && $page->getValidators($this->getValidationGroup())->getCount()>0)
{
- $attributes=$this->getAttributes();
- $onchange=$attributes->itemAt('onchange');
- if($onchange!=='')
- $onchange=rtrim($onchange,';').';';
- $attributes->remove('onchange');
- $onkeypress.=$attributes->itemAt('onkeypress');
- $attributes->remove('onkeypress');
+ $option->setPerformValidation(true);
+ $option->setValidationGroup($this->getValidationGroup());
}
+ $option->setAutoPostBack(true);
+ $onchange=$this->removeAttribute('onchange');
+ $onchange.=THttpUtility::trimJavaScriptString($onchange).$page->getClientScript()->getPostBackEventReference($this,'',$option,false);
+ $writer->addAttribute('onchange','javascript:'.$onchange);
- $option=new TPostBackOptions($this);
- if($this->getCausesValidation())
+ if($textMode!=='MultiLine')
{
- $option->PerformValidation=true;
- $option->ValidationGroup=$this->getValidationGroup();
+ // note, Prado.TextBox.handleReturnKey is defined in base.js,
+ // which is included when AutoPostBack is true for textbox.
+ $onkeypress='javascript:if(Prado.TextBox.handleReturnKey(event)==false) return false;';
+ $onkeypress.=THttpUtility::trimJavaScriptString($this->removeAttribute('onkeypress'));
+ $writer->addAttribute('onkeypress',$onkeypress);
}
- if($page->getForm())
- $option->AutoPostBack=true;
- $onchange.=$page->getClientScript()->getPostBackEventReference($option);
- $writer->addAttribute('onchange',$onchange);
- $writer->addAttribute('onkeypress',$onkeypress);
}
parent::addAttributesToRender($writer);
}
@@ -155,23 +161,6 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
return false;
}
- protected function onPreRender($param)
- {
- parent::onPreRender($param);
- if(($page=$this->getPage()) && $this->getEnabled(true))
- {
- // TODO
- //if($this->getTextMode()==='Password' || ($this->hasEventHandler('TextChanged') && $this->getVisible()))
- // $page->registerEnabledControl($this);
- if($this->getAutoPostBack())
- {
- $page->registerWebFormsScript();
- $page->registerPostBackScript();
- $page->registerFocusScript();
- }
- }
- }
-
/**
* Returns the value to be validated.
* This methid is required by IValidatable interface.
@@ -183,8 +172,8 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * This method is invoked when the value of the Text property changes on postback.
- * The method raises 'TextChanged' event.
+ * This method is invoked when the value of the {@link getText Text}
+ * property changes on postback. The method raises TextChanged event.
* If you override this method, be sure to call the parent implementation to ensure
* the invocation of the attached event handlers.
* @param TEventParameter event parameter to be passed to the event handlers
@@ -196,8 +185,9 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
/**
* Raises postdata changed event.
- * This method is required by IPostBackDataHandler interface.
- * It is invoked by the framework when Text property is changed on postback.
+ * This method is required by {@link IPostBackDataHandler} interface.
+ * It is invoked by the framework when {@link getText Text} property
+ * is changed on postback.
* This method is primarly used by framework developers.
*/
public function raisePostDataChangedEvent()
@@ -209,7 +199,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
if($this->getCausesValidation())
$page->validate($this->getValidationGroup());
}
- $this->onTextChanged(new TEventParameter);
+ $this->onTextChanged(null);
}
/**
@@ -243,13 +233,13 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
*/
public function setAutoCompleteType($value)
{
- $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnum($value,array('BusinessCity','BusinessCountryRegion','BusinessFax','BusinessPhone','BusinessState','BusinessStreetAddress','BusinessUrl','BusinessZipCode','Cellular','Company','Department','Disabled','DisplayName','Email','FirstName','Gender','HomeCity','HomeCountryRegion','HomeFax','Homepage','HomePhone','HomeState','HomeStreetAddress','HomeZipCode','JobTitle','LastName','MiddleName','None','Notes','Office','Pager','Search')),'None');
+ $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnum($value,self::$_autoCompleteTypes),'None');
}
/**
* @return boolean a value indicating whether an automatic postback to the server
* will occur whenever the user modifies the text in the TTextBox control and
- * then tabs out of the component.
+ * then tabs out of the component. Defaults to false.
*/
public function getAutoPostBack()
{
@@ -319,7 +309,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * @return boolean whether the textbox is read only, default is false
+ * @return boolean whether the textbox is read only, default is false.
*/
public function getReadOnly()
{
@@ -339,7 +329,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
*/
public function getRows()
{
- return $this->getViewState('Rows',4);
+ return $this->getViewState('Rows',0);
}
/**
@@ -348,7 +338,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
*/
public function setRows($value)
{
- $this->setViewState('Rows',TPropertyValue::ensureInteger($value),4);
+ $this->setViewState('Rows',TPropertyValue::ensureInteger($value),0);
}
/**
@@ -369,7 +359,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * @return string the behavior mode (SingleLine, MultiLine, or Password) of the TTextBox component.
+ * @return string the behavior mode (SingleLine, MultiLine, or Password) of the TTextBox component. Defaults to SingleLine.
*/
public function getTextMode()
{
@@ -403,7 +393,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * @return boolean whether the text content wraps within a multiline text box.
+ * @return boolean whether the text content wraps within a multiline text box. Defaults to true.
*/
public function getWrap()
{
--
cgit v1.2.3