From 3dcb3c4188c8d5836a2db0847d2fc43bc7e7e4d8 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Mon, 20 Feb 2006 06:23:38 +0000
Subject: Cleaned up TForm and THead.
---
framework/Web/UI/TClientScriptManager.php | 18 +++--
framework/Web/UI/TForm.php | 54 ++++++++++++---
framework/Web/UI/TPage.php | 8 +--
framework/Web/UI/WebControls/THead.php | 99 ++++++++++++++++++++-------
framework/Web/UI/WebControls/TListControl.php | 2 +-
5 files changed, 133 insertions(+), 48 deletions(-)
(limited to 'framework/Web')
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 2fe67308..5ff5dba6 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -173,6 +173,18 @@ class TClientScriptManager extends TApplicationComponent
$this->registerPradoScript('prado');
}
+ /**
+ * Registers the control to receive default focus.
+ * @param TControl|string the control or the client ID of the HTML element to receive default focus
+ */
+ public function registerFocusControl($target)
+ {
+ $this->registerPradoScript('prado');
+ if($target instanceof TControl)
+ $target=$target->getClientID();
+ $this->registerEndScript('prado:focus','Prado.Focus.setFocus("'.TJavaScript::quoteString($target).'");');
+ }
+
/**
* @return array default button options.
*/
@@ -418,12 +430,6 @@ class TClientScriptManager extends TApplicationComponent
if($str!=='')
$writer->write("
\n".$str."
\n");
}
-
- public function registerFocusScript($target)
- {
- $this->registerPradoScript('prado');
- $this->registerEndScript('prado:focus','Prado.Focus.setFocus("'.TJavaScript::quoteString($target).'");');
- }
}
?>
\ No newline at end of file
diff --git a/framework/Web/UI/TForm.php b/framework/Web/UI/TForm.php
index 538cf8cd..317b0158 100644
--- a/framework/Web/UI/TForm.php
+++ b/framework/Web/UI/TForm.php
@@ -13,6 +13,15 @@
/**
* TForm class
*
+ * TForm displays an HTML form. Besides regular body content,
+ * it displays hidden fields, javascript blocks and files that are registered
+ * through {@link TClientScriptManager}.
+ *
+ * A TForm is required for a page that needs postback.
+ * Each page can contain at most one TForm. If multiple HTML forms are needed,
+ * please use regular HTML form tags for those forms that post to different
+ * URLs.
+ *
* @author Qiang Xue
* @version $Revision: $ $Date: $
* @package System.Web.UI
@@ -30,6 +39,10 @@ class TForm extends TControl
$this->getPage()->setForm($this);
}
+ /**
+ * Adds form specific attributes to renderer.
+ * @param THtmlWriter writer
+ */
protected function addAttributesToRender($writer)
{
$writer->addAttribute('id',$this->getClientID());
@@ -52,7 +65,8 @@ class TForm extends TControl
}
/**
- * @internal
+ * Renders the form.
+ * @param THtmlWriter writer
*/
public function render($writer)
{
@@ -65,46 +79,64 @@ class TForm extends TControl
$writer->renderEndTag();
}
+ /**
+ * @return string id path to the default button control.
+ */
public function getDefaultButton()
{
return $this->getViewState('DefaultButton','');
}
+ /**
+ * Sets a button to be default one in a form.
+ * A default button will be clicked if a user presses 'Enter' key within
+ * the form.
+ * @param string id path to the default button control.
+ */
public function setDefaultButton($value)
{
$this->setViewState('DefaultButton',$value,'');
}
- public function getDefaultFocus()
- {
- return $this->getViewState('DefaultFocus','');
- }
-
- public function setDefaultFocus($value)
- {
- $this->setViewState('DefaultFocus',$value,'');
- }
-
+ /**
+ * @return string form submission method. Defaults to 'post'.
+ */
public function getMethod()
{
return $this->getViewState('Method','post');
}
+ /**
+ * @param string form submission method. Valid values include 'post' and 'get'.
+ */
public function setMethod($value)
{
$this->setViewState('Method',TPropertyValue::ensureEnum($value,'post','get'),'post');
}
+ /**
+ * @return string the encoding type a browser uses to post data back to the server
+ */
public function getEnctype()
{
return $this->getViewState('Enctype','');
}
+ /**
+ * @param string the encoding type a browser uses to post data back to the server.
+ * Commonly used types include
+ * - application/x-www-form-urlencoded : Form data is encoded as name/value pairs. This is the standard encoding format.
+ * - multipart/form-data : Form data is encoded as a message with a separate part for each control on the page.
+ * - text/plain : Form data is encoded in plain text, without any control or formatting characters.
+ */
public function setEnctype($value)
{
$this->setViewState('Enctype',$value,'');
}
+ /**
+ * @return string form name, which is equal to {@link getUniqueID UniqueID}.
+ */
public function getName()
{
return $this->getUniqueID();
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index bbfca2fe..aa188a03 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -690,13 +690,11 @@ class TPage extends TTemplateControl
{
if($this->_focus)
{
- if(is_string($this->_focus))
- $cs->registerFocusScript($this->_focus);
- else if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true))
- $cs->registerFocusScript($this->_focus->getClientID());
+ if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true) || is_string($this->_focus))
+ $cs->registerFocusControl($this->_focus);
}
else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null)
- $cs->registerFocusScript($lastFocus);
+ $cs->registerFocusControl($lastFocus);
$cs->renderHiddenFields($writer);
$cs->renderScriptFiles($writer);
$cs->renderEndScripts($writer);
diff --git a/framework/Web/UI/WebControls/THead.php b/framework/Web/UI/WebControls/THead.php
index 3a949e34..30f6cbbd 100644
--- a/framework/Web/UI/WebControls/THead.php
+++ b/framework/Web/UI/WebControls/THead.php
@@ -13,14 +13,22 @@
/**
* THead class
*
- * THead displays a <head> element on a page. It displays the content
- * enclosed in its body. In addition, it displays the page title set by the
- * {@link setTitle Title} property, and the meta tags registered via
- * {@link registerMetaTag}. Stylesheet and JavaScripts registered via
+ * THead displays a head element on a page. It displays the content
+ * enclosed in its body and the page title set by the
+ * {@link setTitle Title} property. In addition, stylesheets and JavaScripts registered via
* {@link TClientScriptManager::registerStyleSheet}, {@link TClientScriptManager::registerStyleSheetFile}
* {@link TClientScriptManager::registerHeadJavaScript}, and
* {@link TClientScriptManager::registerHeadJavaScriptFile} will also be displayed
* in the head.
+ * THead also manages and displays meta tags through its {@link getMetaTags MetaTags}
+ * property. You can add a meta object to the collection in code dynamically,
+ * or add it in template using the following syntax,
+ *
+ *
+ *
+ *
+ *
+ *
*
* Note, {@link TPage} has a property {@link TPage::getHead Head} that refers to
* the THead control currently on the page. A page can have at most once THead
@@ -36,9 +44,9 @@
class THead extends TControl
{
/**
- * @var array list of meta name tags to be loaded by {@link THead}
+ * @var TList list of meta name tags to be loaded by {@link THead}
*/
- private $_metaTags=array();
+ private $_metaTags=null;
/**
* Registers the head control with the current page.
@@ -54,6 +62,21 @@ class THead extends TControl
$this->getPage()->setHead($this);
}
+ /**
+ * Processes an object that is created during parsing template.
+ * This method adds TMetaTag components into the {@link getMetaTags MetaTags}
+ * collection of the head control.
+ * @param string|TComponent text string or component parsed and instantiated in template
+ * @see createdOnTemplate
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TMetaTag)
+ $this->getMetaTags()->add($object);
+ else
+ parent::addParsedObject($object);
+ }
+
/**
* @return string the page title.
*/
@@ -74,24 +97,16 @@ class THead extends TControl
}
/**
- * Registers a meta tag to be imported with the page body
- * @param string a key that identifies the meta tag to avoid repetitive registration
- * @param TMetaTag the meta tag to be registered
- * @see isTagRegistered()
- */
- public function registerMetaTag($key,$metaTag)
- {
- $this->_metaTags[$key]=$metaTag;
- }
-
- /**
- * @param string a key identifying the meta tag.
- * @return boolean whether the named meta tag has been registered before
- * @see registerMetaTag()
+ * @return TMetaTagCollection meta tag collection
*/
- public function isMetaTagRegistered($key)
+ public function getMetaTags()
{
- return isset($this->_metaTags[$key]);
+ if(($metaTags=$this->getViewState('MetaTags',null))===null)
+ {
+ $metaTags=new TMetaTagCollection;
+ $this->setViewState('MetaTags',$metaTags,null);
+ }
+ return $metaTags;
}
/**
@@ -104,10 +119,13 @@ class THead extends TControl
if(($title=$page->getTitle())==='')
$title=$this->getTitle();
$writer->write("\n".THttpUtility::htmlEncode($title)."\n");
- foreach($this->_metaTags as $metaTag)
+ if(($metaTags=$this->getMetaTags())!==null)
{
- $metaTag->render($writer);
- $writer->writeLine();
+ foreach($metaTags as $metaTag)
+ {
+ $metaTag->render($writer);
+ $writer->writeLine();
+ }
}
$cs=$page->getClientScript();
$cs->renderStyleSheetFiles($writer);
@@ -256,4 +274,35 @@ class TMetaTag extends TComponent
}
}
+
+/**
+ * TMetaTagCollection class
+ *
+ * TMetaTagCollection represents a collection of meta tags
+ * contained in a {@link THead} control.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TMetaTagCollection extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing type
+ * check on the item being added.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a {@link TMetaTag}
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TMetaTag)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('metatagcollection_metatag_invalid');
+ }
+}
+
?>
\ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index 3c1cd547..be0abd38 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -195,7 +195,7 @@ abstract class TListControl extends TDataBoundControl
// so we make them be effective now
if($this->_cachedSelectedValue!==null)
{
- $index=$items->findIndexByValue($value);
+ $index=$items->findIndexByValue($this->_cachedSelectedValue);
if($index===-1 || ($this->_cachedSelectedIndex!==-1 && $this->_cachedSelectedIndex!==$index))
throw new TInvalidDataValueException('listcontrol_selection_invalid');
$this->setSelectedIndex($index);
--
cgit v1.2.3