diff options
author | xue <> | 2005-12-07 03:31:08 +0000 |
---|---|---|
committer | xue <> | 2005-12-07 03:31:08 +0000 |
commit | d2f675e58b1c42c8960907ee20490a391aec0ecc (patch) | |
tree | ec37e7019b5ea261b4dde1ac88b2dacbd0675905 /framework/Web/UI | |
parent | bd56fe6028fc09d8121f353ac7e33fc11994de9b (diff) |
Diffstat (limited to 'framework/Web/UI')
-rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 37 | ||||
-rw-r--r-- | framework/Web/UI/TControl.php | 5 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TButton.php | 3 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TImageButton.php | 3 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TLinkButton.php | 2 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TTextBox.php | 126 |
6 files changed, 85 insertions, 91 deletions
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 <b>Text</b> property.
- * You can create a <b>SingleLine</b>, a <b>MultiLine</b>, or a <b>Password</b> text box
- * by setting the <b>TextMode</b> property.
- * If the TTextBox control is a multiline text box, the number of rows
- * it displays is determined by the <b>Rows</b> property, and the <b>Wrap</b> property
+ * The text displayed in the TTextBox control is determined by the
+ * {@link setText Text} property. You can create a <b>SingleLine</b>,
+ * a <b>MultiLine</b>, or a <b>Password</b> 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 <b>Columns</b> property.
- * To prevent the text displayed in the component from being modified,
- * set the <b>ReadOnly</b> property to true. If you want to limit the user input
- * to a specified number of characters, set the <b>MaxLength</b> property. To use AutoComplete
- * feature, set the <b>AutoCompleteType</b> 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 <b>AutoPostBack</b> is set true, updating the text box and then changing the focus out of it
- * will cause postback action. And if <b>CausesValidation</b> is true, validation will also
- * be processed, which can be further restricted within a <b>ValidationGroup</b>.
+ * 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 <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -39,6 +43,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
*/
protected function getTagName()
@@ -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 <b>Text</b> 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 <b>TextChanged</b> 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 <b>Text</b> 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()
{
|