summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorwei <>2006-06-12 03:10:47 +0000
committerwei <>2006-06-12 03:10:47 +0000
commit1c6f1f79d011579a158e87459040075331b636b7 (patch)
tree75236e04a5e2aaf9685b34ed7bed0f82e591bbb4 /framework/Web
parentf30c38fcc9d6cdfa7aafa5078a58645192c11974 (diff)
Minor updates.
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/extended/base.js97
-rw-r--r--framework/Web/Javascripts/js/prado.js6
-rw-r--r--framework/Web/Javascripts/prado/activecontrols3.js2
-rw-r--r--framework/Web/UI/TClientScriptManager.php15
-rw-r--r--framework/Web/UI/WebControls/TBulletedList.php868
-rw-r--r--framework/Web/UI/WebControls/TButton.php512
-rw-r--r--framework/Web/UI/WebControls/TCheckBox.php792
-rw-r--r--framework/Web/UI/WebControls/TDatePicker.php7
-rw-r--r--framework/Web/UI/WebControls/TImageButton.php754
-rw-r--r--framework/Web/UI/WebControls/TImageMap.php1452
-rw-r--r--framework/Web/UI/WebControls/TLinkButton.php510
-rw-r--r--framework/Web/UI/WebControls/TListControl.php1648
-rw-r--r--framework/Web/UI/WebControls/TRadioButton.php362
13 files changed, 3567 insertions, 3458 deletions
diff --git a/framework/Web/Javascripts/extended/base.js b/framework/Web/Javascripts/extended/base.js
index 53856684..d7fabdd0 100644
--- a/framework/Web/Javascripts/extended/base.js
+++ b/framework/Web/Javascripts/extended/base.js
@@ -26,4 +26,99 @@ Class.extend = function(base, definition)
if(definition)
Object.extend(component.prototype, definition);
return component;
-} \ No newline at end of file
+}
+
+/*
+ Base, version 1.0.1
+ Copyright 2006, Dean Edwards
+ License: http://creativecommons.org/licenses/LGPL/2.1/
+*/
+
+function Base() {
+};
+
+Base.version = "1.0.1";
+
+Base.prototype = {
+ extend: function(source, value) {
+ var extend = Base.prototype.extend;
+ if (arguments.length == 2) {
+ var ancestor = this[source];
+ // overriding?
+ if ((ancestor instanceof Function) && (value instanceof Function) &&
+ ancestor.valueOf() != value.valueOf() && /\binherit\b/.test(value)) {
+ var method = value;
+ value = function() {
+ var previous = this.inherit;
+ this.inherit = ancestor;
+ var returnValue = method.apply(this, arguments);
+ this.inherit = previous;
+ return returnValue;
+ };
+ // point to the underlying method
+ value.valueOf = function() {
+ return method;
+ };
+ value.toString = function() {
+ return String(method);
+ };
+ }
+ return this[source] = value;
+ } else if (source) {
+ var _prototype = {toSource: null};
+ // do the "toString" and other methods manually
+ var _protected = ["toString", "valueOf"];
+ // if we are prototyping then include the constructor
+ if (Base._prototyping) _protected[2] = "constructor";
+ for (var i = 0; (name = _protected[i]); i++) {
+ if (source[name] != _prototype[name]) {
+ extend.call(this, name, source[name]);
+ }
+ }
+ // copy each of the source object's properties to this object
+ for (var name in source) {
+ if (!_prototype[name]) {
+ extend.call(this, name, source[name]);
+ }
+ }
+ }
+ return this;
+ },
+
+ inherit: function() {
+ // call this method from any other method to invoke that method's ancestor
+ }
+};
+
+Base.extend = function(_instance, _static) {
+ var extend = Base.prototype.extend;
+ if (!_instance) _instance = {};
+ // create the constructor
+ if (_instance.constructor == Object) {
+ _instance.constructor = new Function;
+ }
+ // build the prototype
+ Base._prototyping = true;
+ var _prototype = new this;
+ extend.call(_prototype, _instance);
+ var constructor = _prototype.constructor;
+ _prototype.constructor = this;
+ delete Base._prototyping;
+ // create the wrapper for the constructor function
+ var klass = function() {
+ if (!Base._prototyping) constructor.apply(this, arguments);
+ this.constructor = klass;
+ };
+ klass.prototype = _prototype;
+ // build the class interface
+ klass.extend = this.extend;
+ klass.toString = function() {
+ return String(constructor);
+ };
+ extend.call(klass, _static);
+ // support singletons
+ var object = constructor ? klass : _prototype;
+ // class initialisation
+ if (object.init instanceof Function) object.init();
+ return object;
+}; \ No newline at end of file
diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js
index 87fd69a6..5f52fece 100644
--- a/framework/Web/Javascripts/js/prado.js
+++ b/framework/Web/Javascripts/js/prado.js
@@ -15,7 +15,11 @@ Function.prototype.bindEvent=function()
Class.extend=function(base,definition)
{var component=Class.create();Object.extend(component.prototype,base.prototype);if(definition)
Object.extend(component.prototype,definition);return component;}
-Object.extend(String.prototype,{gsub:function(pattern,replacement){var result='',source=this,match;replacement=arguments.callee.prepareReplacement(replacement);while(source.length>0){if(match=source.match(pattern)){result+=source.slice(0,match.index);result+=(replacement(match)||'').toString();source=source.slice(match.index+match[0].length);}else{result+=source,source='';}}
+function Base(){};Base.version="1.0.1";Base.prototype={extend:function(source,value){var extend=Base.prototype.extend;if(arguments.length==2){var ancestor=this[source];if((ancestor instanceof Function)&&(value instanceof Function)&&ancestor.valueOf()!=value.valueOf()&&/\binherit\b/.test(value)){var method=value;value=function(){var previous=this.inherit;this.inherit=ancestor;var returnValue=method.apply(this,arguments);this.inherit=previous;return returnValue;};value.valueOf=function(){return method;};value.toString=function(){return String(method);};}
+return this[source]=value;}else if(source){var _prototype={toSource:null};var _protected=["toString","valueOf"];if(Base._prototyping)_protected[2]="constructor";for(var i=0;(name=_protected[i]);i++){if(source[name]!=_prototype[name]){extend.call(this,name,source[name]);}}
+for(var name in source){if(!_prototype[name]){extend.call(this,name,source[name]);}}}
+return this;},inherit:function(){}};Base.extend=function(_instance,_static){var extend=Base.prototype.extend;if(!_instance)_instance={};if(_instance.constructor==Object){_instance.constructor=new Function;}
+Base._prototyping=true;var _prototype=new this;extend.call(_prototype,_instance);var constructor=_prototype.constructor;_prototype.constructor=this;delete Base._prototyping;var klass=function(){if(!Base._prototyping)constructor.apply(this,arguments);this.constructor=klass;};klass.prototype=_prototype;klass.extend=this.extend;klass.toString=function(){return String(constructor);};extend.call(klass,_static);var object=constructor?klass:_prototype;if(object.init instanceof Function)object.init();return object;};Object.extend(String.prototype,{gsub:function(pattern,replacement){var result='',source=this,match;replacement=arguments.callee.prepareReplacement(replacement);while(source.length>0){if(match=source.match(pattern)){result+=source.slice(0,match.index);result+=(replacement(match)||'').toString();source=source.slice(match.index+match[0].length);}else{result+=source,source='';}}
return result;},sub:function(pattern,replacement,count){replacement=this.gsub.prepareReplacement(replacement);count=count===undefined?1:count;return this.gsub(pattern,function(match){if(--count<0)return match[0];return replacement(match);});},scan:function(pattern,iterator){this.gsub(pattern,iterator);return this;},truncate:function(length,truncation){length=length||30;truncation=truncation===undefined?'...':truncation;return this.length>length?this.slice(0,length-truncation.length)+truncation:this;},strip:function(){return this.replace(/^\s+/,'').replace(/\s+$/,'');},stripTags:function(){return this.replace(/<\/?[^>]+>/gi,'');},stripScripts:function(){return this.replace(new RegExp(Prototype.ScriptFragment,'img'),'');},extractScripts:function(){var matchAll=new RegExp(Prototype.ScriptFragment,'img');var matchOne=new RegExp(Prototype.ScriptFragment,'im');return(this.match(matchAll)||[]).map(function(scriptTag){return(scriptTag.match(matchOne)||['',''])[1];});},evalScripts:function(){return this.extractScripts().map(function(script){return eval(script)});},escapeHTML:function(){var div=document.createElement('div');var text=document.createTextNode(this);div.appendChild(text);return div.innerHTML;},unescapeHTML:function(){var div=document.createElement('div');div.innerHTML=this.stripTags();return div.childNodes[0]?div.childNodes[0].nodeValue:'';},toQueryParams:function(){var pairs=this.match(/^\??(.*)$/)[1].split('&');return pairs.inject({},function(params,pairString){var pair=pairString.split('=');params[pair[0]]=pair[1];return params;});},toArray:function(){return this.split('');},camelize:function(){var oStringList=this.split('-');if(oStringList.length==1)return oStringList[0];var camelizedString=this.indexOf('-')==0?oStringList[0].charAt(0).toUpperCase()+oStringList[0].substring(1):oStringList[0];for(var i=1,len=oStringList.length;i<len;i++){var s=oStringList[i];camelizedString+=s.charAt(0).toUpperCase()+s.substring(1);}
return camelizedString;},inspect:function(){return"'"+this.replace(/\\/g,'\\\\').replace(/'/g,'\\\'')+"'";}});String.prototype.gsub.prepareReplacement=function(replacement){if(typeof replacement=='function')return replacement;var template=new Template(replacement);return function(match){return template.evaluate(match)};}
String.prototype.parseQuery=String.prototype.toQueryParams;var Template=Class.create();Template.Pattern=/(^|.|\r|\n)(#\{(.*?)\})/;Template.prototype={initialize:function(template,pattern){this.template=template.toString();this.pattern=pattern||Template.Pattern;},evaluate:function(object){return this.template.gsub(this.pattern,function(match){var before=match[1];if(before=='\\')return match[2];return before+(object[match[3]]||'').toString();});}}
diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js
index 475eb938..4be2779a 100644
--- a/framework/Web/Javascripts/prado/activecontrols3.js
+++ b/framework/Web/Javascripts/prado/activecontrols3.js
@@ -41,4 +41,4 @@ Prado.WebUI.TAutoComplete = Class.extend(Autocompleter.Base,
if(typeof(result) == "string" && result.length > 0)
this.updateChoices(result);
}
-}); \ No newline at end of file
+});
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index a4644e26..eb5e445a 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -122,6 +122,9 @@ class TClientScriptManager extends TApplicationComponent
$this->_page->registerCachingAction('Page.ClientScript','registerPradoScript',$params);
}
+ /**
+ * Registers a prado javascript library to be loaded.
+ */
private function registerPradoScriptInternal($name)
{
if(!isset($this->_registeredPradoScripts[$name]))
@@ -142,6 +145,10 @@ class TClientScriptManager extends TApplicationComponent
}
}
+ /**
+ * Renders the <script> tag that will load the javascript library files.
+ * @param THtmlWriter writer that renders the <script> tag.
+ */
protected function renderPradoScripts($writer)
{
$files=implode(',',array_keys($this->_publishedPradoFiles));
@@ -156,6 +163,12 @@ class TClientScriptManager extends TApplicationComponent
}
}
+ /**
+ * Returns javascript statement that create a new callback request object.
+ * @param ICallbackEventHandler callback response handler
+ * @param array additional callback options
+ * @return string javascript statement that creates a new callback request.
+ */
public function getCallbackReference(ICallbackEventHandler $callbackHandler, $options=null)
{
$options = !is_array($options) ? array() : $options;
@@ -176,7 +189,7 @@ class TClientScriptManager extends TApplicationComponent
public function registerCallbackControl($class, $options)
{
$optionString=TJavaScript::encode($options);
- $code="new Prado.WebUI.{$class}({$optionString});";
+ $code="new {$class}({$optionString});";
$this->_endScripts[sprintf('%08X', crc32($code))]=$code;
$this->registerPradoScriptInternal('ajax');
diff --git a/framework/Web/UI/WebControls/TBulletedList.php b/framework/Web/UI/WebControls/TBulletedList.php
index dfed0b6e..a2529940 100644
--- a/framework/Web/UI/WebControls/TBulletedList.php
+++ b/framework/Web/UI/WebControls/TBulletedList.php
@@ -1,435 +1,435 @@
-<?php
-/**
- * TBulletedList class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TListControl class
- */
-Prado::using('System.Web.UI.WebControls.TListControl');
-
-/**
- * TBulletedList class
- *
- * TBulletedList displays items in a bullet format.
- * The bullet style is specified by {@link setBulletStyle BulletStyle}. When
- * the style is 'CustomImage', the {@link setBackImageUrl BulletImageUrl}
- * specifies the image used as bullets.
- *
- * TBulletedList displays the item texts in three different modes, specified
- * via {@link setDisplayMode DisplayMode}. When the mode is 'Text', the item texts
- * are displayed as static texts; When the mode is 'HyperLink', each item
- * is displayed as a hyperlink whose URL is given by the item value, and the
- * {@link setTarget Target} property can be used to specify the target browser window;
- * When the mode is 'LinkButton', each item is displayed as a link button which
- * posts back to the page if a user clicks on that and the event {@link onClick OnClick}
- * will be raised under such a circumstance.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TBulletedList extends TListControl implements IPostBackEventHandler
-{
- /**
- * @var boolean cached property value of Enabled
- */
- private $_isEnabled;
- /**
- * @var TPostBackOptions postback options
- */
- private $_postBackOptions;
-
- private $_currentRenderItemIndex;
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * If {@link getCausesValidation CausesValidation} is true, it will
- * invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onClick OnClick} events.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- if($this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onClick(new TBulletedListEventParameter((int)$param));
- }
-
- /**
- * @return string tag name of the bulleted list
- */
- protected function getTagName()
- {
- switch($this->getBulletStyle())
- {
- case 'Numbered':
- case 'LowerAlpha':
- case 'UpperAlpha':
- case 'LowerRoman':
- case 'UpperRoman':
- return 'ol';
- }
- return 'ul';
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TBulletedList';
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional bulleted list specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $needStart=false;
- switch($this->getBulletStyle())
- {
- case 'Numbered':
- $writer->addStyleAttribute('list-style-type','decimal');
- $needStart=true;
- break;
- case 'LowerAlpha':
- $writer->addStyleAttribute('list-style-type','lower-alpha');
- $needStart=true;
- break;
- case 'UpperAlpha':
- $writer->addStyleAttribute('list-style-type','upper-alpha');
- $needStart=true;
- break;
- case 'LowerRoman':
- $writer->addStyleAttribute('list-style-type','lower-roman');
- $needStart=true;
- break;
- case 'UpperRoman':
- $writer->addStyleAttribute('list-style-type','upper-roman');
- $needStart=true;
- break;
- case 'Disc':
- $writer->addStyleAttribute('list-style-type','disc');
- break;
- case 'Circle':
- $writer->addStyleAttribute('list-style-type','circle');
- break;
- case 'Square':
- $writer->addStyleAttribute('list-style-type','square');
- break;
- case 'CustomImage':
- $url=$this->getBulletImageUrl();
- $writer->addStyleAttribute('list-style-image',"url($url)");
- break;
- }
- if($needStart && ($start=$this->getFirstBulletNumber())!=1)
- $writer->addAttribute('start',"$start");
- parent::addAttributesToRender($writer);
- }
-
- /**
- * @return string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
- */
- public function getBulletImageUrl()
- {
- return $this->getViewState('BulletImageUrl','');
- }
-
- /**
- * @param string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
- */
- public function setBulletImageUrl($value)
- {
- $this->setViewState('BulletImageUrl',$value,'');
- }
-
- /**
- * @return string style of bullets. Defaults to 'NotSet'.
- */
- public function getBulletStyle()
- {
- return $this->getViewState('BulletStyle','NotSet');
- }
-
- /**
- * @return string style of bullets. Valid values include
- * 'NotSet','Numbered','LowerAlpha','UpperAlpha','LowerRoman','UpperRoman','Disc','Circle','Square','CustomImage'
- */
- public function setBulletStyle($value)
- {
- $this->setViewState('BulletStyle',TPropertyValue::ensureEnum($value,'NotSet','Numbered','LowerAlpha','UpperAlpha','LowerRoman','UpperRoman','Disc','Circle','Square','CustomImage'),'NotSet');
- }
-
- /**
- * @param string display mode of the list. Defaults to 'Text'.
- */
- public function getDisplayMode()
- {
- return $this->getViewState('DisplayMode','Text');
- }
-
- /**
- * @return string display mode of the list. Valid values include
- * 'Text', 'HyperLink', 'LinkButton'.
- */
- public function setDisplayMode($value)
- {
- $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'Text','HyperLink','LinkButton'),'Text');
- }
-
- /**
- * @return integer starting index when {@link getBulletStyle BulletStyle} is one of
- * the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
- * Defaults to 1.
- */
- public function getFirstBulletNumber()
- {
- return $this->getViewState('FirstBulletNumber',1);
- }
-
- /**
- * @param integer starting index when {@link getBulletStyle BulletStyle} is one of
- * the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
- */
- public function setFirstBulletNumber($value)
- {
- $this->setViewState('FirstBulletNumber',TPropertyValue::ensureInteger($value),1);
- }
-
- /**
- * Raises 'OnClick' event.
- * This method is invoked when the {@link getDisplayMode DisplayMode} is 'LinkButton'
- * and end-users click on one of the buttons.
- * @param TBulletedListEventParameter event parameter.
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-
- /**
- * @return string the target window or frame to display the Web page content
- * linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
- * the hyperlinks is clicked.
- */
- public function getTarget()
- {
- return $this->getViewState('Target','');
- }
-
- /**
- * @param string the target window or frame to display the Web page content
- * linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
- * the hyperlinks is clicked.
- */
- public function setTarget($value)
- {
- $this->setViewState('Target',$value,'');
- }
-
- /**
- * Renders the control.
- * @param THtmlWriter the writer for the rendering purpose.
- */
- public function render($writer)
- {
- if($this->getHasItems())
- parent::render($writer);
- }
-
- /**
- * Renders the body contents.
- * @param THtmlWriter the writer for the rendering purpose.
- */
- public function renderContents($writer)
- {
- $this->_isEnabled=$this->getEnabled(true);
- $this->_postBackOptions=$this->getPostBackOptions();
- $writer->writeLine();
- foreach($this->getItems() as $index=>$item)
- {
- if($item->getHasAttributes())
- $writer->addAttributes($item->getAttributes());
- $writer->renderBeginTag('li');
- $this->renderBulletText($writer,$item,$index);
- $writer->renderEndTag();
- $writer->writeLine();
- }
- }
-
- /**
- * Renders each item
- * @param THtmlWriter writer for the rendering purpose
- * @param TListItem item to be rendered
- * @param integer index of the item being rendered
- */
- protected function renderBulletText($writer,$item,$index)
- {
- switch($this->getDisplayMode())
- {
- case 'Text':
- $this->renderTextItem($writer, $item, $index);
- break;
- case 'HyperLink':
- $this->renderHyperLinkItem($writer, $item, $index);
- break;
- case 'LinkButton':
- $this->renderLinkButtonItem($writer, $item, $index);
- break;
- }
- }
-
- protected function renderTextItem($writer, $item, $index)
- {
- if($item->getEnabled())
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- else
- {
- $writer->addAttribute('disabled','disabled');
- $writer->renderBeginTag('span');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- }
- }
-
- protected function renderHyperLinkItem($writer, $item, $index)
- {
- if(!$this->_isEnabled || !$item->getEnabled())
- $writer->addAttribute('disabled','disabled');
- else
- {
- $writer->addAttribute('href',$item->getValue());
- if(($target=$this->getTarget())!=='')
- $writer->addAttribute('target',$target);
- }
- if(($accesskey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accesskey);
- $writer->renderBeginTag('a');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- }
-
- protected function renderLinkButtonItem($writer, $item, $index)
- {
- if(!$this->_isEnabled || !$item->getEnabled())
- $writer->addAttribute('disabled','disabled');
- else
- {
- $this->_currentRenderItemIndex = $index;
- $writer->addAttribute('id', $this->getClientID().$index);
- $writer->addAttribute('href', "javascript:;//".$this->getClientID().$index);
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl('Prado.WebUI.TBulletedList',$this->getPostBackOptions());
- }
- if(($accesskey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accesskey);
- $writer->renderBeginTag('a');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- }
-
- /**
- * @return array postback options used for linkbuttons.
- */
- protected function getPostBackOptions()
- {
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['EventTarget'] = $this->getUniqueID();
- $options['EventParameter'] = $this->_currentRenderItemIndex;
- $options['ID'] = $this->getClientID().$this->_currentRenderItemIndex;
- $options['StopEvent'] = true;
- return $options;
- }
-
- protected function canCauseValidation()
- {
- $group = $this->getValidationGroup();
- $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
- return $this->getCausesValidation() && $hasValidators;
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setAutoPostBack($value)
- {
- throw new TNotSupportedException('bulletedlist_autopostback_unsupported');
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedIndex($index)
- {
- throw new TNotSupportedException('bulletedlist_selectedindex_unsupported');
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedIndices($indices)
- {
- throw new TNotSupportedException('bulletedlist_selectedindices_unsupported');
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedValue($value)
- {
- throw new TNotSupportedException('bulletedlist_selectedvalue_unsupported');
- }
-}
-
-/**
- * TBulletedListEventParameter
- * Event parameter for {@link TBulletedList::onClick Click} event of the
- * bulleted list. The {@link getIndex Index} gives the zero-based index
- * of the item that is currently being clicked.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TBulletedListEventParameter extends TEventParameter
-{
- /**
- * @var integer index of the item clicked
- */
- private $_index;
-
- /**
- * Constructor.
- * @param integer index of the item clicked
- */
- public function __construct($index)
- {
- $this->_index=$index;
- }
-
- /**
- * @return integer zero-based index of the item (rendered as a link button) that is clicked
- */
- public function getIndex()
- {
- return $this->_index;
- }
-}
+<?php
+/**
+ * TBulletedList class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TListControl class
+ */
+Prado::using('System.Web.UI.WebControls.TListControl');
+
+/**
+ * TBulletedList class
+ *
+ * TBulletedList displays items in a bullet format.
+ * The bullet style is specified by {@link setBulletStyle BulletStyle}. When
+ * the style is 'CustomImage', the {@link setBackImageUrl BulletImageUrl}
+ * specifies the image used as bullets.
+ *
+ * TBulletedList displays the item texts in three different modes, specified
+ * via {@link setDisplayMode DisplayMode}. When the mode is 'Text', the item texts
+ * are displayed as static texts; When the mode is 'HyperLink', each item
+ * is displayed as a hyperlink whose URL is given by the item value, and the
+ * {@link setTarget Target} property can be used to specify the target browser window;
+ * When the mode is 'LinkButton', each item is displayed as a link button which
+ * posts back to the page if a user clicks on that and the event {@link onClick OnClick}
+ * will be raised under such a circumstance.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TBulletedList extends TListControl implements IPostBackEventHandler
+{
+ /**
+ * @var boolean cached property value of Enabled
+ */
+ private $_isEnabled;
+ /**
+ * @var TPostBackOptions postback options
+ */
+ private $_postBackOptions;
+
+ private $_currentRenderItemIndex;
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick OnClick} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(new TBulletedListEventParameter((int)$param));
+ }
+
+ /**
+ * @return string tag name of the bulleted list
+ */
+ protected function getTagName()
+ {
+ switch($this->getBulletStyle())
+ {
+ case 'Numbered':
+ case 'LowerAlpha':
+ case 'UpperAlpha':
+ case 'LowerRoman':
+ case 'UpperRoman':
+ return 'ol';
+ }
+ return 'ul';
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TBulletedList';
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional bulleted list specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $needStart=false;
+ switch($this->getBulletStyle())
+ {
+ case 'Numbered':
+ $writer->addStyleAttribute('list-style-type','decimal');
+ $needStart=true;
+ break;
+ case 'LowerAlpha':
+ $writer->addStyleAttribute('list-style-type','lower-alpha');
+ $needStart=true;
+ break;
+ case 'UpperAlpha':
+ $writer->addStyleAttribute('list-style-type','upper-alpha');
+ $needStart=true;
+ break;
+ case 'LowerRoman':
+ $writer->addStyleAttribute('list-style-type','lower-roman');
+ $needStart=true;
+ break;
+ case 'UpperRoman':
+ $writer->addStyleAttribute('list-style-type','upper-roman');
+ $needStart=true;
+ break;
+ case 'Disc':
+ $writer->addStyleAttribute('list-style-type','disc');
+ break;
+ case 'Circle':
+ $writer->addStyleAttribute('list-style-type','circle');
+ break;
+ case 'Square':
+ $writer->addStyleAttribute('list-style-type','square');
+ break;
+ case 'CustomImage':
+ $url=$this->getBulletImageUrl();
+ $writer->addStyleAttribute('list-style-image',"url($url)");
+ break;
+ }
+ if($needStart && ($start=$this->getFirstBulletNumber())!=1)
+ $writer->addAttribute('start',"$start");
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * @return string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
+ */
+ public function getBulletImageUrl()
+ {
+ return $this->getViewState('BulletImageUrl','');
+ }
+
+ /**
+ * @param string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
+ */
+ public function setBulletImageUrl($value)
+ {
+ $this->setViewState('BulletImageUrl',$value,'');
+ }
+
+ /**
+ * @return string style of bullets. Defaults to 'NotSet'.
+ */
+ public function getBulletStyle()
+ {
+ return $this->getViewState('BulletStyle','NotSet');
+ }
+
+ /**
+ * @return string style of bullets. Valid values include
+ * 'NotSet','Numbered','LowerAlpha','UpperAlpha','LowerRoman','UpperRoman','Disc','Circle','Square','CustomImage'
+ */
+ public function setBulletStyle($value)
+ {
+ $this->setViewState('BulletStyle',TPropertyValue::ensureEnum($value,'NotSet','Numbered','LowerAlpha','UpperAlpha','LowerRoman','UpperRoman','Disc','Circle','Square','CustomImage'),'NotSet');
+ }
+
+ /**
+ * @param string display mode of the list. Defaults to 'Text'.
+ */
+ public function getDisplayMode()
+ {
+ return $this->getViewState('DisplayMode','Text');
+ }
+
+ /**
+ * @return string display mode of the list. Valid values include
+ * 'Text', 'HyperLink', 'LinkButton'.
+ */
+ public function setDisplayMode($value)
+ {
+ $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'Text','HyperLink','LinkButton'),'Text');
+ }
+
+ /**
+ * @return integer starting index when {@link getBulletStyle BulletStyle} is one of
+ * the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
+ * Defaults to 1.
+ */
+ public function getFirstBulletNumber()
+ {
+ return $this->getViewState('FirstBulletNumber',1);
+ }
+
+ /**
+ * @param integer starting index when {@link getBulletStyle BulletStyle} is one of
+ * the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
+ */
+ public function setFirstBulletNumber($value)
+ {
+ $this->setViewState('FirstBulletNumber',TPropertyValue::ensureInteger($value),1);
+ }
+
+ /**
+ * Raises 'OnClick' event.
+ * This method is invoked when the {@link getDisplayMode DisplayMode} is 'LinkButton'
+ * and end-users click on one of the buttons.
+ * @param TBulletedListEventParameter event parameter.
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+
+ /**
+ * @return string the target window or frame to display the Web page content
+ * linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
+ * the hyperlinks is clicked.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * @param string the target window or frame to display the Web page content
+ * linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
+ * the hyperlinks is clicked.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',$value,'');
+ }
+
+ /**
+ * Renders the control.
+ * @param THtmlWriter the writer for the rendering purpose.
+ */
+ public function render($writer)
+ {
+ if($this->getHasItems())
+ parent::render($writer);
+ }
+
+ /**
+ * Renders the body contents.
+ * @param THtmlWriter the writer for the rendering purpose.
+ */
+ public function renderContents($writer)
+ {
+ $this->_isEnabled=$this->getEnabled(true);
+ $this->_postBackOptions=$this->getPostBackOptions();
+ $writer->writeLine();
+ foreach($this->getItems() as $index=>$item)
+ {
+ if($item->getHasAttributes())
+ $writer->addAttributes($item->getAttributes());
+ $writer->renderBeginTag('li');
+ $this->renderBulletText($writer,$item,$index);
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ }
+
+ /**
+ * Renders each item
+ * @param THtmlWriter writer for the rendering purpose
+ * @param TListItem item to be rendered
+ * @param integer index of the item being rendered
+ */
+ protected function renderBulletText($writer,$item,$index)
+ {
+ switch($this->getDisplayMode())
+ {
+ case 'Text':
+ $this->renderTextItem($writer, $item, $index);
+ break;
+ case 'HyperLink':
+ $this->renderHyperLinkItem($writer, $item, $index);
+ break;
+ case 'LinkButton':
+ $this->renderLinkButtonItem($writer, $item, $index);
+ break;
+ }
+ }
+
+ protected function renderTextItem($writer, $item, $index)
+ {
+ if($item->getEnabled())
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ else
+ {
+ $writer->addAttribute('disabled','disabled');
+ $writer->renderBeginTag('span');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ }
+ }
+
+ protected function renderHyperLinkItem($writer, $item, $index)
+ {
+ if(!$this->_isEnabled || !$item->getEnabled())
+ $writer->addAttribute('disabled','disabled');
+ else
+ {
+ $writer->addAttribute('href',$item->getValue());
+ if(($target=$this->getTarget())!=='')
+ $writer->addAttribute('target',$target);
+ }
+ if(($accesskey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accesskey);
+ $writer->renderBeginTag('a');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ }
+
+ protected function renderLinkButtonItem($writer, $item, $index)
+ {
+ if(!$this->_isEnabled || !$item->getEnabled())
+ $writer->addAttribute('disabled','disabled');
+ else
+ {
+ $this->_currentRenderItemIndex = $index;
+ $writer->addAttribute('id', $this->getClientID().$index);
+ $writer->addAttribute('href', "javascript:;//".$this->getClientID().$index);
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl('Prado.WebUI.TBulletedList',$this->getPostBackOptions());
+ }
+ if(($accesskey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accesskey);
+ $writer->renderBeginTag('a');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ }
+
+ /**
+ * @return array postback options used for linkbuttons.
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['EventParameter'] = $this->_currentRenderItemIndex;
+ $options['ID'] = $this->getClientID().$this->_currentRenderItemIndex;
+ $options['StopEvent'] = true;
+ return $options;
+ }
+
+ protected function canCauseValidation()
+ {
+ $group = $this->getValidationGroup();
+ $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
+ return $this->getCausesValidation() && $hasValidators;
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setAutoPostBack($value)
+ {
+ throw new TNotSupportedException('bulletedlist_autopostback_unsupported');
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedIndex($index)
+ {
+ throw new TNotSupportedException('bulletedlist_selectedindex_unsupported');
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedIndices($indices)
+ {
+ throw new TNotSupportedException('bulletedlist_selectedindices_unsupported');
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedValue($value)
+ {
+ throw new TNotSupportedException('bulletedlist_selectedvalue_unsupported');
+ }
+}
+
+/**
+ * TBulletedListEventParameter
+ * Event parameter for {@link TBulletedList::onClick Click} event of the
+ * bulleted list. The {@link getIndex Index} gives the zero-based index
+ * of the item that is currently being clicked.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TBulletedListEventParameter extends TEventParameter
+{
+ /**
+ * @var integer index of the item clicked
+ */
+ private $_index;
+
+ /**
+ * Constructor.
+ * @param integer index of the item clicked
+ */
+ public function __construct($index)
+ {
+ $this->_index=$index;
+ }
+
+ /**
+ * @return integer zero-based index of the item (rendered as a link button) that is clicked
+ */
+ public function getIndex()
+ {
+ return $this->_index;
+ }
+}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php
index f1302853..3bc11c3c 100644
--- a/framework/Web/UI/WebControls/TButton.php
+++ b/framework/Web/UI/WebControls/TButton.php
@@ -1,257 +1,257 @@
-<?php
-/**
- * TButton class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TButton class
- *
- * TButton creates a click button on the page. It is used to submit data to a page.
- * You can create either a <b>submit</b> button or a <b>command</b> button.
- *
- * A <b>command</b> button has a command name (specified by
- * the {@link setCommandName CommandName} property) and and a command parameter
- * (specified by {@link setCommandParameter CommandParameter} property)
- * associated with the button. This allows you to create multiple TButton
- * components on a Web page and programmatically determine which one is clicked
- * with what parameter. You can provide an event handler for
- * {@link onCommand OnCommand} event to programmatically control the actions performed
- * when the command button is clicked. In the event handler, you can determine
- * the {@link setCommandName CommandName} property value and
- * the {@link setCommandParameter CommandParameter} property value
- * through the {@link TCommandParameter::getName Name} and
- * {@link TCommandParameter::getParameter Parameter} properties of the event
- * parameter which is of type {@link TCommandEventParameter}.
- *
- * A <b>submit</b> button does not have a command name associated with the button
- * and clicking on it simply posts the Web page back to the server.
- * By default, a TButton component is a submit button.
- * You can provide an event handler for the {@link onClick OnClick} event
- * to programmatically control the actions performed when the submit button is clicked.
- *
- * Clicking on button can trigger form validation, if
- * {@link setCausesValidation CausesValidation} is true.
- * And the validation may be restricted within a certain group of validator
- * controls by setting {@link setValidationGroup ValidationGroup} property.
- * If validation is successful, the data will be post back to the same page.
- *
- * TButton displays the {@link setText Text} property as the button caption.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TButton extends TWebControl implements IPostBackEventHandler, IButtonControl
-{
- /**
- * @return string tag name of the button
- */
- protected function getTagName()
- {
- return 'input';
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional button specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
- $writer->addAttribute('type','submit');
- if(($uniqueID=$this->getUniqueID())!=='')
- $writer->addAttribute('name',$uniqueID);
- $writer->addAttribute('value',$this->getText());
- if($this->getEnabled(true) )
- $this->renderClientControlScript($writer);
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
-
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- if($this->canCauseValidation())
- {
- $writer->addAttribute('id',$this->getClientID());
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl('Prado.WebUI.TButton',$this->getPostBackOptions());
- }
- }
-
- /**
- * @return boolean whether to perform validation if the button is clicked
- */
- protected function canCauseValidation()
- {
- if($this->getCausesValidation())
- {
- $group=$this->getValidationGroup();
- return $this->getPage()->getValidators($group)->getCount()>0;
- }
- else
- return false;
- }
-
- /**
- * Returns postback specifications for the button.
- * This method is used by framework and control developers.
- * @return array parameters about how the button defines its postback behavior.
- */
- protected function getPostBackOptions()
- {
- $options['ID']=$this->getClientID();
- $options['CausesValidation']=$this->getCausesValidation();
- $options['EventTarget'] = $this->getUniqueID();
- $options['ValidationGroup']=$this->getValidationGroup();
-
- return $options;
- }
-
- /**
- * Renders the body content enclosed between the control tag.
- * This overrides the parent implementation with nothing to be rendered.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderContents($writer)
- {
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnClick' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handler can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnCommand' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TCommandEventParameter event parameter to be passed to the event handlers
- */
- public function onCommand($param)
- {
- $this->raiseEvent('OnCommand',$this,$param);
- $this->raiseBubbleEvent($this,$param);
- }
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * If {@link getCausesValidation CausesValidation} is true, it will
- * invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- if($this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onClick(null);
- $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
- }
-
- /**
- * @return string caption of the button
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * @param string caption of the button
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * @return boolean whether postback event trigger by this button will cause input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this button will cause input validation
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function getCommandName()
- {
- return $this->getViewState('CommandName','');
- }
-
- /**
- * @param string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandName($value)
- {
- $this->setViewState('CommandName',$value,'');
- }
-
- /**
- * @return string the parameter associated with the {@link onCommand OnCommand} event
- */
- public function getCommandParameter()
- {
- return $this->getViewState('CommandParameter','');
- }
-
- /**
- * @param string the parameter associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandParameter($value)
- {
- $this->setViewState('CommandParameter',$value,'');
- }
-
- /**
- * @return string the group of validators which the button causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the button causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-}
-
+<?php
+/**
+ * TButton class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TButton class
+ *
+ * TButton creates a click button on the page. It is used to submit data to a page.
+ * You can create either a <b>submit</b> button or a <b>command</b> button.
+ *
+ * A <b>command</b> button has a command name (specified by
+ * the {@link setCommandName CommandName} property) and and a command parameter
+ * (specified by {@link setCommandParameter CommandParameter} property)
+ * associated with the button. This allows you to create multiple TButton
+ * components on a Web page and programmatically determine which one is clicked
+ * with what parameter. You can provide an event handler for
+ * {@link onCommand OnCommand} event to programmatically control the actions performed
+ * when the command button is clicked. In the event handler, you can determine
+ * the {@link setCommandName CommandName} property value and
+ * the {@link setCommandParameter CommandParameter} property value
+ * through the {@link TCommandParameter::getName Name} and
+ * {@link TCommandParameter::getParameter Parameter} properties of the event
+ * parameter which is of type {@link TCommandEventParameter}.
+ *
+ * A <b>submit</b> button does not have a command name associated with the button
+ * and clicking on it simply posts the Web page back to the server.
+ * By default, a TButton component is a submit button.
+ * You can provide an event handler for the {@link onClick OnClick} event
+ * to programmatically control the actions performed when the submit button is clicked.
+ *
+ * Clicking on button can trigger form validation, if
+ * {@link setCausesValidation CausesValidation} is true.
+ * And the validation may be restricted within a certain group of validator
+ * controls by setting {@link setValidationGroup ValidationGroup} property.
+ * If validation is successful, the data will be post back to the same page.
+ *
+ * TButton displays the {@link setText Text} property as the button caption.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TButton extends TWebControl implements IPostBackEventHandler, IButtonControl
+{
+ /**
+ * @return string tag name of the button
+ */
+ protected function getTagName()
+ {
+ return 'input';
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional button specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+ $writer->addAttribute('type','submit');
+ if(($uniqueID=$this->getUniqueID())!=='')
+ $writer->addAttribute('name',$uniqueID);
+ $writer->addAttribute('value',$this->getText());
+ if($this->getEnabled(true) )
+ $this->renderClientControlScript($writer);
+ else if($this->getEnabled()) // in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ if($this->canCauseValidation())
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl('Prado.WebUI.TButton',$this->getPostBackOptions());
+ }
+ }
+
+ /**
+ * @return boolean whether to perform validation if the button is clicked
+ */
+ protected function canCauseValidation()
+ {
+ if($this->getCausesValidation())
+ {
+ $group=$this->getValidationGroup();
+ return $this->getPage()->getValidators($group)->getCount()>0;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Returns postback specifications for the button.
+ * This method is used by framework and control developers.
+ * @return array parameters about how the button defines its postback behavior.
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID']=$this->getClientID();
+ $options['CausesValidation']=$this->getCausesValidation();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['ValidationGroup']=$this->getValidationGroup();
+
+ return $options;
+ }
+
+ /**
+ * Renders the body content enclosed between the control tag.
+ * This overrides the parent implementation with nothing to be rendered.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnClick' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handler can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnCommand' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TCommandEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCommand($param)
+ {
+ $this->raiseEvent('OnCommand',$this,$param);
+ $this->raiseBubbleEvent($this,$param);
+ }
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(null);
+ $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
+ }
+
+ /**
+ * @return string caption of the button
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string caption of the button
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this button will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function getCommandName()
+ {
+ return $this->getViewState('CommandName','');
+ }
+
+ /**
+ * @param string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandName($value)
+ {
+ $this->setViewState('CommandName',$value,'');
+ }
+
+ /**
+ * @return string the parameter associated with the {@link onCommand OnCommand} event
+ */
+ public function getCommandParameter()
+ {
+ return $this->getViewState('CommandParameter','');
+ }
+
+ /**
+ * @param string the parameter associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandParameter($value)
+ {
+ $this->setViewState('CommandParameter',$value,'');
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php
index 37ea0369..8a8ace7a 100644
--- a/framework/Web/UI/WebControls/TCheckBox.php
+++ b/framework/Web/UI/WebControls/TCheckBox.php
@@ -1,397 +1,397 @@
-<?php
-/**
- * TCheckBox class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TCheckBox class
- *
- * TCheckBox displays a check box on the page.
- * You can specify the caption to display beside the check box by setting
- * the {@link setText Text} property. The caption can appear either on the right
- * or left of the check box, which is determined by the {@link setTextAlign TextAlign}
- * property.
- *
- * To determine whether the TCheckBox component is checked, test the {@link getChecked Checked}
- * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when
- * the {@link getChecked Checked} state of the TCheckBox component changes
- * between posts to the server. You can provide an event handler for
- * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically
- * control the actions performed when the state of the TCheckBox component changes
- * between posts to the server.
- *
- * If {@link setAutoPostBack AutoPostBack} is set true, changing the check box state
- * 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}.
- *
- * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters
- * that may bring security vulnerabilities.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatable
-{
- /**
- * @return string tag name of the button
- */
- protected function getTagName()
- {
- return 'input';
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values)
- {
- $checked=$this->getChecked();
- if(isset($values[$key])!=$checked)
- {
- $this->setChecked(!$checked);
- return true;
- }
- else
- return false;
- }
-
- /**
- * Raises postdata changed event.
- * This method raises {@link onCheckedChanged OnCheckedChanged} event.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- if($this->getAutoPostBack() && $this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onCheckedChanged(null);
- }
-
- /**
- * Raises <b>OnCheckedChanged</b> event when {@link getChecked Checked} changes value during postback.
- * If you override this method, be sure to call the parent implementation
- * so that the event delegates can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onCheckedChanged($param)
- {
- $this->raiseEvent('OnCheckedChanged',$this,$param);
- }
-
- /**
- * Registers the checkbox to receive postback data during postback.
- * This is necessary because a checkbox if unchecked, when postback,
- * does not have direct mapping between post data and the checkbox name.
- *
- * This method overrides the parent implementation and is invoked before render.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if($this->getEnabled(true))
- $this->getPage()->registerRequiresPostData($this);
- }
-
- /**
- * Returns the value of the property that needs validation.
- * @return mixed the property value to be validated
- */
- public function getValidationPropertyValue()
- {
- return $this->getChecked();
- }
-
- /**
- * @return string the text caption of the checkbox
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text caption of the checkbox.
- * @param string the text caption to be set
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * @return string the alignment (Left or Right) of the text caption, defaults to Right.
- */
- public function getTextAlign()
- {
- return $this->getViewState('TextAlign','Right');
- }
-
- /**
- * @param string the alignment of the text caption. Valid values include Left and Right.
- */
- public function setTextAlign($value)
- {
- $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,array('Left','Right')),'Right');
- }
-
- /**
- * @return boolean whether the checkbox is checked
- */
- public function getChecked()
- {
- return $this->getViewState('Checked',false);
- }
-
- /**
- * Sets a value indicating whether the checkbox is to be checked or not.
- * @param boolean whether the checkbox is to be checked or not.
- */
- public function setChecked($value)
- {
- $this->setViewState('Checked',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether clicking on the checkbox will post the page.
- */
- public function getAutoPostBack()
- {
- return $this->getViewState('AutoPostBack',false);
- }
-
- /**
- * Sets a value indicating whether clicking on the checkbox will post the page.
- * @param boolean whether clicking on the checkbox will post the page.
- */
- public function setAutoPostBack($value)
- {
- $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether postback event triggered by this checkbox will cause input validation, default is true.
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * Sets the value indicating whether postback event trigger by this checkbox will cause input validation.
- * @param boolean whether postback event trigger by this checkbox will cause input validation.
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the checkbox causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the checkbox causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * Renders the checkbox control.
- * This method overrides the parent implementation by rendering a checkbox input element
- * and a span element if needed.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function render($writer)
- {
- $this->getPage()->ensureRenderInForm($this);
- $needSpan=false;
- if($this->getHasStyle())
- {
- $this->getStyle()->addAttributesToRender($writer);
- $needSpan=true;
- }
- if(($tooltip=$this->getToolTip())!=='')
- {
- $writer->addAttribute('title',$tooltip);
- $needSpan=true;
- }
- if($this->getHasAttributes())
- {
- $attributes=$this->getAttributes();
- $value=$attributes->remove('value');
- // onclick js should only be added to input tag
- $onclick=$attributes->remove('onclick');
- if($attributes->getCount())
- {
- $writer->addAttributes($attributes);
- $needSpan=true;
- }
- if($value!==null)
- $attributes->add('value',$value);
- }
- else
- $onclick='';
- if($needSpan)
- $writer->renderBeginTag('span');
- $clientID=$this->getClientID();
- if(($text=$this->getText())!=='')
- {
- if($this->getTextAlign()==='Left')
- {
- $this->renderLabel($writer,$clientID,$text);
- $this->renderInputTag($writer,$clientID,$onclick);
- }
- else
- {
- $this->renderInputTag($writer,$clientID,$onclick);
- $this->renderLabel($writer,$clientID,$text);
- }
- }
- else
- $this->renderInputTag($writer,$clientID,$onclick);
- if($needSpan)
- $writer->renderEndTag();
- }
-
- /**
- * @return TMap list of attributes to be rendered for label beside the checkbox
- */
- public function getLabelAttributes()
- {
- if($attributes=$this->getViewState('LabelAttributes',null))
- return $attributes;
- else
- {
- $attributes=new TAttributeCollection;
- $this->setViewState('LabelAttributes',$attributes,null);
- return $attributes;
- }
- }
-
- /**
- * @return TMap list of attributes to be rendered for the checkbox
- */
- public function getInputAttributes()
- {
- if($attributes=$this->getViewState('InputAttributes',null))
- return $attributes;
- else
- {
- $attributes=new TAttributeCollection;
- $this->setViewState('InputAttributes',$attributes,null);
- return $attributes;
- }
- }
-
- /**
- * @return string the value attribute to be rendered
- */
- protected function getValueAttribute()
- {
- $attributes=$this->getViewState('InputAttributes',null);
- if($attributes && $attributes->contains('value'))
- return $attributes->itemAt('value');
- else if($this->hasAttribute('value'))
- return $this->getAttribute('value');
- else
- return '';
- }
-
- /**
- * Renders a label beside the checkbox.
- * @param THtmlWriter the writer for the rendering purpose
- * @param string checkbox id
- * @param string label text
- */
- protected function renderLabel($writer,$clientID,$text)
- {
- $writer->addAttribute('for',$clientID);
- if($attributes=$this->getViewState('LabelAttributes',null))
- $writer->addAttributes($attributes);
- $writer->renderBeginTag('label');
- $writer->write($text);
- $writer->renderEndTag();
- }
-
- /**
- * Renders a checkbox input element.
- * @param THtmlWriter the writer for the rendering purpose
- * @param string checkbox id
- * @param string onclick js
- */
- protected function renderInputTag($writer,$clientID,$onclick)
- {
- if($clientID!=='')
- $writer->addAttribute('id',$clientID);
- $writer->addAttribute('type','checkbox');
- if(($value = $this->getValueAttribute()) !== '')
- $writer->addAttribute('value',$value);
- if($onclick!=='')
- $writer->addAttribute('onclick',$onclick);
- if(($uniqueID=$this->getUniqueID())!=='')
- $writer->addAttribute('name',$uniqueID);
- if($this->getChecked())
- $writer->addAttribute('checked','checked');
- if(!$this->getEnabled(true))
- $writer->addAttribute('disabled','disabled');
-
- $page=$this->getPage();
- if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- $this->renderClientControlScript($writer);
-
- if(($accesskey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accesskey);
- if(($tabindex=$this->getTabIndex())>0)
- $writer->addAttribute('tabindex',"$tabindex");
- if($attributes=$this->getViewState('InputAttributes',null))
- $writer->addAttributes($attributes);
- $writer->renderBeginTag('input');
- $writer->renderEndTag();
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl('Prado.WebUI.TCheckBox',$this->getPostBackOptions());
- }
-
- /**
- * Gets the post back options for this checkbox.
- * @return array
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['EventTarget'] = $this->getUniqueID();
- return $options;
- }
-
-}
-
+<?php
+/**
+ * TCheckBox class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TCheckBox class
+ *
+ * TCheckBox displays a check box on the page.
+ * You can specify the caption to display beside the check box by setting
+ * the {@link setText Text} property. The caption can appear either on the right
+ * or left of the check box, which is determined by the {@link setTextAlign TextAlign}
+ * property.
+ *
+ * To determine whether the TCheckBox component is checked, test the {@link getChecked Checked}
+ * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when
+ * the {@link getChecked Checked} state of the TCheckBox component changes
+ * between posts to the server. You can provide an event handler for
+ * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically
+ * control the actions performed when the state of the TCheckBox component changes
+ * between posts to the server.
+ *
+ * If {@link setAutoPostBack AutoPostBack} is set true, changing the check box state
+ * 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}.
+ *
+ * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters
+ * that may bring security vulnerabilities.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatable
+{
+ /**
+ * @return string tag name of the button
+ */
+ protected function getTagName()
+ {
+ return 'input';
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $checked=$this->getChecked();
+ if(isset($values[$key])!=$checked)
+ {
+ $this->setChecked(!$checked);
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method raises {@link onCheckedChanged OnCheckedChanged} event.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ if($this->getAutoPostBack() && $this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onCheckedChanged(null);
+ }
+
+ /**
+ * Raises <b>OnCheckedChanged</b> event when {@link getChecked Checked} changes value during postback.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event delegates can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCheckedChanged($param)
+ {
+ $this->raiseEvent('OnCheckedChanged',$this,$param);
+ }
+
+ /**
+ * Registers the checkbox to receive postback data during postback.
+ * This is necessary because a checkbox if unchecked, when postback,
+ * does not have direct mapping between post data and the checkbox name.
+ *
+ * This method overrides the parent implementation and is invoked before render.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if($this->getEnabled(true))
+ $this->getPage()->registerRequiresPostData($this);
+ }
+
+ /**
+ * Returns the value of the property that needs validation.
+ * @return mixed the property value to be validated
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getChecked();
+ }
+
+ /**
+ * @return string the text caption of the checkbox
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text caption of the checkbox.
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * @return string the alignment (Left or Right) of the text caption, defaults to Right.
+ */
+ public function getTextAlign()
+ {
+ return $this->getViewState('TextAlign','Right');
+ }
+
+ /**
+ * @param string the alignment of the text caption. Valid values include Left and Right.
+ */
+ public function setTextAlign($value)
+ {
+ $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,array('Left','Right')),'Right');
+ }
+
+ /**
+ * @return boolean whether the checkbox is checked
+ */
+ public function getChecked()
+ {
+ return $this->getViewState('Checked',false);
+ }
+
+ /**
+ * Sets a value indicating whether the checkbox is to be checked or not.
+ * @param boolean whether the checkbox is to be checked or not.
+ */
+ public function setChecked($value)
+ {
+ $this->setViewState('Checked',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether clicking on the checkbox will post the page.
+ */
+ public function getAutoPostBack()
+ {
+ return $this->getViewState('AutoPostBack',false);
+ }
+
+ /**
+ * Sets a value indicating whether clicking on the checkbox will post the page.
+ * @param boolean whether clicking on the checkbox will post the page.
+ */
+ public function setAutoPostBack($value)
+ {
+ $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether postback event triggered by this checkbox will cause input validation, default is true.
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * Sets the value indicating whether postback event trigger by this checkbox will cause input validation.
+ * @param boolean whether postback event trigger by this checkbox will cause input validation.
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the checkbox causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the checkbox causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * Renders the checkbox control.
+ * This method overrides the parent implementation by rendering a checkbox input element
+ * and a span element if needed.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function render($writer)
+ {
+ $this->getPage()->ensureRenderInForm($this);
+ $needSpan=false;
+ if($this->getHasStyle())
+ {
+ $this->getStyle()->addAttributesToRender($writer);
+ $needSpan=true;
+ }
+ if(($tooltip=$this->getToolTip())!=='')
+ {
+ $writer->addAttribute('title',$tooltip);
+ $needSpan=true;
+ }
+ if($this->getHasAttributes())
+ {
+ $attributes=$this->getAttributes();
+ $value=$attributes->remove('value');
+ // onclick js should only be added to input tag
+ $onclick=$attributes->remove('onclick');
+ if($attributes->getCount())
+ {
+ $writer->addAttributes($attributes);
+ $needSpan=true;
+ }
+ if($value!==null)
+ $attributes->add('value',$value);
+ }
+ else
+ $onclick='';
+ if($needSpan)
+ $writer->renderBeginTag('span');
+ $clientID=$this->getClientID();
+ if(($text=$this->getText())!=='')
+ {
+ if($this->getTextAlign()==='Left')
+ {
+ $this->renderLabel($writer,$clientID,$text);
+ $this->renderInputTag($writer,$clientID,$onclick);
+ }
+ else
+ {
+ $this->renderInputTag($writer,$clientID,$onclick);
+ $this->renderLabel($writer,$clientID,$text);
+ }
+ }
+ else
+ $this->renderInputTag($writer,$clientID,$onclick);
+ if($needSpan)
+ $writer->renderEndTag();
+ }
+
+ /**
+ * @return TMap list of attributes to be rendered for label beside the checkbox
+ */
+ public function getLabelAttributes()
+ {
+ if($attributes=$this->getViewState('LabelAttributes',null))
+ return $attributes;
+ else
+ {
+ $attributes=new TAttributeCollection;
+ $this->setViewState('LabelAttributes',$attributes,null);
+ return $attributes;
+ }
+ }
+
+ /**
+ * @return TMap list of attributes to be rendered for the checkbox
+ */
+ public function getInputAttributes()
+ {
+ if($attributes=$this->getViewState('InputAttributes',null))
+ return $attributes;
+ else
+ {
+ $attributes=new TAttributeCollection;
+ $this->setViewState('InputAttributes',$attributes,null);
+ return $attributes;
+ }
+ }
+
+ /**
+ * @return string the value attribute to be rendered
+ */
+ protected function getValueAttribute()
+ {
+ $attributes=$this->getViewState('InputAttributes',null);
+ if($attributes && $attributes->contains('value'))
+ return $attributes->itemAt('value');
+ else if($this->hasAttribute('value'))
+ return $this->getAttribute('value');
+ else
+ return '';
+ }
+
+ /**
+ * Renders a label beside the checkbox.
+ * @param THtmlWriter the writer for the rendering purpose
+ * @param string checkbox id
+ * @param string label text
+ */
+ protected function renderLabel($writer,$clientID,$text)
+ {
+ $writer->addAttribute('for',$clientID);
+ if($attributes=$this->getViewState('LabelAttributes',null))
+ $writer->addAttributes($attributes);
+ $writer->renderBeginTag('label');
+ $writer->write($text);
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Renders a checkbox input element.
+ * @param THtmlWriter the writer for the rendering purpose
+ * @param string checkbox id
+ * @param string onclick js
+ */
+ protected function renderInputTag($writer,$clientID,$onclick)
+ {
+ if($clientID!=='')
+ $writer->addAttribute('id',$clientID);
+ $writer->addAttribute('type','checkbox');
+ if(($value = $this->getValueAttribute()) !== '')
+ $writer->addAttribute('value',$value);
+ if($onclick!=='')
+ $writer->addAttribute('onclick',$onclick);
+ if(($uniqueID=$this->getUniqueID())!=='')
+ $writer->addAttribute('name',$uniqueID);
+ if($this->getChecked())
+ $writer->addAttribute('checked','checked');
+ if(!$this->getEnabled(true))
+ $writer->addAttribute('disabled','disabled');
+
+ $page=$this->getPage();
+ if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript())
+ $this->renderClientControlScript($writer);
+
+ if(($accesskey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accesskey);
+ if(($tabindex=$this->getTabIndex())>0)
+ $writer->addAttribute('tabindex',"$tabindex");
+ if($attributes=$this->getViewState('InputAttributes',null))
+ $writer->addAttributes($attributes);
+ $writer->renderBeginTag('input');
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl('Prado.WebUI.TCheckBox',$this->getPostBackOptions());
+ }
+
+ /**
+ * Gets the post back options for this checkbox.
+ * @return array
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['EventTarget'] = $this->getUniqueID();
+ return $options;
+ }
+
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php
index a746437b..27d080c6 100644
--- a/framework/Web/UI/WebControls/TDatePicker.php
+++ b/framework/Web/UI/WebControls/TDatePicker.php
@@ -721,11 +721,8 @@ class TDatePicker extends TTextBox
$spacer = $this->publishIFrameSpacer();
$code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
$cs->registerEndScript('TDatePicker.spacer', $code);
- }
-
- $options = TJavaScript::encode($this->getDatePickerOptions());
- $code = "new Prado.WebUI.TDatePicker($options);";
- $cs->registerEndScript("prado:".$this->getClientID(), $code);
+ }
+ $cs->registerPostBackControl('Prado.WebUI.TDatePicker', $this->getDatePickerOptions());
}
}
}
diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php
index f7f6408a..690a8eea 100644
--- a/framework/Web/UI/WebControls/TImageButton.php
+++ b/framework/Web/UI/WebControls/TImageButton.php
@@ -1,378 +1,378 @@
-<?php
-/**
- * TImageButton class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TImage class file
- */
-Prado::using('System.Web.UI.WebControls.TImage');
-
-/**
- * TImageButton class
- *
- * TImageButton creates an image button on the page. It is used to submit data to a page.
- * You can create either a <b>submit</b> button or a <b>command</b> button.
- *
- * A <b>command</b> button has a command name (specified by
- * the {@link setCommandName CommandName} property) and and a command parameter
- * (specified by {@link setCommandParameter CommandParameter} property)
- * associated with the button. This allows you to create multiple TLinkButton
- * components on a Web page and programmatically determine which one is clicked
- * with what parameter. You can provide an event handler for
- * {@link onCommand OnCommand} event to programmatically control the actions performed
- * when the command button is clicked. In the event handler, you can determine
- * the {@link setCommandName CommandName} property value and
- * the {@link setCommandParameter CommandParameter} property value
- * through the {@link TCommandParameter::getName Name} and
- * {@link TCommandParameter::getParameter Parameter} properties of the event
- * parameter which is of type {@link TCommandEventParameter}.
- *
- * A <b>submit</b> button does not have a command name associated with the button
- * and clicking on it simply posts the Web page back to the server.
- * By default, a TImageButton control is a submit button.
- * You can provide an event handler for the {@link onClick OnClick} event
- * to programmatically control the actions performed when the submit button is clicked.
- * The coordinates of the clicking point can be obtained from the {@link onClick OnClick}
- * event parameter, which is of type {@link TImageClickEventParameter}.
- *
- * Clicking on button can trigger form validation, if
- * {@link setCausesValidation CausesValidation} is true.
- * And the validation may be restricted within a certain group of validator
- * controls by setting {@link setValidationGroup ValidationGroup} property.
- * If validation is successful, the data will be post back to the same page.
- *
- * TImageButton displays the {@link setText Text} property as the hint text to the displayed image.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEventHandler, IButtonControl
-{
- /**
- * @var integer x coordinate that the image is being clicked at
- */
- private $_x=0;
- /**
- * @var integer y coordinate that the image is being clicked at
- */
- private $_y=0;
-
- /**
- * @return string tag name of the button
- */
- protected function getTagName()
- {
- return 'input';
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional button specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
- $writer->addAttribute('type','image');
- if(($uniqueID=$this->getUniqueID())!=='')
- $writer->addAttribute('name',$uniqueID);
- if($this->getEnabled(true))
- $this->renderClientControlScript($writer);
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- if($this->canCauseValidation())
- {
- $writer->addAttribute('id',$this->getClientID());
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl('Prado.WebUI.TImageButton',$this->getPostBackOptions());
- }
- }
- /**
- * @return boolean whether to perform validation if the button is clicked
- */
- protected function canCauseValidation()
- {
- if($this->getCausesValidation())
- {
- $group=$this->getValidationGroup();
- return $this->getPage()->getValidators($group)->getCount()>0;
- }
- else
- return false;
- }
-
- /**
- * Returns postback specifications for the button.
- * This method is used by framework and control developers.
- * @return array parameters about how the button defines its postback behavior.
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['EventTarget'] = $this->getUniqueID();
-
- return $options;
- }
-
- /**
- * This method checks if the TImageButton is clicked and loads the coordinates of the clicking position.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the component has been changed
- */
- public function loadPostData($key,$values)
- {
- $uid=$this->getUniqueID();
- if(isset($values["{$uid}_x"]) && isset($values["{$uid}_y"]))
- {
- $this->_x=intval($values["{$uid}_x"]);
- $this->_y=intval($values["{$uid}_y"]);
- $this->getPage()->setPostBackEventTarget($this);
- }
- return false;
- }
-
- /**
- * A dummy implementation for the IPostBackDataHandler interface.
- */
- public function raisePostDataChangedEvent()
- {
- // no post data to handle
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnClick' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handler can be invoked.
- * @param TImageClickEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnCommand' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TCommandEventParameter event parameter to be passed to the event handlers
- */
- public function onCommand($param)
- {
- $this->raiseEvent('OnCommand',$this,$param);
- $this->raiseBubbleEvent($this,$param);
- }
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * If {@link getCausesValidation CausesValidation} is true, it will
- * invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- if($this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onClick(new TImageClickEventParameter($this->_x,$this->_y));
- $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
- }
-
- /**
- * @return boolean whether postback event trigger by this button will cause input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this button will cause input validation
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function getCommandName()
- {
- return $this->getViewState('CommandName','');
- }
-
- /**
- * @param string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandName($value)
- {
- $this->setViewState('CommandName',$value,'');
- }
-
- /**
- * @return string the parameter associated with the {@link onCommand OnCommand} event
- */
- public function getCommandParameter()
- {
- return $this->getViewState('CommandParameter','');
- }
-
- /**
- * @param string the parameter associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandParameter($value)
- {
- $this->setViewState('CommandParameter',$value,'');
- }
-
- /**
- * @return string the group of validators which the button causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the button causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * @return string caption of the button
- */
- public function getText()
- {
- return $this->getAlternateText();
- }
-
- /**
- * @param string caption of the button
- */
- public function setText($value)
- {
- $this->setAlternateText($value);
- }
-
- /**
- * Registers the image button to receive postback data during postback.
- * This is necessary because an image button, when postback, does not have
- * direct mapping between post data and the image button name.
- * This method overrides the parent implementation and is invoked before render.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- $this->getPage()->registerRequiresPostData($this);
- }
-
- /**
- * Renders the body content enclosed between the control tag.
- * This overrides the parent implementation with nothing to be rendered.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderContents($writer)
- {
- }
-}
-
-/**
- * TImageClickEventParameter class
- *
- * TImageClickEventParameter encapsulates the parameter data for
- * {@link TImageButton::onClick Click} event of {@link TImageButton} controls.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImageClickEventParameter extends TEventParameter
-{
- /**
- * the X coordinate of the clicking point
- * @var integer
- */
- public $_x=0;
- /**
- * the Y coordinate of the clicking point
- * @var integer
- */
- public $_y=0;
-
- /**
- * Constructor.
- * @param integer X coordinate of the clicking point
- * @param integer Y coordinate of the clicking point
- */
- public function __construct($x,$y)
- {
- $this->_x=$x;
- $this->_y=$y;
- }
-
- /**
- * @return integer X coordinate of the clicking point, defaults to 0
- */
- public function getX()
- {
- return $this->_x;
- }
-
- /**
- * @param integer X coordinate of the clicking point
- */
- public function setX($value)
- {
- $this->_x=TPropertyValue::ensureInteger($value);
- }
-
- /**
- * @return integer Y coordinate of the clicking point, defaults to 0
- */
- public function getY()
- {
- return $this->_y;
- }
-
- /**
- * @param integer Y coordinate of the clicking point
- */
- public function setY($value)
- {
- $this->_y=TPropertyValue::ensureInteger($value);
- }
-}
-
+<?php
+/**
+ * TImageButton class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TImage class file
+ */
+Prado::using('System.Web.UI.WebControls.TImage');
+
+/**
+ * TImageButton class
+ *
+ * TImageButton creates an image button on the page. It is used to submit data to a page.
+ * You can create either a <b>submit</b> button or a <b>command</b> button.
+ *
+ * A <b>command</b> button has a command name (specified by
+ * the {@link setCommandName CommandName} property) and and a command parameter
+ * (specified by {@link setCommandParameter CommandParameter} property)
+ * associated with the button. This allows you to create multiple TLinkButton
+ * components on a Web page and programmatically determine which one is clicked
+ * with what parameter. You can provide an event handler for
+ * {@link onCommand OnCommand} event to programmatically control the actions performed
+ * when the command button is clicked. In the event handler, you can determine
+ * the {@link setCommandName CommandName} property value and
+ * the {@link setCommandParameter CommandParameter} property value
+ * through the {@link TCommandParameter::getName Name} and
+ * {@link TCommandParameter::getParameter Parameter} properties of the event
+ * parameter which is of type {@link TCommandEventParameter}.
+ *
+ * A <b>submit</b> button does not have a command name associated with the button
+ * and clicking on it simply posts the Web page back to the server.
+ * By default, a TImageButton control is a submit button.
+ * You can provide an event handler for the {@link onClick OnClick} event
+ * to programmatically control the actions performed when the submit button is clicked.
+ * The coordinates of the clicking point can be obtained from the {@link onClick OnClick}
+ * event parameter, which is of type {@link TImageClickEventParameter}.
+ *
+ * Clicking on button can trigger form validation, if
+ * {@link setCausesValidation CausesValidation} is true.
+ * And the validation may be restricted within a certain group of validator
+ * controls by setting {@link setValidationGroup ValidationGroup} property.
+ * If validation is successful, the data will be post back to the same page.
+ *
+ * TImageButton displays the {@link setText Text} property as the hint text to the displayed image.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEventHandler, IButtonControl
+{
+ /**
+ * @var integer x coordinate that the image is being clicked at
+ */
+ private $_x=0;
+ /**
+ * @var integer y coordinate that the image is being clicked at
+ */
+ private $_y=0;
+
+ /**
+ * @return string tag name of the button
+ */
+ protected function getTagName()
+ {
+ return 'input';
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional button specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+ $writer->addAttribute('type','image');
+ if(($uniqueID=$this->getUniqueID())!=='')
+ $writer->addAttribute('name',$uniqueID);
+ if($this->getEnabled(true))
+ $this->renderClientControlScript($writer);
+ else if($this->getEnabled()) // in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ if($this->canCauseValidation())
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl('Prado.WebUI.TImageButton',$this->getPostBackOptions());
+ }
+ }
+ /**
+ * @return boolean whether to perform validation if the button is clicked
+ */
+ protected function canCauseValidation()
+ {
+ if($this->getCausesValidation())
+ {
+ $group=$this->getValidationGroup();
+ return $this->getPage()->getValidators($group)->getCount()>0;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Returns postback specifications for the button.
+ * This method is used by framework and control developers.
+ * @return array parameters about how the button defines its postback behavior.
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['EventTarget'] = $this->getUniqueID();
+
+ return $options;
+ }
+
+ /**
+ * This method checks if the TImageButton is clicked and loads the coordinates of the clicking position.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the component has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $uid=$this->getUniqueID();
+ if(isset($values["{$uid}_x"]) && isset($values["{$uid}_y"]))
+ {
+ $this->_x=intval($values["{$uid}_x"]);
+ $this->_y=intval($values["{$uid}_y"]);
+ $this->getPage()->setPostBackEventTarget($this);
+ }
+ return false;
+ }
+
+ /**
+ * A dummy implementation for the IPostBackDataHandler interface.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ // no post data to handle
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnClick' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handler can be invoked.
+ * @param TImageClickEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnCommand' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TCommandEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCommand($param)
+ {
+ $this->raiseEvent('OnCommand',$this,$param);
+ $this->raiseBubbleEvent($this,$param);
+ }
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(new TImageClickEventParameter($this->_x,$this->_y));
+ $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this button will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function getCommandName()
+ {
+ return $this->getViewState('CommandName','');
+ }
+
+ /**
+ * @param string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandName($value)
+ {
+ $this->setViewState('CommandName',$value,'');
+ }
+
+ /**
+ * @return string the parameter associated with the {@link onCommand OnCommand} event
+ */
+ public function getCommandParameter()
+ {
+ return $this->getViewState('CommandParameter','');
+ }
+
+ /**
+ * @param string the parameter associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandParameter($value)
+ {
+ $this->setViewState('CommandParameter',$value,'');
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return string caption of the button
+ */
+ public function getText()
+ {
+ return $this->getAlternateText();
+ }
+
+ /**
+ * @param string caption of the button
+ */
+ public function setText($value)
+ {
+ $this->setAlternateText($value);
+ }
+
+ /**
+ * Registers the image button to receive postback data during postback.
+ * This is necessary because an image button, when postback, does not have
+ * direct mapping between post data and the image button name.
+ * This method overrides the parent implementation and is invoked before render.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $this->getPage()->registerRequiresPostData($this);
+ }
+
+ /**
+ * Renders the body content enclosed between the control tag.
+ * This overrides the parent implementation with nothing to be rendered.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ }
+}
+
+/**
+ * TImageClickEventParameter class
+ *
+ * TImageClickEventParameter encapsulates the parameter data for
+ * {@link TImageButton::onClick Click} event of {@link TImageButton} controls.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImageClickEventParameter extends TEventParameter
+{
+ /**
+ * the X coordinate of the clicking point
+ * @var integer
+ */
+ public $_x=0;
+ /**
+ * the Y coordinate of the clicking point
+ * @var integer
+ */
+ public $_y=0;
+
+ /**
+ * Constructor.
+ * @param integer X coordinate of the clicking point
+ * @param integer Y coordinate of the clicking point
+ */
+ public function __construct($x,$y)
+ {
+ $this->_x=$x;
+ $this->_y=$y;
+ }
+
+ /**
+ * @return integer X coordinate of the clicking point, defaults to 0
+ */
+ public function getX()
+ {
+ return $this->_x;
+ }
+
+ /**
+ * @param integer X coordinate of the clicking point
+ */
+ public function setX($value)
+ {
+ $this->_x=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return integer Y coordinate of the clicking point, defaults to 0
+ */
+ public function getY()
+ {
+ return $this->_y;
+ }
+
+ /**
+ * @param integer Y coordinate of the clicking point
+ */
+ public function setY($value)
+ {
+ $this->_y=TPropertyValue::ensureInteger($value);
+ }
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TImageMap.php b/framework/Web/UI/WebControls/TImageMap.php
index b6acf39e..b2d5f55e 100644
--- a/framework/Web/UI/WebControls/TImageMap.php
+++ b/framework/Web/UI/WebControls/TImageMap.php
@@ -1,727 +1,727 @@
-<?php
-/**
- * TImageMap and related class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TImage class file
- */
-Prado::using('System.Web.UI.WebControls.TImage');
-
-/**
- * TImageMap class
- *
- * TImageMap represents an image on a page. Hotspot regions can be defined
- * within the image. Depending on the {@link setHotSpotMode HotSpotMode},
- * clicking on the hotspots may trigger a postback or navigate to a specified
- * URL. The hotspots defined may be accessed via {@link getHotSpots HotSpots}.
- * Each hotspot is described as a {@link THotSpot}, which can be a circle,
- * rectangle, polygon, etc. To add hotspot in a template, use the following,
- * <code>
- * <com:TImageMap>
- * <com:TCircleHotSpot ... />
- * <com:TRectangleHotSpot ... />
- * <com:TPolygonHotSpot ... />
- * </com:TImageMap>
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImageMap extends TImage implements IPostBackEventHandler
-{
- const MAP_NAME_PREFIX='ImageMap';
-
- /**
- * Processes an object that is created during parsing template.
- * This method adds {@link THotSpot} objects into the hotspot collection
- * of the imagemap.
- * @param string|TComponent text string or component parsed and instantiated in template
- */
- public function addParsedObject($object)
- {
- if($object instanceof THotSpot)
- $this->getHotSpots()->add($object);
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional imagemap specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- if($this->getHotSpots()->getCount()>0)
- {
- $writer->addAttribute('usemap','#'.self::MAP_NAME_PREFIX.$this->getClientID());
- $writer->addAttribute('id',$this->getUniqueID());
- }
- if($this->getEnabled() && !$this->getEnabled(true))
- $writer->addAttribute('disabled','disabled');
- }
-
- /**
- * Renders this imagemap.
- * @param THtmlWriter
- */
- public function render($writer)
- {
- parent::render($writer);
-
- $hotspots=$this->getHotSpots();
-
- if($hotspots->getCount()>0)
- {
- $clientID=$this->getClientID();
- $cs=$this->getPage()->getClientScript();
- $writer->writeLine();
- $writer->addAttribute('name',self::MAP_NAME_PREFIX.$clientID);
- $writer->renderBeginTag('map');
- $writer->writeLine();
- if(($mode=$this->getHotSpotMode())==='NotSet')
- $mode='Navigate';
- $target=$this->getTarget();
- $i=0;
- $options['EventTarget'] = $this->getUniqueID();
- $options['StopEvent'] = true;
- $cs=$this->getPage()->getClientScript();
- foreach($hotspots as $hotspot)
- {
- if($hotspot->getHotSpotMode()==='NotSet')
- $hotspot->setHotSpotMode($mode);
- if($target!=='' && $hotspot->getTarget()==='')
- $hotspot->setTarget($target);
- if($hotspot->getHotSpotMode()==='PostBack')
- {
- $id=$clientID.'_'.$i;
- $writer->addAttribute('id',$id);
- $writer->addAttribute('href','#'.$id); //create unique no-op url references
- $options['ID']=$id;
- $options['EventParameter']="$i";
- $options['CausesValidation']=$hotspot->getCausesValidation();
- $options['ValidationGroup']=$hotspot->getValidationGroup();
- $cs->registerPostBackControl('Prado.WebUI.TImageMap',$options);
- }
- $hotspot->render($writer);
- $writer->writeLine();
- $i++;
- }
- $writer->renderEndTag();
- }
- }
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- $postBackValue=null;
- if($param!=='')
- {
- $index=TPropertyValue::ensureInteger($param);
- $hotspots=$this->getHotSpots();
- if($index>=0 && $index<$hotspots->getCount())
- {
- $hotspot=$hotspots->itemAt($index);
- if(($mode=$hotspot->getHotSpotMode())==='NotSet')
- $mode=$this->getHotSpotMode();
- if($mode==='PostBack')
- {
- $postBackValue=$hotspot->getPostBackValue();
- if($hotspot->getCausesValidation())
- $this->getPage()->validate($hotspot->getValidationGroup());
- }
- }
- }
- if($postBackValue!==null)
- $this->onClick(new TImageMapEventParameter($postBackValue));
- }
-
- /**
- * @return string the behavior of hotspot regions in this imagemap when they are clicked. Defaults to 'NotSet'.
- */
- public function getHotSpotMode()
- {
- return $this->getViewState('HotSpotMode','NotSet');
- }
-
- /**
- * Sets the behavior of hotspot regions in this imagemap when they are clicked.
- * If an individual hotspot has a mode other than 'NotSet', the mode set in this
- * imagemap will be ignored. By default, 'NotSet' is equivalent to 'Navigate'.
- * @param string the behavior of hotspot regions in this imagemap when they are clicked.
- * Valid values include 'NotSet','Navigate','PostBack','Inactive'.
- */
- public function setHotSpotMode($value)
- {
- $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'NotSet','Navigate','PostBack','Inactive'),'NotSet');
- }
-
- /**
- * @return THotSpotCollection collection of hotspots defined in this imagemap.
- */
- public function getHotSpots()
- {
- if(($hotspots=$this->getViewState('HotSpots',null))===null)
- {
- $hotspots=new THotSpotCollection;
- $this->setViewState('HotSpots',$hotspots);
- }
- return $hotspots;
- }
-
- /**
- * @return string the target window or frame to display the new page when a hotspot region is clicked within the imagemap. Defaults to ''.
- */
- public function getTarget()
- {
- return $this->getViewState('Target','');
- }
-
- /**
- * @param string the target window or frame to display the new page when a hotspot region is clicked within the imagemap.
- */
- public function setTarget($value)
- {
- $this->setViewState('Target',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * Raises <b>OnClick</b> event.
- * This method is invoked when a hotspot region is clicked within the imagemap.
- * If you override this method, be sure to call the parent implementation
- * so that the event handler can be invoked.
- * @param TImageMapEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-}
-
-/**
- * TImageMapEventParameter class.
- *
- * TImageMapEventParameter represents a postback event parameter
- * when a hotspot is clicked and posts back in a {@link TImageMap}.
- * To retrieve the post back value associated with the hotspot being clicked,
- * access {@link getPostBackValue PostBackValue}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImageMapEventParameter extends TEventParameter
-{
- private $_postBackValue;
-
- /**
- * Constructor.
- * @param string post back value associated with the hotspot clicked
- */
- public function __construct($postBackValue)
- {
- $this->_postBackValue=$postBackValue;
- }
-
- /**
- * @return string post back value associated with the hotspot clicked
- */
- public function getPostBackValue()
- {
- return $this->_postBackValue;
- }
-}
-
-/**
- * THotSpotCollection class.
- *
- * THotSpotCollection represents a collection of hotspots in an imagemap.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class THotSpotCollection extends TList
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by inserting only {@link THotSpot}.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a THotSpot.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof THotSpot)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('hotspotcollection_hotspot_required');
- }
-}
-
-
-/**
- * THotSpot class.
- *
- * THotSpot implements the basic functionality common to all hot spot shapes.
- * Derived classes include {@link TCircleHotSpot}, {@link TPolygonHotSpot}
- * and {@link TRectangleHotSpot}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class THotSpot extends TComponent
-{
- private $_viewState=array();
-
- /**
- * Returns a viewstate value.
- *
- * This function is very useful in defining getter functions for component properties
- * that must be kept in viewstate.
- * @param string the name of the viewstate value to be returned
- * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
- * @return mixed the viewstate value corresponding to $key
- */
- protected function getViewState($key,$defaultValue=null)
- {
- return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue;
- }
-
- /**
- * Sets a viewstate value.
- *
- * This function is very useful in defining setter functions for control properties
- * that must be kept in viewstate.
- * Make sure that the viewstate value must be serializable and unserializable.
- * @param string the name of the viewstate value
- * @param mixed the viewstate value to be set
- * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
- */
- protected function setViewState($key,$value,$defaultValue=null)
- {
- if($value===$defaultValue)
- unset($this->_viewState[$key]);
- else
- $this->_viewState[$key]=$value;
- }
-
- /**
- * @return string shape of the hotspot, can be 'circle', 'rect', 'poly', etc.
- */
- abstract public function getShape();
- /**
- * @return string coordinates defining the hotspot shape.
- */
- abstract public function getCoordinates();
-
- /**
- * @return string the access key that allows you to quickly navigate to the HotSpot region. Defaults to ''.
- */
- public function getAccessKey()
- {
- return $this->getViewState('AccessKey','');
- }
-
- /**
- * @param string the access key that allows you to quickly navigate to the HotSpot region.
- */
- public function setAccessKey($value)
- {
- $this->setViewState('AccessKey',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string the alternate text to display for a HotSpot object. Defaults to ''.
- */
- public function getAlternateText()
- {
- return $this->getViewState('AlternateText','');
- }
-
- /**
- * @param string the alternate text to display for a HotSpot object.
- */
- public function setAlternateText($value)
- {
- $this->setViewState('AlternateText',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string the behavior of a HotSpot object when it is clicked. Defaults to 'NotSet'.
- */
- public function getHotSpotMode()
- {
- return $this->getViewState('HotSpotMode','NotSet');
- }
-
- /**
- * @param string the behavior of a HotSpot object when it is clicked.
- * Valid values include 'NotSet','Navigate','PostBack','Inactive'.
- */
- public function setHotSpotMode($value)
- {
- $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'NotSet','Navigate','PostBack','Inactive'),'NotSet');
- }
-
- /**
- * @return string the URL to navigate to when a HotSpot object is clicked. Defaults to ''.
- */
- public function getNavigateUrl()
- {
- return $this->getViewState('NavigateUrl','');
- }
-
- /**
- * @param string the URL to navigate to when a HotSpot object is clicked.
- */
- public function setNavigateUrl($value)
- {
- $this->setViewState('NavigateUrl',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string a value that is post back when the HotSpot is clicked. Defaults to ''.
- */
- public function getPostBackValue()
- {
- return $this->getViewState('PostBackValue','');
- }
-
- /**
- * @param string a value that is post back when the HotSpot is clicked.
- */
- public function setPostBackValue($value)
- {
- $this->setViewState('PostBackValue',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return integer the tab index of the HotSpot region. Defaults to 0.
- */
- public function getTabIndex()
- {
- return $this->getViewState('TabIndex',0);
- }
-
- /**
- * @param integer the tab index of the HotSpot region.
- */
- public function setTabIndex($value)
- {
- $this->setViewState('TabIndex',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return boolean whether postback event trigger by this hotspot will cause input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this hotspot will cause input validation
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the hotspot causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the hotspot causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * @return string the target window or frame to display the new page when the HotSpot region
- * is clicked. Defaults to ''.
- */
- public function getTarget()
- {
- return $this->getViewState('Target','');
- }
-
- /**
- * @param string the target window or frame to display the new page when the HotSpot region
- * is clicked.
- */
- public function setTarget($value)
- {
- $this->setViewState('Target',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * Renders this hotspot.
- * @param THtmlWriter
- */
- public function render($writer)
- {
- $writer->addAttribute('shape',$this->getShape());
- $writer->addAttribute('coords',$this->getCoordinates());
- if(($mode=$this->getHotSpotMode())==='NotSet')
- $mode='Navigate';
- if($mode==='Navigate')
- {
- $writer->addAttribute('href',$this->getNavigateUrl());
- if(($target=$this->getTarget())!=='')
- $writer->addAttribute('target',$target);
- }
- else if($mode==='Inactive')
- $writer->addAttribute('nohref','true');
- $text=$this->getAlternateText();
- $writer->addAttribute('title',$text);
- $writer->addAttribute('alt',$text);
- if(($accessKey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accessKey);
- if(($tabIndex=$this->getTabIndex())!==0)
- $writer->addAttribute('tabindex',"$tabIndex");
- $writer->renderBeginTag('area');
- $writer->renderEndTag();
- }
-}
-
-/**
- * Class TCircleHotSpot.
- *
- * TCircleHotSpot defines a circular hot spot region in a {@link TImageMap}
- * control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCircleHotSpot extends THotSpot
-{
- /**
- * @return string shape of this hotspot.
- */
- public function getShape()
- {
- return 'circle';
- }
-
- /**
- * @return string coordinates defining this hotspot shape
- */
- public function getCoordinates()
- {
- return $this->getX().','.$this->getY().','.$this->getRadius();
- }
-
- /**
- * @return integer radius of the circular HotSpot region. Defaults to 0.
- */
- public function getRadius()
- {
- return $this->getViewState('Radius',0);
- }
-
- /**
- * @param integer radius of the circular HotSpot region.
- */
- public function setRadius($value)
- {
- $this->setViewState('Radius',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the X coordinate of the center of the circular HotSpot region. Defaults to 0.
- */
- public function getX()
- {
- return $this->getViewState('X',0);
- }
-
- /**
- * @param integer the X coordinate of the center of the circular HotSpot region.
- */
- public function setX($value)
- {
- $this->setViewState('X',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the Y coordinate of the center of the circular HotSpot region. Defaults to 0.
- */
- public function getY()
- {
- return $this->getViewState('Y',0);
- }
-
- /**
- * @param integer the Y coordinate of the center of the circular HotSpot region.
- */
- public function setY($value)
- {
- $this->setViewState('Y',TPropertyValue::ensureInteger($value),0);
- }
-}
-
-/**
- * Class TRectangleHotSpot.
- *
- * TRectangleHotSpot defines a rectangle hot spot region in a {@link
- * TImageMap} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRectangleHotSpot extends THotSpot
-{
- /**
- * @return string shape of this hotspot.
- */
- public function getShape()
- {
- return 'rect';
- }
-
- /**
- * @return string coordinates defining this hotspot shape
- */
- public function getCoordinates()
- {
- return $this->getLeft().','.$this->getTop().','.$this->getRight().','.$this->getBottom();
- }
-
- /**
- * @return integer the Y coordinate of the bottom side of the rectangle HotSpot region. Defaults to 0.
- */
- public function getBottom()
- {
- return $this->getViewState('Bottom',0);
- }
-
- /**
- * @param integer the Y coordinate of the bottom side of the rectangle HotSpot region.
- */
- public function setBottom($value)
- {
- $this->setViewState('Bottom',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0.
- */
- public function getLeft()
- {
- return $this->getViewState('Left',0);
- }
-
- /**
- * @param integer the X coordinate of the right side of the rectangle HotSpot region.
- */
- public function setLeft($value)
- {
- $this->setViewState('Left',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0.
- */
- public function getRight()
- {
- return $this->getViewState('Right',0);
- }
-
- /**
- * @param integer the X coordinate of the right side of the rectangle HotSpot region.
- */
- public function setRight($value)
- {
- $this->setViewState('Right',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the Y coordinate of the top side of the rectangle HotSpot region. Defaults to 0.
- */
- public function getTop()
- {
- return $this->getViewState('Top',0);
- }
-
- /**
- * @param integer the Y coordinate of the top side of the rectangle HotSpot region.
- */
- public function setTop($value)
- {
- $this->setViewState('Top',TPropertyValue::ensureInteger($value),0);
- }
-}
-
-/**
- * Class TPolygonHotSpot.
- *
- * TPolygonHotSpot defines a polygon hot spot region in a {@link
- * TImageMap} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TPolygonHotSpot extends THotSpot
-{
- /**
- * @return string shape of this hotspot.
- */
- public function getShape()
- {
- return 'poly';
- }
-
- /**
- * @return string coordinates of the vertices defining the polygon.
- * Coordinates are concatenated together with comma ','. Each pair
- * represents (x,y) of a vertex.
- */
- public function getCoordinates()
- {
- return $this->getViewState('Coordinates','');
- }
-
- /**
- * @param string coordinates of the vertices defining the polygon.
- * Coordinates are concatenated together with comma ','. Each pair
- * represents (x,y) of a vertex.
- */
- public function setCoordinates($value)
- {
- $this->setViewState('Coordinates',$value,'');
- }
-}
-
+<?php
+/**
+ * TImageMap and related class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TImage class file
+ */
+Prado::using('System.Web.UI.WebControls.TImage');
+
+/**
+ * TImageMap class
+ *
+ * TImageMap represents an image on a page. Hotspot regions can be defined
+ * within the image. Depending on the {@link setHotSpotMode HotSpotMode},
+ * clicking on the hotspots may trigger a postback or navigate to a specified
+ * URL. The hotspots defined may be accessed via {@link getHotSpots HotSpots}.
+ * Each hotspot is described as a {@link THotSpot}, which can be a circle,
+ * rectangle, polygon, etc. To add hotspot in a template, use the following,
+ * <code>
+ * <com:TImageMap>
+ * <com:TCircleHotSpot ... />
+ * <com:TRectangleHotSpot ... />
+ * <com:TPolygonHotSpot ... />
+ * </com:TImageMap>
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImageMap extends TImage implements IPostBackEventHandler
+{
+ const MAP_NAME_PREFIX='ImageMap';
+
+ /**
+ * Processes an object that is created during parsing template.
+ * This method adds {@link THotSpot} objects into the hotspot collection
+ * of the imagemap.
+ * @param string|TComponent text string or component parsed and instantiated in template
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof THotSpot)
+ $this->getHotSpots()->add($object);
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional imagemap specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ if($this->getHotSpots()->getCount()>0)
+ {
+ $writer->addAttribute('usemap','#'.self::MAP_NAME_PREFIX.$this->getClientID());
+ $writer->addAttribute('id',$this->getUniqueID());
+ }
+ if($this->getEnabled() && !$this->getEnabled(true))
+ $writer->addAttribute('disabled','disabled');
+ }
+
+ /**
+ * Renders this imagemap.
+ * @param THtmlWriter
+ */
+ public function render($writer)
+ {
+ parent::render($writer);
+
+ $hotspots=$this->getHotSpots();
+
+ if($hotspots->getCount()>0)
+ {
+ $clientID=$this->getClientID();
+ $cs=$this->getPage()->getClientScript();
+ $writer->writeLine();
+ $writer->addAttribute('name',self::MAP_NAME_PREFIX.$clientID);
+ $writer->renderBeginTag('map');
+ $writer->writeLine();
+ if(($mode=$this->getHotSpotMode())==='NotSet')
+ $mode='Navigate';
+ $target=$this->getTarget();
+ $i=0;
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['StopEvent'] = true;
+ $cs=$this->getPage()->getClientScript();
+ foreach($hotspots as $hotspot)
+ {
+ if($hotspot->getHotSpotMode()==='NotSet')
+ $hotspot->setHotSpotMode($mode);
+ if($target!=='' && $hotspot->getTarget()==='')
+ $hotspot->setTarget($target);
+ if($hotspot->getHotSpotMode()==='PostBack')
+ {
+ $id=$clientID.'_'.$i;
+ $writer->addAttribute('id',$id);
+ $writer->addAttribute('href','#'.$id); //create unique no-op url references
+ $options['ID']=$id;
+ $options['EventParameter']="$i";
+ $options['CausesValidation']=$hotspot->getCausesValidation();
+ $options['ValidationGroup']=$hotspot->getValidationGroup();
+ $cs->registerPostBackControl('Prado.WebUI.TImageMap',$options);
+ }
+ $hotspot->render($writer);
+ $writer->writeLine();
+ $i++;
+ }
+ $writer->renderEndTag();
+ }
+ }
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ $postBackValue=null;
+ if($param!=='')
+ {
+ $index=TPropertyValue::ensureInteger($param);
+ $hotspots=$this->getHotSpots();
+ if($index>=0 && $index<$hotspots->getCount())
+ {
+ $hotspot=$hotspots->itemAt($index);
+ if(($mode=$hotspot->getHotSpotMode())==='NotSet')
+ $mode=$this->getHotSpotMode();
+ if($mode==='PostBack')
+ {
+ $postBackValue=$hotspot->getPostBackValue();
+ if($hotspot->getCausesValidation())
+ $this->getPage()->validate($hotspot->getValidationGroup());
+ }
+ }
+ }
+ if($postBackValue!==null)
+ $this->onClick(new TImageMapEventParameter($postBackValue));
+ }
+
+ /**
+ * @return string the behavior of hotspot regions in this imagemap when they are clicked. Defaults to 'NotSet'.
+ */
+ public function getHotSpotMode()
+ {
+ return $this->getViewState('HotSpotMode','NotSet');
+ }
+
+ /**
+ * Sets the behavior of hotspot regions in this imagemap when they are clicked.
+ * If an individual hotspot has a mode other than 'NotSet', the mode set in this
+ * imagemap will be ignored. By default, 'NotSet' is equivalent to 'Navigate'.
+ * @param string the behavior of hotspot regions in this imagemap when they are clicked.
+ * Valid values include 'NotSet','Navigate','PostBack','Inactive'.
+ */
+ public function setHotSpotMode($value)
+ {
+ $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'NotSet','Navigate','PostBack','Inactive'),'NotSet');
+ }
+
+ /**
+ * @return THotSpotCollection collection of hotspots defined in this imagemap.
+ */
+ public function getHotSpots()
+ {
+ if(($hotspots=$this->getViewState('HotSpots',null))===null)
+ {
+ $hotspots=new THotSpotCollection;
+ $this->setViewState('HotSpots',$hotspots);
+ }
+ return $hotspots;
+ }
+
+ /**
+ * @return string the target window or frame to display the new page when a hotspot region is clicked within the imagemap. Defaults to ''.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * @param string the target window or frame to display the new page when a hotspot region is clicked within the imagemap.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * Raises <b>OnClick</b> event.
+ * This method is invoked when a hotspot region is clicked within the imagemap.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handler can be invoked.
+ * @param TImageMapEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+}
+
+/**
+ * TImageMapEventParameter class.
+ *
+ * TImageMapEventParameter represents a postback event parameter
+ * when a hotspot is clicked and posts back in a {@link TImageMap}.
+ * To retrieve the post back value associated with the hotspot being clicked,
+ * access {@link getPostBackValue PostBackValue}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImageMapEventParameter extends TEventParameter
+{
+ private $_postBackValue;
+
+ /**
+ * Constructor.
+ * @param string post back value associated with the hotspot clicked
+ */
+ public function __construct($postBackValue)
+ {
+ $this->_postBackValue=$postBackValue;
+ }
+
+ /**
+ * @return string post back value associated with the hotspot clicked
+ */
+ public function getPostBackValue()
+ {
+ return $this->_postBackValue;
+ }
+}
+
+/**
+ * THotSpotCollection class.
+ *
+ * THotSpotCollection represents a collection of hotspots in an imagemap.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class THotSpotCollection extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by inserting only {@link THotSpot}.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a THotSpot.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof THotSpot)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('hotspotcollection_hotspot_required');
+ }
+}
+
+
+/**
+ * THotSpot class.
+ *
+ * THotSpot implements the basic functionality common to all hot spot shapes.
+ * Derived classes include {@link TCircleHotSpot}, {@link TPolygonHotSpot}
+ * and {@link TRectangleHotSpot}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class THotSpot extends TComponent
+{
+ private $_viewState=array();
+
+ /**
+ * Returns a viewstate value.
+ *
+ * This function is very useful in defining getter functions for component properties
+ * that must be kept in viewstate.
+ * @param string the name of the viewstate value to be returned
+ * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
+ * @return mixed the viewstate value corresponding to $key
+ */
+ protected function getViewState($key,$defaultValue=null)
+ {
+ return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue;
+ }
+
+ /**
+ * Sets a viewstate value.
+ *
+ * This function is very useful in defining setter functions for control properties
+ * that must be kept in viewstate.
+ * Make sure that the viewstate value must be serializable and unserializable.
+ * @param string the name of the viewstate value
+ * @param mixed the viewstate value to be set
+ * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
+ */
+ protected function setViewState($key,$value,$defaultValue=null)
+ {
+ if($value===$defaultValue)
+ unset($this->_viewState[$key]);
+ else
+ $this->_viewState[$key]=$value;
+ }
+
+ /**
+ * @return string shape of the hotspot, can be 'circle', 'rect', 'poly', etc.
+ */
+ abstract public function getShape();
+ /**
+ * @return string coordinates defining the hotspot shape.
+ */
+ abstract public function getCoordinates();
+
+ /**
+ * @return string the access key that allows you to quickly navigate to the HotSpot region. Defaults to ''.
+ */
+ public function getAccessKey()
+ {
+ return $this->getViewState('AccessKey','');
+ }
+
+ /**
+ * @param string the access key that allows you to quickly navigate to the HotSpot region.
+ */
+ public function setAccessKey($value)
+ {
+ $this->setViewState('AccessKey',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string the alternate text to display for a HotSpot object. Defaults to ''.
+ */
+ public function getAlternateText()
+ {
+ return $this->getViewState('AlternateText','');
+ }
+
+ /**
+ * @param string the alternate text to display for a HotSpot object.
+ */
+ public function setAlternateText($value)
+ {
+ $this->setViewState('AlternateText',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string the behavior of a HotSpot object when it is clicked. Defaults to 'NotSet'.
+ */
+ public function getHotSpotMode()
+ {
+ return $this->getViewState('HotSpotMode','NotSet');
+ }
+
+ /**
+ * @param string the behavior of a HotSpot object when it is clicked.
+ * Valid values include 'NotSet','Navigate','PostBack','Inactive'.
+ */
+ public function setHotSpotMode($value)
+ {
+ $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'NotSet','Navigate','PostBack','Inactive'),'NotSet');
+ }
+
+ /**
+ * @return string the URL to navigate to when a HotSpot object is clicked. Defaults to ''.
+ */
+ public function getNavigateUrl()
+ {
+ return $this->getViewState('NavigateUrl','');
+ }
+
+ /**
+ * @param string the URL to navigate to when a HotSpot object is clicked.
+ */
+ public function setNavigateUrl($value)
+ {
+ $this->setViewState('NavigateUrl',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string a value that is post back when the HotSpot is clicked. Defaults to ''.
+ */
+ public function getPostBackValue()
+ {
+ return $this->getViewState('PostBackValue','');
+ }
+
+ /**
+ * @param string a value that is post back when the HotSpot is clicked.
+ */
+ public function setPostBackValue($value)
+ {
+ $this->setViewState('PostBackValue',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return integer the tab index of the HotSpot region. Defaults to 0.
+ */
+ public function getTabIndex()
+ {
+ return $this->getViewState('TabIndex',0);
+ }
+
+ /**
+ * @param integer the tab index of the HotSpot region.
+ */
+ public function setTabIndex($value)
+ {
+ $this->setViewState('TabIndex',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this hotspot will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this hotspot will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the hotspot causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the hotspot causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return string the target window or frame to display the new page when the HotSpot region
+ * is clicked. Defaults to ''.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * @param string the target window or frame to display the new page when the HotSpot region
+ * is clicked.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * Renders this hotspot.
+ * @param THtmlWriter
+ */
+ public function render($writer)
+ {
+ $writer->addAttribute('shape',$this->getShape());
+ $writer->addAttribute('coords',$this->getCoordinates());
+ if(($mode=$this->getHotSpotMode())==='NotSet')
+ $mode='Navigate';
+ if($mode==='Navigate')
+ {
+ $writer->addAttribute('href',$this->getNavigateUrl());
+ if(($target=$this->getTarget())!=='')
+ $writer->addAttribute('target',$target);
+ }
+ else if($mode==='Inactive')
+ $writer->addAttribute('nohref','true');
+ $text=$this->getAlternateText();
+ $writer->addAttribute('title',$text);
+ $writer->addAttribute('alt',$text);
+ if(($accessKey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accessKey);
+ if(($tabIndex=$this->getTabIndex())!==0)
+ $writer->addAttribute('tabindex',"$tabIndex");
+ $writer->renderBeginTag('area');
+ $writer->renderEndTag();
+ }
+}
+
+/**
+ * Class TCircleHotSpot.
+ *
+ * TCircleHotSpot defines a circular hot spot region in a {@link TImageMap}
+ * control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCircleHotSpot extends THotSpot
+{
+ /**
+ * @return string shape of this hotspot.
+ */
+ public function getShape()
+ {
+ return 'circle';
+ }
+
+ /**
+ * @return string coordinates defining this hotspot shape
+ */
+ public function getCoordinates()
+ {
+ return $this->getX().','.$this->getY().','.$this->getRadius();
+ }
+
+ /**
+ * @return integer radius of the circular HotSpot region. Defaults to 0.
+ */
+ public function getRadius()
+ {
+ return $this->getViewState('Radius',0);
+ }
+
+ /**
+ * @param integer radius of the circular HotSpot region.
+ */
+ public function setRadius($value)
+ {
+ $this->setViewState('Radius',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the X coordinate of the center of the circular HotSpot region. Defaults to 0.
+ */
+ public function getX()
+ {
+ return $this->getViewState('X',0);
+ }
+
+ /**
+ * @param integer the X coordinate of the center of the circular HotSpot region.
+ */
+ public function setX($value)
+ {
+ $this->setViewState('X',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the Y coordinate of the center of the circular HotSpot region. Defaults to 0.
+ */
+ public function getY()
+ {
+ return $this->getViewState('Y',0);
+ }
+
+ /**
+ * @param integer the Y coordinate of the center of the circular HotSpot region.
+ */
+ public function setY($value)
+ {
+ $this->setViewState('Y',TPropertyValue::ensureInteger($value),0);
+ }
+}
+
+/**
+ * Class TRectangleHotSpot.
+ *
+ * TRectangleHotSpot defines a rectangle hot spot region in a {@link
+ * TImageMap} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRectangleHotSpot extends THotSpot
+{
+ /**
+ * @return string shape of this hotspot.
+ */
+ public function getShape()
+ {
+ return 'rect';
+ }
+
+ /**
+ * @return string coordinates defining this hotspot shape
+ */
+ public function getCoordinates()
+ {
+ return $this->getLeft().','.$this->getTop().','.$this->getRight().','.$this->getBottom();
+ }
+
+ /**
+ * @return integer the Y coordinate of the bottom side of the rectangle HotSpot region. Defaults to 0.
+ */
+ public function getBottom()
+ {
+ return $this->getViewState('Bottom',0);
+ }
+
+ /**
+ * @param integer the Y coordinate of the bottom side of the rectangle HotSpot region.
+ */
+ public function setBottom($value)
+ {
+ $this->setViewState('Bottom',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0.
+ */
+ public function getLeft()
+ {
+ return $this->getViewState('Left',0);
+ }
+
+ /**
+ * @param integer the X coordinate of the right side of the rectangle HotSpot region.
+ */
+ public function setLeft($value)
+ {
+ $this->setViewState('Left',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0.
+ */
+ public function getRight()
+ {
+ return $this->getViewState('Right',0);
+ }
+
+ /**
+ * @param integer the X coordinate of the right side of the rectangle HotSpot region.
+ */
+ public function setRight($value)
+ {
+ $this->setViewState('Right',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the Y coordinate of the top side of the rectangle HotSpot region. Defaults to 0.
+ */
+ public function getTop()
+ {
+ return $this->getViewState('Top',0);
+ }
+
+ /**
+ * @param integer the Y coordinate of the top side of the rectangle HotSpot region.
+ */
+ public function setTop($value)
+ {
+ $this->setViewState('Top',TPropertyValue::ensureInteger($value),0);
+ }
+}
+
+/**
+ * Class TPolygonHotSpot.
+ *
+ * TPolygonHotSpot defines a polygon hot spot region in a {@link
+ * TImageMap} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TPolygonHotSpot extends THotSpot
+{
+ /**
+ * @return string shape of this hotspot.
+ */
+ public function getShape()
+ {
+ return 'poly';
+ }
+
+ /**
+ * @return string coordinates of the vertices defining the polygon.
+ * Coordinates are concatenated together with comma ','. Each pair
+ * represents (x,y) of a vertex.
+ */
+ public function getCoordinates()
+ {
+ return $this->getViewState('Coordinates','');
+ }
+
+ /**
+ * @param string coordinates of the vertices defining the polygon.
+ * Coordinates are concatenated together with comma ','. Each pair
+ * represents (x,y) of a vertex.
+ */
+ public function setCoordinates($value)
+ {
+ $this->setViewState('Coordinates',$value,'');
+ }
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php
index e7fea0b5..84e1d5a4 100644
--- a/framework/Web/UI/WebControls/TLinkButton.php
+++ b/framework/Web/UI/WebControls/TLinkButton.php
@@ -1,255 +1,255 @@
-<?php
-/**
- * TLinkButton class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TLinkButton class
- *
- * TLinkButton creates a hyperlink style button on the page.
- * TLinkButton has the same appearance as a hyperlink. However, it is mainly
- * used to submit data to a page. Like {@link TButton}, you can create either
- * a <b>submit</b> button or a <b>command</b> button.
- *
- * A <b>command</b> button has a command name (specified by
- * the {@link setCommandName CommandName} property) and and a command parameter
- * (specified by {@link setCommandParameter CommandParameter} property)
- * associated with the button. This allows you to create multiple TLinkButton
- * components on a Web page and programmatically determine which one is clicked
- * with what parameter. You can provide an event handler for
- * {@link onCommand OnCommand} event to programmatically control the actions performed
- * when the command button is clicked. In the event handler, you can determine
- * the {@link setCommandName CommandName} property value and
- * the {@link setCommandParameter CommandParameter} property value
- * through the {@link TCommandParameter::getName Name} and
- * {@link TCommandParameter::getParameter Parameter} properties of the event
- * parameter which is of type {@link TCommandEventParameter}.
- *
- * A <b>submit</b> button does not have a command name associated with the button
- * and clicking on it simply posts the Web page back to the server.
- * By default, a TLinkButton component is a submit button.
- * You can provide an event handler for the {@link onClick OnClick} event
- * to programmatically control the actions performed when the submit button is clicked.
- *
- * Clicking on button can trigger form validation, if
- * {@link setCausesValidation CausesValidation} is true.
- * And the validation may be restricted within a certain group of validator
- * controls by setting {@link setValidationGroup ValidationGroup} property.
- * If validation is successful, the data will be post back to the same page.
- *
- * TLinkButton will display the {@link setText Text} property value
- * as the hyperlink text. If {@link setText Text} is empty, the body content
- * of TLinkButton will be displayed. Therefore, you can use TLinkButton
- * as an image button by enclosing an &lt;img&gt; tag as the body of TLinkButton.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TLinkButton extends TWebControl implements IPostBackEventHandler, IButtonControl
-{
- /**
- * @return string tag name of the button
- */
- protected function getTagName()
- {
- return 'a';
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional button specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
-
- $writer->addAttribute('id',$this->getClientID());
-
- // We call parent implementation here because some attributes
- // may be overwritten in the following
- parent::addAttributesToRender($writer);
-
- if($this->getEnabled(true))
- $this->renderClientControlScript($writer);
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- //create unique no-op url references
- $nop = "javascript:;//".$this->getClientID();
- $writer->addAttribute('href', $nop);
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl('Prado.WebUI.TLinkButton',$this->getPostBackOptions());
- }
-
- /**
- * Returns postback specifications for the button.
- * This method is used by framework and control developers.
- * @return array parameters about how the button defines its postback behavior.
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['EventTarget'] = $this->getUniqueID();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['StopEvent'] = true;
-
- return $options;
- }
-
- /**
- * Renders the body content enclosed between the control tag.
- * If {@link getText Text} is not empty, it will be rendered. Otherwise,
- * the body content enclosed in the control tag will be rendered.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderContents($writer)
- {
- if(($text=$this->getText())==='')
- parent::renderContents($writer);
- else
- $writer->write($text);
- }
-
- /**
- * @return string the text caption of the button
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * @param string the text caption to be set
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * @return string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function getCommandName()
- {
- return $this->getViewState('CommandName','');
- }
-
- /**
- * @param string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandName($value)
- {
- $this->setViewState('CommandName',$value,'');
- }
-
- /**
- * @return string the parameter associated with the {@link onCommand OnCommand} event
- */
- public function getCommandParameter()
- {
- return $this->getViewState('CommandParameter','');
- }
-
- /**
- * @param string the parameter associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandParameter($value)
- {
- $this->setViewState('CommandParameter',$value,'');
- }
-
- /**
- * @return boolean whether postback event trigger by this button will cause input validation
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * Sets the value indicating whether postback event trigger by this button will cause input validation.
- * @param string the text caption to be set
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the button causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the button causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * If {@link getCausesValidation CausesValidation} is true, it will
- * invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- if($this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onClick(null);
- $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnClick' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handler can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnCommand' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TCommandEventParameter event parameter to be passed to the event handlers
- */
- public function onCommand($param)
- {
- $this->raiseEvent('OnCommand',$this,$param);
- $this->raiseBubbleEvent($this,$param);
- }
-}
-
-?>
+<?php
+/**
+ * TLinkButton class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TLinkButton class
+ *
+ * TLinkButton creates a hyperlink style button on the page.
+ * TLinkButton has the same appearance as a hyperlink. However, it is mainly
+ * used to submit data to a page. Like {@link TButton}, you can create either
+ * a <b>submit</b> button or a <b>command</b> button.
+ *
+ * A <b>command</b> button has a command name (specified by
+ * the {@link setCommandName CommandName} property) and and a command parameter
+ * (specified by {@link setCommandParameter CommandParameter} property)
+ * associated with the button. This allows you to create multiple TLinkButton
+ * components on a Web page and programmatically determine which one is clicked
+ * with what parameter. You can provide an event handler for
+ * {@link onCommand OnCommand} event to programmatically control the actions performed
+ * when the command button is clicked. In the event handler, you can determine
+ * the {@link setCommandName CommandName} property value and
+ * the {@link setCommandParameter CommandParameter} property value
+ * through the {@link TCommandParameter::getName Name} and
+ * {@link TCommandParameter::getParameter Parameter} properties of the event
+ * parameter which is of type {@link TCommandEventParameter}.
+ *
+ * A <b>submit</b> button does not have a command name associated with the button
+ * and clicking on it simply posts the Web page back to the server.
+ * By default, a TLinkButton component is a submit button.
+ * You can provide an event handler for the {@link onClick OnClick} event
+ * to programmatically control the actions performed when the submit button is clicked.
+ *
+ * Clicking on button can trigger form validation, if
+ * {@link setCausesValidation CausesValidation} is true.
+ * And the validation may be restricted within a certain group of validator
+ * controls by setting {@link setValidationGroup ValidationGroup} property.
+ * If validation is successful, the data will be post back to the same page.
+ *
+ * TLinkButton will display the {@link setText Text} property value
+ * as the hyperlink text. If {@link setText Text} is empty, the body content
+ * of TLinkButton will be displayed. Therefore, you can use TLinkButton
+ * as an image button by enclosing an &lt;img&gt; tag as the body of TLinkButton.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TLinkButton extends TWebControl implements IPostBackEventHandler, IButtonControl
+{
+ /**
+ * @return string tag name of the button
+ */
+ protected function getTagName()
+ {
+ return 'a';
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional button specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+
+ $writer->addAttribute('id',$this->getClientID());
+
+ // We call parent implementation here because some attributes
+ // may be overwritten in the following
+ parent::addAttributesToRender($writer);
+
+ if($this->getEnabled(true))
+ $this->renderClientControlScript($writer);
+ else if($this->getEnabled()) // in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ //create unique no-op url references
+ $nop = "javascript:;//".$this->getClientID();
+ $writer->addAttribute('href', $nop);
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl('Prado.WebUI.TLinkButton',$this->getPostBackOptions());
+ }
+
+ /**
+ * Returns postback specifications for the button.
+ * This method is used by framework and control developers.
+ * @return array parameters about how the button defines its postback behavior.
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['StopEvent'] = true;
+
+ return $options;
+ }
+
+ /**
+ * Renders the body content enclosed between the control tag.
+ * If {@link getText Text} is not empty, it will be rendered. Otherwise,
+ * the body content enclosed in the control tag will be rendered.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())==='')
+ parent::renderContents($writer);
+ else
+ $writer->write($text);
+ }
+
+ /**
+ * @return string the text caption of the button
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * @return string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function getCommandName()
+ {
+ return $this->getViewState('CommandName','');
+ }
+
+ /**
+ * @param string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandName($value)
+ {
+ $this->setViewState('CommandName',$value,'');
+ }
+
+ /**
+ * @return string the parameter associated with the {@link onCommand OnCommand} event
+ */
+ public function getCommandParameter()
+ {
+ return $this->getViewState('CommandParameter','');
+ }
+
+ /**
+ * @param string the parameter associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandParameter($value)
+ {
+ $this->setViewState('CommandParameter',$value,'');
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * Sets the value indicating whether postback event trigger by this button will cause input validation.
+ * @param string the text caption to be set
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(null);
+ $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnClick' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handler can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnCommand' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TCommandEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCommand($param)
+ {
+ $this->raiseEvent('OnCommand',$this,$param);
+ $this->raiseBubbleEvent($this,$param);
+ }
+}
+
+?>
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index ccb400dc..85b8d88f 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -1,824 +1,824 @@
-<?php
-/**
- * TListControl class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes the supporting classes
- */
-Prado::using('System.Web.UI.WebControls.TDataBoundControl');
-Prado::using('System.Web.UI.WebControls.TListItem');
-Prado::using('System.Collections.TAttributeCollection');
-Prado::using('System.Util.TDataFieldAccessor');
-
-
-/**
- * TListControl class
- *
- * TListControl is a base class for list controls, such as {@link TListBox},
- * {@link TDropDownList}, {@link TCheckBoxList}, etc.
- * It manages the items and their status in a list control.
- * It also implements how the items can be populated from template and
- * data source.
- *
- * The property {@link getItems} returns a list of the items in the control.
- * To specify or determine which item is selected, use the
- * {@link getSelectedIndex SelectedIndex} property that indicates the zero-based
- * index of the selected item in the item list. You may also use
- * {@link getSelectedItem SelectedItem} and {@link getSelectedValue SelectedValue}
- * to get the selected item and its value. For multiple selection lists
- * (such as {@link TCheckBoxList} and {@link TListBox}), property
- * {@link getSelectedIndices SelectedIndices} is useful.
- *
- * TListControl implements {@link setAutoPostBack AutoPostBack} which allows
- * a list control to postback the page if the selections of the list items are changed.
- * The {@link setCausesValidation CausesValidation} and {@link setValidationGroup ValidationGroup}
- * properties may be used to specify that validation be performed when auto postback occurs.
- *
- * There are three ways to populate the items in a list control: from template,
- * using {@link setDataSource DataSource} and using {@link setDataSourceID DataSourceID}.
- * The latter two are covered in {@link TDataBoundControl}. To specify items via
- * template, using the following template syntax:
- * <code>
- * <com:TListControl>
- * <com:TListItem Value="xxx" Text="yyy" >
- * <com:TListItem Value="xxx" Text="yyy" Selected="true" >
- * <com:TListItem Value="xxx" Text="yyy" >
- * </com:TListControl>
- * </code>
- *
- * When {@link setDataSource DataSource} or {@link setDataSourceID DataSourceID}
- * is used to populate list items, the {@link setDataTextField DataTextField} and
- * {@link setDataValueField DataValueField} properties are used to specify which
- * columns of the data will be used to populate the text and value of the items.
- * For example, if a data source is as follows,
- * <code>
- * $dataSource=array(
- * array('name'=>'John', 'age'=>31),
- * array('name'=>'Cary', 'age'=>28),
- * array('name'=>'Rose', 'age'=>35),
- * );
- * </code>
- * setting {@link setDataTextField DataTextField} and {@link setDataValueField DataValueField}
- * to 'name' and 'age' will make the first item's text be 'John', value be 31,
- * the second item's text be 'Cary', value be 28, and so on.
- * The {@link setDataTextFormatString DataTextFormatString} property may be further
- * used to format how the item should be displayed. See {@link formatDataValue()}
- * for an explanation of the format string.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class TListControl extends TDataBoundControl
-{
- /**
- * @var TListItemCollection item list
- */
- private $_items=null;
- /**
- * @var boolean whether items are restored from viewstate
- */
- private $_stateLoaded=false;
- /**
- * @var mixed the following selection variables are used
- * to keep selections when Items are not available
- */
- private $_cachedSelectedIndex=-1;
- private $_cachedSelectedValue=null;
-
- /**
- * @return string tag name of the list control
- */
- protected function getTagName()
- {
- return 'select';
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
- if($this->getIsMultiSelect())
- $writer->addAttribute('multiple','multiple');
- if($this->getEnabled(true))
- {
- if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- $this->renderClientControlScript($writer);
- }
- else if($this->getEnabled())
- $writer->addAttribute('disabled','disabled');
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the javascript for list control.
- */
- protected function renderClientControlScript($writer)
- {
- $writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- abstract protected function getClientClassName();
-
- /**
- * @return array postback options for JS postback code
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['EventTarget'] = $this->getUniqueID();
- return $options;
- }
-
- /**
- * Adds object parsed from template to the control.
- * This method adds only {@link TListItem} objects into the {@link getItems Items} collection.
- * All other objects are ignored.
- * @param mixed object parsed from template
- */
- public function addParsedObject($object)
- {
- // Do not add items from template if items are loaded from viewstate
- if(!$this->_stateLoaded && ($object instanceof TListItem))
- {
- $index=$this->getItems()->add($object);
- if(($this->_cachedSelectedValue!==null && $this->_cachedSelectedValue===$object->getValue()) || ($this->_cachedSelectedIndex===$index))
- {
- $object->setSelected(true);
- $this->_cachedSelectedValue=null;
- $this->_cachedSelectedIndex=-1;
- }
- }
- }
-
- /**
- * Performs databinding to populate list items from data source.
- * This method is invoked by dataBind().
- * You may override this function to provide your own way of data population.
- * @param Traversable the data
- */
- protected function performDataBinding($data)
- {
- $items=$this->getItems();
- if(!$this->getAppendDataBoundItems())
- $items->clear();
- $textField=$this->getDataTextField();
- if($textField==='')
- $textField=0;
- $valueField=$this->getDataValueField();
- if($valueField==='')
- $valueField=1;
- $textFormat=$this->getDataTextFormatString();
- foreach($data as $key=>$object)
- {
- $item=$items->createListItem();
- if(is_array($object) || is_object($object))
- {
- $text=TDataFieldAccessor::getDataFieldValue($object,$textField);
- $value=TDataFieldAccessor::getDataFieldValue($object,$valueField);
- $item->setValue($value);
- }
- else
- {
- $text=$object;
- $item->setValue("$key");
- }
- $item->setText($this->formatDataValue($textFormat,$text));
- }
- // SelectedValue or SelectedIndex may be set before databinding
- // so we make them be effective now
- if($this->_cachedSelectedValue!==null)
- {
- $index=$items->findIndexByValue($this->_cachedSelectedValue);
- if($index===-1 || ($this->_cachedSelectedIndex!==-1 && $this->_cachedSelectedIndex!==$index))
- throw new TInvalidDataValueException('listcontrol_selection_invalid',get_class($this));
- $this->setSelectedIndex($index);
- $this->_cachedSelectedValue=null;
- $this->_cachedSelectedIndex=-1;
- }
- else if($this->_cachedSelectedIndex!==-1)
- {
- $this->setSelectedIndex($this->_cachedSelectedIndex);
- $this->_cachedSelectedIndex=-1;
- }
- }
-
- /**
- * Creates a collection object to hold list items.
- * This method may be overriden to create a customized collection.
- * @return TListItemCollection the collection object
- */
- protected function createListItemCollection()
- {
- return new TListItemCollection;
- }
-
- /**
- * Saves items into viewstate.
- * This method is invoked right before control state is to be saved.
- */
- public function saveState()
- {
- parent::saveState();
- if($this->_items)
- $this->setViewState('Items',$this->_items->saveState(),null);
- else
- $this->clearViewState('Items');
- }
-
- /**
- * Loads items from viewstate.
- * This method is invoked right after control state is loaded.
- */
- public function loadState()
- {
- parent::loadState();
- $this->_stateLoaded=true;
- if(!$this->getIsDataBound())
- {
- $this->_items=$this->createListItemCollection();
- $this->_items->loadState($this->getViewState('Items',null));
- }
- $this->clearViewState('Items');
- }
-
- /**
- * @return boolean whether this is a multiselect control. Defaults to false.
- */
- protected function getIsMultiSelect()
- {
- return false;
- }
-
- /**
- * @return boolean whether performing databind should append items or clear the existing ones. Defaults to false.
- */
- public function getAppendDataBoundItems()
- {
- return $this->getViewState('AppendDataBoundItems',false);
- }
-
- /**
- * @param boolean whether performing databind should append items or clear the existing ones.
- */
- public function setAppendDataBoundItems($value)
- {
- $this->setViewState('AppendDataBoundItems',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean a value indicating whether an automatic postback to the server
- * will occur whenever the user makes change to the list control and then tabs out of it.
- * Defaults to false.
- */
- public function getAutoPostBack()
- {
- return $this->getViewState('AutoPostBack',false);
- }
-
- /**
- * Sets the value indicating if postback automatically.
- * An automatic postback to the server will occur whenever the user
- * makes change to the list control and then tabs out of it.
- * @param boolean the value indicating if postback automatically
- */
- public function setAutoPostBack($value)
- {
- $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether postback event trigger by this list control will cause input validation, default is true.
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this list control will cause input validation.
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the field of the data source that provides the text content of the list items.
- */
- public function getDataTextField()
- {
- return $this->getViewState('DataTextField','');
- }
-
- /**
- * @param string the field of the data source that provides the text content of the list items.
- */
- public function setDataTextField($value)
- {
- $this->setViewState('DataTextField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how data bound to the list control is displayed.
- */
- public function getDataTextFormatString()
- {
- return $this->getViewState('DataTextFormatString','');
- }
-
- /**
- * Sets data text format string.
- * The format string is used in {@link TDataValueFormatter::format()} to format the Text property value
- * of each item in the list control.
- * @param string the formatting string used to control how data bound to the list control is displayed.
- * @see TDataValueFormatter::format()
- */
- public function setDataTextFormatString($value)
- {
- $this->setViewState('DataTextFormatString',$value,'');
- }
-
- /**
- * @return string the field of the data source that provides the value of each list item.
- */
- public function getDataValueField()
- {
- return $this->getViewState('DataValueField','');
- }
-
- /**
- * @param string the field of the data source that provides the value of each list item.
- */
- public function setDataValueField($value)
- {
- $this->setViewState('DataValueField',$value,'');
- }
-
- /**
- * @return integer the number of items in the list control
- */
- public function getItemCount()
- {
- return $this->_items?$this->_items->getCount():0;
- }
-
- /**
- * @return boolean whether the list control contains any items.
- */
- public function getHasItems()
- {
- return ($this->_items && $this->_items->getCount()>0);
- }
-
- /**
- * @return TListItemCollection the item collection
- */
- public function getItems()
- {
- if(!$this->_items)
- $this->_items=$this->createListItemCollection();
- return $this->_items;
- }
-
- /**
- * @return integer the index (zero-based) of the item being selected, -1 if no item is selected.
- */
- public function getSelectedIndex()
- {
- if($this->_items)
- {
- $n=$this->_items->getCount();
- for($i=0;$i<$n;++$i)
- if($this->_items->itemAt($i)->getSelected())
- return $i;
- }
- return -1;
- }
-
- /**
- * @param integer the index (zero-based) of the item to be selected
- */
- public function setSelectedIndex($index)
- {
- if(($index=TPropertyValue::ensureInteger($index))<0)
- $index=-1;
- if($this->_items)
- {
- $this->clearSelection();
- if($index>=0 && $index<$this->_items->getCount())
- $this->_items->itemAt($index)->setSelected(true);
- else if($index!==-1)
- throw new TInvalidDataValueException('listcontrol_selectedindex_invalid',get_class($this),$index);
- }
- $this->_cachedSelectedIndex=$index;
- }
-
- /**
- * @return array list of index of items that are selected
- */
- public function getSelectedIndices()
- {
- $selections=array();
- if($this->_items)
- {
- $n=$this->_items->getCount();
- for($i=0;$i<$n;++$i)
- if($this->_items->itemAt($i)->getSelected())
- $selections[]=$i;
- }
- return $selections;
- }
-
- /**
- * @param array list of index of items to be selected
- */
- public function setSelectedIndices($indices)
- {
- if($this->_items)
- {
- $this->clearSelection();
- $n=$this->_items->getCount();
- foreach($indices as $index)
- {
- if($index>=0 && $index<$n)
- $this->_items->itemAt($index)->setSelected(true);
- }
- }
- }
-
- /**
- * @return TListItem|null the selected item with the lowest cardinal index, null if no item is selected.
- */
- public function getSelectedItem()
- {
- if(($index=$this->getSelectedIndex())>=0)
- return $this->_items->itemAt($index);
- else
- return null;
- }
-
- /**
- * @return string the value of the selected item with the lowest cardinal index, empty if no selection
- */
- public function getSelectedValue()
- {
- $index=$this->getSelectedIndex();
- return $index>=0?$this->getItems()->itemAt($index)->getValue():'';
- }
-
- /**
- * Sets selection by item value.
- * Existing selections will be cleared if the item value is found in the item collection.
- * Note, if the value is null, existing selections will also be cleared.
- * @param string the value of the item to be selected.
- */
- public function setSelectedValue($value)
- {
- if($this->_items)
- {
- if($value===null)
- $this->clearSelection();
- else if(($item=$this->_items->findItemByValue($value))!==null)
- {
- $this->clearSelection();
- $item->setSelected(true);
- }
- else
- throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value);
- }
- $this->_cachedSelectedValue=$value;
- }
-
-
- /**
- * @return array list of the selected item values (strings)
- */
- public function getSelectedValues()
- {
- $values=array();
- if($this->_items)
- {
- foreach($this->_items as $item)
- {
- if($item->getSelected())
- $values[]=$item->getValue();
- }
- }
- return $values;
- }
-
- /**
- * @param array list of the selected item values
- */
- public function setSelectedValues($values)
- {
- if($this->_items)
- {
- $this->clearSelection();
- $lookup=array();
- foreach($this->_items as $item)
- $lookup[$item->getValue()]=$item;
- foreach($values as $value)
- {
- if(isset($lookup["$value"]))
- $lookup["$value"]->setSelected(true);
- else
- throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value);
- }
- }
- }
-
- /**
- * @return string selected value
- */
- public function getText()
- {
- return $this->getSelectedValue();
- }
-
- /**
- * @param string value to be selected
- */
- public function setText($value)
- {
- $this->setSelectedValue($value);
- }
-
- /**
- * Clears all existing selections.
- */
- public function clearSelection()
- {
- if($this->_items)
- {
- foreach($this->_items as $item)
- $item->setSelected(false);
- }
- }
-
- /**
- * @return string the group of validators which the list control causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the list control causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * Raises OnSelectedIndexChanged event when selection is changed.
- * This method is invoked when the list control has its selection changed
- * by end-users.
- * @param TEventParameter event parameter
- */
- public function onSelectedIndexChanged($param)
- {
- $this->raiseEvent('OnSelectedIndexChanged',$this,$param);
- $this->onTextChanged($param);
- }
-
- /**
- * Raises OnTextChanged event when selection is changed.
- * This method is invoked when the list control has its selection changed
- * by end-users.
- * @param TEventParameter event parameter
- */
- public function onTextChanged($param)
- {
- $this->raiseEvent('OnTextChanged',$this,$param);
- }
-
- /**
- * Renders body content of the list control.
- * This method renders items contained in the list control as the body content.
- * @param THtmlWriter writer
- */
- public function renderContents($writer)
- {
- if($this->_items)
- {
- $writer->writeLine();
- foreach($this->_items as $item)
- {
- if($item->getEnabled())
- {
- if($item->getSelected())
- $writer->addAttribute('selected','selected');
- $writer->addAttribute('value',$item->getValue());
- if($item->getHasAttributes())
- {
- foreach($item->getAttributes() as $name=>$value)
- $writer->addAttribute($name,$value);
- }
- $writer->renderBeginTag('option');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- $writer->writeLine();
- }
- }
- }
- }
-
- /**
- * Formats the text value according to a format string.
- * If the format string is empty, the original value is converted into
- * a string and returned.
- * If the format string starts with '#', the string is treated as a PHP expression
- * within which the token '{0}' is translated with the data value to be formated.
- * Otherwise, the format string and the data value are passed
- * as the first and second parameters in {@link sprintf}.
- * @param string format string
- * @param mixed the data to be formatted
- * @return string the formatted result
- */
- protected function formatDataValue($formatString,$value)
- {
- if($formatString==='')
- return TPropertyValue::ensureString($value);
- else if($formatString[0]==='#')
- {
- $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
- try
- {
- if(eval("\$result=$expression;")===false)
- throw new Exception('');
- return $result;
- }
- catch(Exception $e)
- {
- throw new TInvalidDataValueException('listcontrol_expression_invalid',get_class($this),$expression,$e->getMessage());
- }
- }
- else
- return sprintf($formatString,$value);
- }
-}
-
-/**
- * TListItemCollection class.
- *
- * TListItemCollection maintains a list of {@link TListItem} for {@link TListControl}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TListItemCollection extends TList
-{
- /**
- * Creates a list item object.
- * This method may be overriden to provide a customized list item object.
- * @param integer index where the newly created item is to be inserted at.
- * If -1, the item will be appended to the end.
- * @return TListItem list item object
- */
- public function createListItem($index=-1)
- {
- $item=new TListItem;
- if($index<0)
- $this->add($item);
- else
- $this->insertAt($index,$item);
- return $item;
- }
-
- /**
- * Inserts an item into the collection.
- * @param integer the location where the item will be inserted.
- * The current item at the place and the following ones will be moved backward.
- * @param TListItem the item to be inserted.
- * @throws TInvalidDataTypeException if the item being inserted is neither a string nor TListItem
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TListItem)
- parent::insertAt($index,$item);
- else if(is_string($item))
- {
- $item=$this->createListItem($index);
- $item->setText($item);
- }
- else
- throw new TInvalidDataTypeException('listitemcollection_item_invalid',get_class($this));
- }
-
- /**
- * Finds the lowest cardinal index of the item whose value is the one being looked for.
- * @param string the value to be looked for
- * @param boolean whether to look for disabled items also
- * @return integer the index of the item found, -1 if not found.
- */
- public function findIndexByValue($value,$includeDisabled=true)
- {
- $value=TPropertyValue::ensureString($value);
- $index=0;
- foreach($this as $item)
- {
- if($item->getValue()===$value && ($includeDisabled || $item->getEnabled()))
- return $index;
- $index++;
- }
- return -1;
- }
-
- /**
- * Finds the lowest cardinal index of the item whose text is the one being looked for.
- * @param string the text to be looked for
- * @param boolean whether to look for disabled items also
- * @return integer the index of the item found, -1 if not found.
- */
- public function findIndexByText($text,$includeDisabled=true)
- {
- $text=TPropertyValue::ensureString($text);
- $index=0;
- foreach($this as $item)
- {
- if($item->getText()===$text && ($includeDisabled || $item->getEnabled()))
- return $index;
- $index++;
- }
- return -1;
- }
-
- /**
- * Finds the item whose value is the one being looked for.
- * @param string the value to be looked for
- * @param boolean whether to look for disabled items also
- * @return TListItem the item found, null if not found.
- */
- public function findItemByValue($value,$includeDisabled=true)
- {
- if(($index=$this->findIndexByValue($value,$includeDisabled))>=0)
- return $this->itemAt($index);
- else
- return null;
- }
-
- /**
- * Finds the item whose text is the one being looked for.
- * @param string the text to be looked for
- * @param boolean whether to look for disabled items also
- * @return TListItem the item found, null if not found.
- */
- public function findItemByText($text,$includeDisabled=true)
- {
- if(($index=$this->findIndexByText($text,$includeDisabled))>=0)
- return $this->itemAt($index);
- else
- return null;
- }
-
- /**
- * Loads state into every item in the collection.
- * This method should only be used by framework and control developers.
- * @param array|null state to be loaded.
- */
- public function loadState($state)
- {
- $this->clear();
- if($state!==null)
- $this->copyFrom($state);
- }
-
- /**
- * Saves state of items.
- * This method should only be used by framework and control developers.
- * @return array|null the saved state
- */
- public function saveState()
- {
- return ($this->getCount()>0) ? $this->toArray() : null;
- }
-}
-
-?>
+<?php
+/**
+ * TListControl class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes the supporting classes
+ */
+Prado::using('System.Web.UI.WebControls.TDataBoundControl');
+Prado::using('System.Web.UI.WebControls.TListItem');
+Prado::using('System.Collections.TAttributeCollection');
+Prado::using('System.Util.TDataFieldAccessor');
+
+
+/**
+ * TListControl class
+ *
+ * TListControl is a base class for list controls, such as {@link TListBox},
+ * {@link TDropDownList}, {@link TCheckBoxList}, etc.
+ * It manages the items and their status in a list control.
+ * It also implements how the items can be populated from template and
+ * data source.
+ *
+ * The property {@link getItems} returns a list of the items in the control.
+ * To specify or determine which item is selected, use the
+ * {@link getSelectedIndex SelectedIndex} property that indicates the zero-based
+ * index of the selected item in the item list. You may also use
+ * {@link getSelectedItem SelectedItem} and {@link getSelectedValue SelectedValue}
+ * to get the selected item and its value. For multiple selection lists
+ * (such as {@link TCheckBoxList} and {@link TListBox}), property
+ * {@link getSelectedIndices SelectedIndices} is useful.
+ *
+ * TListControl implements {@link setAutoPostBack AutoPostBack} which allows
+ * a list control to postback the page if the selections of the list items are changed.
+ * The {@link setCausesValidation CausesValidation} and {@link setValidationGroup ValidationGroup}
+ * properties may be used to specify that validation be performed when auto postback occurs.
+ *
+ * There are three ways to populate the items in a list control: from template,
+ * using {@link setDataSource DataSource} and using {@link setDataSourceID DataSourceID}.
+ * The latter two are covered in {@link TDataBoundControl}. To specify items via
+ * template, using the following template syntax:
+ * <code>
+ * <com:TListControl>
+ * <com:TListItem Value="xxx" Text="yyy" >
+ * <com:TListItem Value="xxx" Text="yyy" Selected="true" >
+ * <com:TListItem Value="xxx" Text="yyy" >
+ * </com:TListControl>
+ * </code>
+ *
+ * When {@link setDataSource DataSource} or {@link setDataSourceID DataSourceID}
+ * is used to populate list items, the {@link setDataTextField DataTextField} and
+ * {@link setDataValueField DataValueField} properties are used to specify which
+ * columns of the data will be used to populate the text and value of the items.
+ * For example, if a data source is as follows,
+ * <code>
+ * $dataSource=array(
+ * array('name'=>'John', 'age'=>31),
+ * array('name'=>'Cary', 'age'=>28),
+ * array('name'=>'Rose', 'age'=>35),
+ * );
+ * </code>
+ * setting {@link setDataTextField DataTextField} and {@link setDataValueField DataValueField}
+ * to 'name' and 'age' will make the first item's text be 'John', value be 31,
+ * the second item's text be 'Cary', value be 28, and so on.
+ * The {@link setDataTextFormatString DataTextFormatString} property may be further
+ * used to format how the item should be displayed. See {@link formatDataValue()}
+ * for an explanation of the format string.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class TListControl extends TDataBoundControl
+{
+ /**
+ * @var TListItemCollection item list
+ */
+ private $_items=null;
+ /**
+ * @var boolean whether items are restored from viewstate
+ */
+ private $_stateLoaded=false;
+ /**
+ * @var mixed the following selection variables are used
+ * to keep selections when Items are not available
+ */
+ private $_cachedSelectedIndex=-1;
+ private $_cachedSelectedValue=null;
+
+ /**
+ * @return string tag name of the list control
+ */
+ protected function getTagName()
+ {
+ return 'select';
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+ if($this->getIsMultiSelect())
+ $writer->addAttribute('multiple','multiple');
+ if($this->getEnabled(true))
+ {
+ if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
+ $this->renderClientControlScript($writer);
+ }
+ else if($this->getEnabled())
+ $writer->addAttribute('disabled','disabled');
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the javascript for list control.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ abstract protected function getClientClassName();
+
+ /**
+ * @return array postback options for JS postback code
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['EventTarget'] = $this->getUniqueID();
+ return $options;
+ }
+
+ /**
+ * Adds object parsed from template to the control.
+ * This method adds only {@link TListItem} objects into the {@link getItems Items} collection.
+ * All other objects are ignored.
+ * @param mixed object parsed from template
+ */
+ public function addParsedObject($object)
+ {
+ // Do not add items from template if items are loaded from viewstate
+ if(!$this->_stateLoaded && ($object instanceof TListItem))
+ {
+ $index=$this->getItems()->add($object);
+ if(($this->_cachedSelectedValue!==null && $this->_cachedSelectedValue===$object->getValue()) || ($this->_cachedSelectedIndex===$index))
+ {
+ $object->setSelected(true);
+ $this->_cachedSelectedValue=null;
+ $this->_cachedSelectedIndex=-1;
+ }
+ }
+ }
+
+ /**
+ * Performs databinding to populate list items from data source.
+ * This method is invoked by dataBind().
+ * You may override this function to provide your own way of data population.
+ * @param Traversable the data
+ */
+ protected function performDataBinding($data)
+ {
+ $items=$this->getItems();
+ if(!$this->getAppendDataBoundItems())
+ $items->clear();
+ $textField=$this->getDataTextField();
+ if($textField==='')
+ $textField=0;
+ $valueField=$this->getDataValueField();
+ if($valueField==='')
+ $valueField=1;
+ $textFormat=$this->getDataTextFormatString();
+ foreach($data as $key=>$object)
+ {
+ $item=$items->createListItem();
+ if(is_array($object) || is_object($object))
+ {
+ $text=TDataFieldAccessor::getDataFieldValue($object,$textField);
+ $value=TDataFieldAccessor::getDataFieldValue($object,$valueField);
+ $item->setValue($value);
+ }
+ else
+ {
+ $text=$object;
+ $item->setValue("$key");
+ }
+ $item->setText($this->formatDataValue($textFormat,$text));
+ }
+ // SelectedValue or SelectedIndex may be set before databinding
+ // so we make them be effective now
+ if($this->_cachedSelectedValue!==null)
+ {
+ $index=$items->findIndexByValue($this->_cachedSelectedValue);
+ if($index===-1 || ($this->_cachedSelectedIndex!==-1 && $this->_cachedSelectedIndex!==$index))
+ throw new TInvalidDataValueException('listcontrol_selection_invalid',get_class($this));
+ $this->setSelectedIndex($index);
+ $this->_cachedSelectedValue=null;
+ $this->_cachedSelectedIndex=-1;
+ }
+ else if($this->_cachedSelectedIndex!==-1)
+ {
+ $this->setSelectedIndex($this->_cachedSelectedIndex);
+ $this->_cachedSelectedIndex=-1;
+ }
+ }
+
+ /**
+ * Creates a collection object to hold list items.
+ * This method may be overriden to create a customized collection.
+ * @return TListItemCollection the collection object
+ */
+ protected function createListItemCollection()
+ {
+ return new TListItemCollection;
+ }
+
+ /**
+ * Saves items into viewstate.
+ * This method is invoked right before control state is to be saved.
+ */
+ public function saveState()
+ {
+ parent::saveState();
+ if($this->_items)
+ $this->setViewState('Items',$this->_items->saveState(),null);
+ else
+ $this->clearViewState('Items');
+ }
+
+ /**
+ * Loads items from viewstate.
+ * This method is invoked right after control state is loaded.
+ */
+ public function loadState()
+ {
+ parent::loadState();
+ $this->_stateLoaded=true;
+ if(!$this->getIsDataBound())
+ {
+ $this->_items=$this->createListItemCollection();
+ $this->_items->loadState($this->getViewState('Items',null));
+ }
+ $this->clearViewState('Items');
+ }
+
+ /**
+ * @return boolean whether this is a multiselect control. Defaults to false.
+ */
+ protected function getIsMultiSelect()
+ {
+ return false;
+ }
+
+ /**
+ * @return boolean whether performing databind should append items or clear the existing ones. Defaults to false.
+ */
+ public function getAppendDataBoundItems()
+ {
+ return $this->getViewState('AppendDataBoundItems',false);
+ }
+
+ /**
+ * @param boolean whether performing databind should append items or clear the existing ones.
+ */
+ public function setAppendDataBoundItems($value)
+ {
+ $this->setViewState('AppendDataBoundItems',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean a value indicating whether an automatic postback to the server
+ * will occur whenever the user makes change to the list control and then tabs out of it.
+ * Defaults to false.
+ */
+ public function getAutoPostBack()
+ {
+ return $this->getViewState('AutoPostBack',false);
+ }
+
+ /**
+ * Sets the value indicating if postback automatically.
+ * An automatic postback to the server will occur whenever the user
+ * makes change to the list control and then tabs out of it.
+ * @param boolean the value indicating if postback automatically
+ */
+ public function setAutoPostBack($value)
+ {
+ $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this list control will cause input validation, default is true.
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this list control will cause input validation.
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the field of the data source that provides the text content of the list items.
+ */
+ public function getDataTextField()
+ {
+ return $this->getViewState('DataTextField','');
+ }
+
+ /**
+ * @param string the field of the data source that provides the text content of the list items.
+ */
+ public function setDataTextField($value)
+ {
+ $this->setViewState('DataTextField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how data bound to the list control is displayed.
+ */
+ public function getDataTextFormatString()
+ {
+ return $this->getViewState('DataTextFormatString','');
+ }
+
+ /**
+ * Sets data text format string.
+ * The format string is used in {@link TDataValueFormatter::format()} to format the Text property value
+ * of each item in the list control.
+ * @param string the formatting string used to control how data bound to the list control is displayed.
+ * @see TDataValueFormatter::format()
+ */
+ public function setDataTextFormatString($value)
+ {
+ $this->setViewState('DataTextFormatString',$value,'');
+ }
+
+ /**
+ * @return string the field of the data source that provides the value of each list item.
+ */
+ public function getDataValueField()
+ {
+ return $this->getViewState('DataValueField','');
+ }
+
+ /**
+ * @param string the field of the data source that provides the value of each list item.
+ */
+ public function setDataValueField($value)
+ {
+ $this->setViewState('DataValueField',$value,'');
+ }
+
+ /**
+ * @return integer the number of items in the list control
+ */
+ public function getItemCount()
+ {
+ return $this->_items?$this->_items->getCount():0;
+ }
+
+ /**
+ * @return boolean whether the list control contains any items.
+ */
+ public function getHasItems()
+ {
+ return ($this->_items && $this->_items->getCount()>0);
+ }
+
+ /**
+ * @return TListItemCollection the item collection
+ */
+ public function getItems()
+ {
+ if(!$this->_items)
+ $this->_items=$this->createListItemCollection();
+ return $this->_items;
+ }
+
+ /**
+ * @return integer the index (zero-based) of the item being selected, -1 if no item is selected.
+ */
+ public function getSelectedIndex()
+ {
+ if($this->_items)
+ {
+ $n=$this->_items->getCount();
+ for($i=0;$i<$n;++$i)
+ if($this->_items->itemAt($i)->getSelected())
+ return $i;
+ }
+ return -1;
+ }
+
+ /**
+ * @param integer the index (zero-based) of the item to be selected
+ */
+ public function setSelectedIndex($index)
+ {
+ if(($index=TPropertyValue::ensureInteger($index))<0)
+ $index=-1;
+ if($this->_items)
+ {
+ $this->clearSelection();
+ if($index>=0 && $index<$this->_items->getCount())
+ $this->_items->itemAt($index)->setSelected(true);
+ else if($index!==-1)
+ throw new TInvalidDataValueException('listcontrol_selectedindex_invalid',get_class($this),$index);
+ }
+ $this->_cachedSelectedIndex=$index;
+ }
+
+ /**
+ * @return array list of index of items that are selected
+ */
+ public function getSelectedIndices()
+ {
+ $selections=array();
+ if($this->_items)
+ {
+ $n=$this->_items->getCount();
+ for($i=0;$i<$n;++$i)
+ if($this->_items->itemAt($i)->getSelected())
+ $selections[]=$i;
+ }
+ return $selections;
+ }
+
+ /**
+ * @param array list of index of items to be selected
+ */
+ public function setSelectedIndices($indices)
+ {
+ if($this->_items)
+ {
+ $this->clearSelection();
+ $n=$this->_items->getCount();
+ foreach($indices as $index)
+ {
+ if($index>=0 && $index<$n)
+ $this->_items->itemAt($index)->setSelected(true);
+ }
+ }
+ }
+
+ /**
+ * @return TListItem|null the selected item with the lowest cardinal index, null if no item is selected.
+ */
+ public function getSelectedItem()
+ {
+ if(($index=$this->getSelectedIndex())>=0)
+ return $this->_items->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * @return string the value of the selected item with the lowest cardinal index, empty if no selection
+ */
+ public function getSelectedValue()
+ {
+ $index=$this->getSelectedIndex();
+ return $index>=0?$this->getItems()->itemAt($index)->getValue():'';
+ }
+
+ /**
+ * Sets selection by item value.
+ * Existing selections will be cleared if the item value is found in the item collection.
+ * Note, if the value is null, existing selections will also be cleared.
+ * @param string the value of the item to be selected.
+ */
+ public function setSelectedValue($value)
+ {
+ if($this->_items)
+ {
+ if($value===null)
+ $this->clearSelection();
+ else if(($item=$this->_items->findItemByValue($value))!==null)
+ {
+ $this->clearSelection();
+ $item->setSelected(true);
+ }
+ else
+ throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value);
+ }
+ $this->_cachedSelectedValue=$value;
+ }
+
+
+ /**
+ * @return array list of the selected item values (strings)
+ */
+ public function getSelectedValues()
+ {
+ $values=array();
+ if($this->_items)
+ {
+ foreach($this->_items as $item)
+ {
+ if($item->getSelected())
+ $values[]=$item->getValue();
+ }
+ }
+ return $values;
+ }
+
+ /**
+ * @param array list of the selected item values
+ */
+ public function setSelectedValues($values)
+ {
+ if($this->_items)
+ {
+ $this->clearSelection();
+ $lookup=array();
+ foreach($this->_items as $item)
+ $lookup[$item->getValue()]=$item;
+ foreach($values as $value)
+ {
+ if(isset($lookup["$value"]))
+ $lookup["$value"]->setSelected(true);
+ else
+ throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value);
+ }
+ }
+ }
+
+ /**
+ * @return string selected value
+ */
+ public function getText()
+ {
+ return $this->getSelectedValue();
+ }
+
+ /**
+ * @param string value to be selected
+ */
+ public function setText($value)
+ {
+ $this->setSelectedValue($value);
+ }
+
+ /**
+ * Clears all existing selections.
+ */
+ public function clearSelection()
+ {
+ if($this->_items)
+ {
+ foreach($this->_items as $item)
+ $item->setSelected(false);
+ }
+ }
+
+ /**
+ * @return string the group of validators which the list control causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the list control causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * Raises OnSelectedIndexChanged event when selection is changed.
+ * This method is invoked when the list control has its selection changed
+ * by end-users.
+ * @param TEventParameter event parameter
+ */
+ public function onSelectedIndexChanged($param)
+ {
+ $this->raiseEvent('OnSelectedIndexChanged',$this,$param);
+ $this->onTextChanged($param);
+ }
+
+ /**
+ * Raises OnTextChanged event when selection is changed.
+ * This method is invoked when the list control has its selection changed
+ * by end-users.
+ * @param TEventParameter event parameter
+ */
+ public function onTextChanged($param)
+ {
+ $this->raiseEvent('OnTextChanged',$this,$param);
+ }
+
+ /**
+ * Renders body content of the list control.
+ * This method renders items contained in the list control as the body content.
+ * @param THtmlWriter writer
+ */
+ public function renderContents($writer)
+ {
+ if($this->_items)
+ {
+ $writer->writeLine();
+ foreach($this->_items as $item)
+ {
+ if($item->getEnabled())
+ {
+ if($item->getSelected())
+ $writer->addAttribute('selected','selected');
+ $writer->addAttribute('value',$item->getValue());
+ if($item->getHasAttributes())
+ {
+ foreach($item->getAttributes() as $name=>$value)
+ $writer->addAttribute($name,$value);
+ }
+ $writer->renderBeginTag('option');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ }
+ }
+ }
+
+ /**
+ * Formats the text value according to a format string.
+ * If the format string is empty, the original value is converted into
+ * a string and returned.
+ * If the format string starts with '#', the string is treated as a PHP expression
+ * within which the token '{0}' is translated with the data value to be formated.
+ * Otherwise, the format string and the data value are passed
+ * as the first and second parameters in {@link sprintf}.
+ * @param string format string
+ * @param mixed the data to be formatted
+ * @return string the formatted result
+ */
+ protected function formatDataValue($formatString,$value)
+ {
+ if($formatString==='')
+ return TPropertyValue::ensureString($value);
+ else if($formatString[0]==='#')
+ {
+ $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
+ try
+ {
+ if(eval("\$result=$expression;")===false)
+ throw new Exception('');
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('listcontrol_expression_invalid',get_class($this),$expression,$e->getMessage());
+ }
+ }
+ else
+ return sprintf($formatString,$value);
+ }
+}
+
+/**
+ * TListItemCollection class.
+ *
+ * TListItemCollection maintains a list of {@link TListItem} for {@link TListControl}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TListItemCollection extends TList
+{
+ /**
+ * Creates a list item object.
+ * This method may be overriden to provide a customized list item object.
+ * @param integer index where the newly created item is to be inserted at.
+ * If -1, the item will be appended to the end.
+ * @return TListItem list item object
+ */
+ public function createListItem($index=-1)
+ {
+ $item=new TListItem;
+ if($index<0)
+ $this->add($item);
+ else
+ $this->insertAt($index,$item);
+ return $item;
+ }
+
+ /**
+ * Inserts an item into the collection.
+ * @param integer the location where the item will be inserted.
+ * The current item at the place and the following ones will be moved backward.
+ * @param TListItem the item to be inserted.
+ * @throws TInvalidDataTypeException if the item being inserted is neither a string nor TListItem
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TListItem)
+ parent::insertAt($index,$item);
+ else if(is_string($item))
+ {
+ $item=$this->createListItem($index);
+ $item->setText($item);
+ }
+ else
+ throw new TInvalidDataTypeException('listitemcollection_item_invalid',get_class($this));
+ }
+
+ /**
+ * Finds the lowest cardinal index of the item whose value is the one being looked for.
+ * @param string the value to be looked for
+ * @param boolean whether to look for disabled items also
+ * @return integer the index of the item found, -1 if not found.
+ */
+ public function findIndexByValue($value,$includeDisabled=true)
+ {
+ $value=TPropertyValue::ensureString($value);
+ $index=0;
+ foreach($this as $item)
+ {
+ if($item->getValue()===$value && ($includeDisabled || $item->getEnabled()))
+ return $index;
+ $index++;
+ }
+ return -1;
+ }
+
+ /**
+ * Finds the lowest cardinal index of the item whose text is the one being looked for.
+ * @param string the text to be looked for
+ * @param boolean whether to look for disabled items also
+ * @return integer the index of the item found, -1 if not found.
+ */
+ public function findIndexByText($text,$includeDisabled=true)
+ {
+ $text=TPropertyValue::ensureString($text);
+ $index=0;
+ foreach($this as $item)
+ {
+ if($item->getText()===$text && ($includeDisabled || $item->getEnabled()))
+ return $index;
+ $index++;
+ }
+ return -1;
+ }
+
+ /**
+ * Finds the item whose value is the one being looked for.
+ * @param string the value to be looked for
+ * @param boolean whether to look for disabled items also
+ * @return TListItem the item found, null if not found.
+ */
+ public function findItemByValue($value,$includeDisabled=true)
+ {
+ if(($index=$this->findIndexByValue($value,$includeDisabled))>=0)
+ return $this->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * Finds the item whose text is the one being looked for.
+ * @param string the text to be looked for
+ * @param boolean whether to look for disabled items also
+ * @return TListItem the item found, null if not found.
+ */
+ public function findItemByText($text,$includeDisabled=true)
+ {
+ if(($index=$this->findIndexByText($text,$includeDisabled))>=0)
+ return $this->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * Loads state into every item in the collection.
+ * This method should only be used by framework and control developers.
+ * @param array|null state to be loaded.
+ */
+ public function loadState($state)
+ {
+ $this->clear();
+ if($state!==null)
+ $this->copyFrom($state);
+ }
+
+ /**
+ * Saves state of items.
+ * This method should only be used by framework and control developers.
+ * @return array|null the saved state
+ */
+ public function saveState()
+ {
+ return ($this->getCount()>0) ? $this->toArray() : null;
+ }
+}
+
+?>
diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php
index 688b99bf..64387683 100644
--- a/framework/Web/UI/WebControls/TRadioButton.php
+++ b/framework/Web/UI/WebControls/TRadioButton.php
@@ -1,182 +1,182 @@
-<?php
-/**
- * TRadioButton class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TCheckBox parent class
- */
-Prado::using('System.Web.UI.WebControls.TCheckBox');
-/**
- * Using TRadioButtonList class
- */
-Prado::using('System.Web.UI.WebControls.TRadioButtonList');
-
-/**
- * TRadioButton class
- *
- * TRadioButton displays a radio button on the page.
- * You can specify the caption to display beside the radio buttonby setting
- * the {@link setText Text} property. The caption can appear either on the right
- * or left of the radio button, which is determined by the {@link setTextAlign TextAlign}
- * property.
- *
- * To determine whether the TRadioButton component is checked, test the {@link getChecked Checked}
- * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when
- * the {@link getChecked Checked} state of the TRadioButton component changes
- * between posts to the server. You can provide an event handler for
- * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically
- * control the actions performed when the state of the TRadioButton component changes
- * between posts to the server.
- *
- * TRadioButton uses {@link setGroupName GroupName} to group together a set of radio buttons.
- *
- * If {@link setAutoPostBack AutoPostBack} is set true, changing the radio button state
- * 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}.
- *
- * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters
- * that may bring security vulnerabilities.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRadioButton extends TCheckBox
-{
- /**
- * @var string the name used to fetch radiobutton post data
- */
- private $_uniqueGroupName=null;
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values)
- {
- $uniqueGroupName=$this->getUniqueGroupName();
- $value=isset($values[$uniqueGroupName])?$values[$uniqueGroupName]:null;
- if($value!==null && $value===$this->getValueAttribute())
- {
- if(!$this->getChecked())
- {
- $this->setChecked(true);
- return true;
- }
- else
- return false;
- }
- else if($this->getChecked())
- $this->setChecked(false);
- return false;
- }
-
- /**
- * @return string the name of the group that the radio button belongs to. Defaults to empty.
- */
- public function getGroupName()
- {
- return $this->getViewState('GroupName','');
- }
-
- /**
- * Sets the name of the group that the radio button belongs to
- * @param string the group name
- */
- public function setGroupName($value)
- {
- $this->setViewState('GroupName',$value,'');
- }
-
- protected function getValueAttribute()
- {
- if(($value=parent::getValueAttribute())==='')
- return $this->getUniqueID();
- else
- return $value;
- }
-
- /**
- * @return string the name used to fetch radiobutton post data
- */
- private function getUniqueGroupName()
- {
- if($this->_uniqueGroupName===null)
- {
- $groupName=$this->getGroupName();
- $uniqueID=$this->getUniqueID();
- if($uniqueID!=='')
- {
- if(($pos=strrpos($uniqueID,TControl::ID_SEPARATOR))!==false)
- {
- if($groupName!=='')
- $groupName=substr($uniqueID,0,$pos+1).$groupName;
- else if($this->getNamingContainer() instanceof TRadioButtonList)
- $groupName=substr($uniqueID,0,$pos);
- }
- if($groupName==='')
- $groupName=$uniqueID;
- }
- $this->_uniqueGroupName=$groupName;
- }
- return $this->_uniqueGroupName;
- }
-
- /**
- * Renders a radiobutton input element.
- * @param THtmlWriter the writer for the rendering purpose
- * @param string checkbox id
- * @param string onclick js
- */
- protected function renderInputTag($writer,$clientID,$onclick)
- {
- if($clientID!=='')
- $writer->addAttribute('id',$clientID);
- $writer->addAttribute('type','radio');
- $writer->addAttribute('name',$this->getUniqueGroupName());
- $writer->addAttribute('value',$this->getValueAttribute());
- if($onclick!=='')
- $writer->addAttribute('onclick',$onclick);
- if($this->getChecked())
- $writer->addAttribute('checked','checked');
- if(!$this->getEnabled(true))
- $writer->addAttribute('disabled','disabled');
-
- $page=$this->getPage();
- if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- $this->renderClientControlScript($writer);
-
- if(($accesskey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accesskey);
- if(($tabindex=$this->getTabIndex())>0)
- $writer->addAttribute('tabindex',"$tabindex");
- if($attributes=$this->getViewState('InputAttributes',null))
- $writer->addAttributes($attributes);
- $writer->renderBeginTag('input');
- $writer->renderEndTag();
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl('Prado.WebUI.TRadioButton',$this->getPostBackOptions());
- }
-}
-
+<?php
+/**
+ * TRadioButton class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TCheckBox parent class
+ */
+Prado::using('System.Web.UI.WebControls.TCheckBox');
+/**
+ * Using TRadioButtonList class
+ */
+Prado::using('System.Web.UI.WebControls.TRadioButtonList');
+
+/**
+ * TRadioButton class
+ *
+ * TRadioButton displays a radio button on the page.
+ * You can specify the caption to display beside the radio buttonby setting
+ * the {@link setText Text} property. The caption can appear either on the right
+ * or left of the radio button, which is determined by the {@link setTextAlign TextAlign}
+ * property.
+ *
+ * To determine whether the TRadioButton component is checked, test the {@link getChecked Checked}
+ * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when
+ * the {@link getChecked Checked} state of the TRadioButton component changes
+ * between posts to the server. You can provide an event handler for
+ * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically
+ * control the actions performed when the state of the TRadioButton component changes
+ * between posts to the server.
+ *
+ * TRadioButton uses {@link setGroupName GroupName} to group together a set of radio buttons.
+ *
+ * If {@link setAutoPostBack AutoPostBack} is set true, changing the radio button state
+ * 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}.
+ *
+ * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters
+ * that may bring security vulnerabilities.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRadioButton extends TCheckBox
+{
+ /**
+ * @var string the name used to fetch radiobutton post data
+ */
+ private $_uniqueGroupName=null;
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $uniqueGroupName=$this->getUniqueGroupName();
+ $value=isset($values[$uniqueGroupName])?$values[$uniqueGroupName]:null;
+ if($value!==null && $value===$this->getValueAttribute())
+ {
+ if(!$this->getChecked())
+ {
+ $this->setChecked(true);
+ return true;
+ }
+ else
+ return false;
+ }
+ else if($this->getChecked())
+ $this->setChecked(false);
+ return false;
+ }
+
+ /**
+ * @return string the name of the group that the radio button belongs to. Defaults to empty.
+ */
+ public function getGroupName()
+ {
+ return $this->getViewState('GroupName','');
+ }
+
+ /**
+ * Sets the name of the group that the radio button belongs to
+ * @param string the group name
+ */
+ public function setGroupName($value)
+ {
+ $this->setViewState('GroupName',$value,'');
+ }
+
+ protected function getValueAttribute()
+ {
+ if(($value=parent::getValueAttribute())==='')
+ return $this->getUniqueID();
+ else
+ return $value;
+ }
+
+ /**
+ * @return string the name used to fetch radiobutton post data
+ */
+ private function getUniqueGroupName()
+ {
+ if($this->_uniqueGroupName===null)
+ {
+ $groupName=$this->getGroupName();
+ $uniqueID=$this->getUniqueID();
+ if($uniqueID!=='')
+ {
+ if(($pos=strrpos($uniqueID,TControl::ID_SEPARATOR))!==false)
+ {
+ if($groupName!=='')
+ $groupName=substr($uniqueID,0,$pos+1).$groupName;
+ else if($this->getNamingContainer() instanceof TRadioButtonList)
+ $groupName=substr($uniqueID,0,$pos);
+ }
+ if($groupName==='')
+ $groupName=$uniqueID;
+ }
+ $this->_uniqueGroupName=$groupName;
+ }
+ return $this->_uniqueGroupName;
+ }
+
+ /**
+ * Renders a radiobutton input element.
+ * @param THtmlWriter the writer for the rendering purpose
+ * @param string checkbox id
+ * @param string onclick js
+ */
+ protected function renderInputTag($writer,$clientID,$onclick)
+ {
+ if($clientID!=='')
+ $writer->addAttribute('id',$clientID);
+ $writer->addAttribute('type','radio');
+ $writer->addAttribute('name',$this->getUniqueGroupName());
+ $writer->addAttribute('value',$this->getValueAttribute());
+ if($onclick!=='')
+ $writer->addAttribute('onclick',$onclick);
+ if($this->getChecked())
+ $writer->addAttribute('checked','checked');
+ if(!$this->getEnabled(true))
+ $writer->addAttribute('disabled','disabled');
+
+ $page=$this->getPage();
+ if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript())
+ $this->renderClientControlScript($writer);
+
+ if(($accesskey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accesskey);
+ if(($tabindex=$this->getTabIndex())>0)
+ $writer->addAttribute('tabindex',"$tabindex");
+ if($attributes=$this->getViewState('InputAttributes',null))
+ $writer->addAttributes($attributes);
+ $writer->renderBeginTag('input');
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl('Prado.WebUI.TRadioButton',$this->getPostBackOptions());
+ }
+}
+
?> \ No newline at end of file