diff options
32 files changed, 4250 insertions, 3801 deletions
diff --git a/.gitattributes b/.gitattributes index 79cb8dfd..40db22fe 100644 --- a/.gitattributes +++ b/.gitattributes @@ -596,8 +596,10 @@ framework/DataAccess/SQLMap/Statements/TUpdateMappedStatement.php -text framework/DataAccess/SQLMap/TMapper.php -text framework/DataAccess/SQLMap/TSqlMapClient.php -text framework/DataAccess/SQLMap/TSqlMapper.php -text +framework/DataAccess/TActiveRecord.php -text framework/DataAccess/TAdodb.php -text framework/DataAccess/TDatabaseProvider.php -text +framework/DataAccess/TEzpdo.php -text framework/DataAccess/TSQLMap.php -text framework/Exceptions/TErrorHandler.php -text framework/Exceptions/TException.php -text diff --git a/buildscripts/jsbuilder/build.php b/buildscripts/jsbuilder/build.php index 50fb8b56..fa9ef72a 100644 --- a/buildscripts/jsbuilder/build.php +++ b/buildscripts/jsbuilder/build.php @@ -113,6 +113,10 @@ $libraries = array( 'extra/logger.js',
),
+ 'containers.js' => array(
+ 'effects/dragdrop.js',
+ ),
+
//rico
'rico.js' => array(
'rico/rico.js',
diff --git a/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php b/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php index 9a44d1ec..ee8f1744 100644 --- a/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php +++ b/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php @@ -111,6 +111,7 @@ class TConfigDeserialize $property->initialize($sqlMap, $resultMap);
$resultMap->addResultProperty($property);
}
+
$discriminator = null;
if(isset($node->discriminator))
{
@@ -118,18 +119,24 @@ class TConfigDeserialize $this->loadConfiguration($discriminator, $node->discriminator, $file);
$discriminator->initMapping($sqlMap, $resultMap);
}
+
+
+
foreach($node->subMap as $subMapNode)
{
- if(is_null($discriminator))
- throw new TSqlMapConfigurationException(
- 'sqlmap_undefined_discriminator', $resultMap->getID(), $file);
- $subMap = new TSubMap;
- $this->loadConfiguration($subMap, $subMapNode, $file);
- $discriminator->add($subMap);
+ if(isset($subMapNode['value']))
+ {
+ if(is_null($discriminator))
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_undefined_discriminator', $resultMap->getID(), $file);
+
+ $subMap = new TSubMap;
+ $this->loadConfiguration($subMap, $subMapNode, $file);
+ $discriminator->add($subMap);
+ }
}
if(!is_null($discriminator))
$resultMap->setDiscriminator($discriminator);
-
return $resultMap;
}
diff --git a/framework/DataAccess/SQLMap/DataMapper/TPropertyAccess.php b/framework/DataAccess/SQLMap/DataMapper/TPropertyAccess.php index 8680601e..4bbe2cb5 100644 --- a/framework/DataAccess/SQLMap/DataMapper/TPropertyAccess.php +++ b/framework/DataAccess/SQLMap/DataMapper/TPropertyAccess.php @@ -39,7 +39,7 @@ class TPropertyAccess */
public static function get($object,$path)
{
- if(!is_array($object) && !is_object($object))
+ if(!is_array($object) || !is_object($object))
return $object;
$properties = explode('.', $path);
foreach($properties as $prop)
@@ -67,6 +67,34 @@ class TPropertyAccess return $object;
}
+ public static function has($object, $path)
+ {
+ if(!is_array($object) || !is_object($object))
+ return false;
+ $properties = explode('.', $path);
+ foreach($properties as $prop)
+ {
+ if(is_array($object) || $object instanceof ArrayAccess)
+ {
+ if(isset($object[$prop]))
+ $object = $object[$prop];
+ else
+ return false;
+ }
+ else if(is_object($object))
+ {
+ $getter = 'get'.$prop;
+ if(is_callable(array($object,$getter)))
+ $object = $object->{$getter}();
+ else if(in_array($prop, array_keys(get_object_vars($object))))
+ $object = $object->{$prop};
+ return false;
+ }
+ else
+ return false;
+ }
+ return true;
+ }
public static function set($object, $path, $value)
{
diff --git a/framework/DataAccess/TActiveRecord.php b/framework/DataAccess/TActiveRecord.php new file mode 100644 index 00000000..0c33fde3 --- /dev/null +++ b/framework/DataAccess/TActiveRecord.php @@ -0,0 +1,51 @@ +<?php
+
+Prado::using('System.3rdParty.adodb.ADOdb_Active_Record');
+
+/**
+ * Adodb's active record implementation is very basic. Example: A table
+ * named "persons"
+ * <code>
+ * CREATE TABLE persons
+ * (
+ * id INTEGER PRIMARY KEY,
+ * first_name TEXT NOT NULL,
+ * last_name TEXT NOT NULL,
+ * favorite_color TEXT NOT NULL
+ * );
+ * </code>
+ * Create a class called <tt>Person</tt>, connect insert some data as follows.
+ * <code>
+ * class Person extends TActiveRecord { }
+ *
+ * $person = new Person();
+ * $person->first_name = 'Andi';
+ * $person->last_name = 'Gutmans';
+ * $person->favorite_color = 'blue';
+ * $person->save(); // this save will perform an INSERT successfully
+ *
+ * $person = new Person();
+ * $person->first_name = 'John';
+ * $person->last_name = 'Lim';
+ * $person->favorite_color = 'lavender';
+ * $person->save(); // this save will perform an INSERT successfully
+ *
+ * // load record where id=2 into a new ADOdb_Active_Record
+ * $person2 = new Person();
+ * $person2->Load('id=2');
+ * var_dump($person2);
+ * </code>
+ *
+ *
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.DataAccess
+ * @since 3.0
+ */
+class TActiveRecord extends ADOdb_Active_Record
+{
+
+}
+
+?>
\ No newline at end of file diff --git a/framework/DataAccess/TAdodb.php b/framework/DataAccess/TAdodb.php index c7005c76..cd188e49 100644 --- a/framework/DataAccess/TAdodb.php +++ b/framework/DataAccess/TAdodb.php @@ -143,6 +143,7 @@ class TAdodb extends TDatabaseProvider */
public function getConnection()
{
+ $this->init(null);
return $this->_connection;
}
@@ -303,9 +304,10 @@ class TAdodbConnection extends TDbConnection */
public function __construct($provider=null)
{
- parent::__construct($provider);
if(is_string($provider))
$this->initProvider($provider);
+ else
+ parent::__construct($provider);
}
/**
@@ -329,7 +331,6 @@ class TAdodbConnection extends TDbConnection //close any open connections before serializing.
$this->close();
$this->_connection = null;
- return array_keys(get_object_vars($this));
}
/**
diff --git a/framework/DataAccess/TEzpdo.php b/framework/DataAccess/TEzpdo.php new file mode 100644 index 00000000..de9d53fe --- /dev/null +++ b/framework/DataAccess/TEzpdo.php @@ -0,0 +1,251 @@ +<?php
+
+class TEzpdo extends TDatabaseProvider
+{
+ /**
+ * @var array list of default ezpdo options.
+ */
+ private $_options = array(
+ 'source_dirs' => null,
+ 'recursive' => true,
+ 'compiled_dir' => null, // default to compiled under current dir
+ 'compiled_file' => 'compiled_file', // the default class map file
+ 'backup_compiled' => true, // whether to backup old compiled file
+ 'check_table_exists' => true, // whether always check if table exists before db operation
+ 'table_prefix' => '', // table prefix (default to none)
+ 'relation_table' => '_ez_relation_', // the table name for object relations
+ 'split_relation_table' => true, // whether to split relation table
+ 'auto_flush' => false, // enable or disable auto flush at the end of script
+ 'flush_before_find' => true, // enable or disable auto flush before find()
+ 'auto_compile' => true, // enable or disable auto compile
+ 'autoload' => false, // enable or disable class autoloading
+ 'log_queries' => false, // enable logging queries (for debug only)
+ 'dispatch_events' => true, // whether to dispatch events (true by default)
+ 'default_oid_column' => 'eoid', // oid column name is default to 'eoid' now
+ );
+
+ /**
+ * @var array List of source directories.
+ */
+ private $_sources = array();
+
+ /**
+ * @var epManager ezpdo manager instance.
+ */
+ private $_manager;
+
+ /**
+ * Initialize the ezpdo module, sets the default compile directory to use
+ * the Prado runtime directory.
+ */
+ public function init($config)
+ {
+ parent::init($config);
+ include($this->getEzpdoLibrary().'/ezpdo.php');
+ $path = $this->getApplication()->getRuntimePath().'/ezpdo';
+ $this->_options['compiled_dir'] = $path;
+ if($this->getApplication()->getMode() != TApplication::STATE_PERFORMANCE)
+ {
+ if(!is_dir($path))
+ throw new TConfigurationException('ezpdo_compile_dir_not_found', $path);
+ $this->_options['auto_compile'] = false;
+ }
+ }
+
+ /**
+ * @return string ezpdo library directory.
+ */
+ protected function getEzpdoLibrary()
+ {
+ return Prado::getPathOfNamespace('System.3rdParty.ezpdo');
+ }
+
+ /**
+ * @return array merged database connection options with the other options.
+ */
+ protected function getOptions()
+ {
+ if(strlen($dsn = $this->getConnectionString()) > 0)
+ $options['default_dsn'] = $dsn;
+ else
+ $options['default_dsn'] = $this->buildDsn();
+
+ return array_merge($this->_options, $options);
+ }
+
+ /**
+ * Initialize the ezManager once.
+ */
+ protected function initialize()
+ {
+ Prado::using('System.3rdParty.ezpdo.src.base.epConfig');
+ include($this->getEzpdoLibrary().'/src/runtime/epManager.php');
+
+ if(is_null($this->_manager))
+ {
+ $this->_manager = new epManager;
+ foreach($this->_sources as $source)
+ Prado::using($source.'.*');
+ $this->_manager->setConfig(new epConfig($this->getOptions()));
+ }
+ }
+
+ /**
+ * @return epManager the ezpdo manager for this module.
+ */
+ public function getConnection()
+ {
+ $this->initialize();
+ return $this->_manager;
+ }
+
+ /**
+ * @param string The intput directory, using dot path aliases, that contains
+ * class source files to be compiled. Use commma for multiple directories
+ */
+ public function setSourceDirs($values)
+ {
+ $paths = array();
+ foreach(explode(',', $values) as $value)
+ {
+ $dot = Prado::getPathOfNamespace($value);
+ $this->_sources[] = $value;
+ if(($path = realpath($dot)) !== false)
+ $paths[] = $path;
+ }
+ $this->_options['source_dirs'] = implode(',', $paths);
+ }
+
+ /**
+ * @return string comma delimited list of source directories.
+ */
+ public function getSourceDirs()
+ {
+ return $this->_options['source_dir'];
+ }
+
+ /**
+ * @param boolean Whether to compile subdirs recursively, default is true.
+ */
+ public function setRecursive($value)
+ {
+ $this->_options['recursive'] = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean true will compile subdirectories recursively.
+ */
+ public function getRecursive()
+ {
+ return $this->_options['recursive'];
+ }
+
+ /**
+ * @param string database table prefix.
+ */
+ public function setTablePrefix($value)
+ {
+ $this->_options['table_prefix'] = $value;
+ }
+
+ /**
+ * @param string the table name for object relations, default is
+ * '_ez_relation_'
+ */
+ public function setRelationTableName($value)
+ {
+ $this->_options['relation_table'] = $value;
+ }
+
+ /**
+ * @return string the table name for object relations.
+ */
+ public function getRelationTableName()
+ {
+ return $this->_options['relation_table'];
+ }
+
+ /**
+ * @param boolean whether to split relation table, default is true.
+ */
+ public function setSplitRelationTable($value)
+ {
+ $this->_options['split_relation_table'] = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @string boolean true will split relation table.
+ */
+ public function getSplitRelationTable()
+ {
+ return $this->_options['split_relation_table'];
+ }
+
+ /**
+ * @param boolean enable or disable auto flush at the end of script, default
+ * is false.
+ */
+ public function setAutoFlush($value)
+ {
+ $this->_options['auto_flush'] = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether to auto flush at the end of script.
+ */
+ public function getAutoFlush()
+ {
+ return $this->_options['auto_flush'];
+ }
+
+ /**
+ * @param boolean enable or disable auto flush before find(), default is
+ * true.
+ */
+ public function setFlushBeforeFind($value)
+ {
+ $this->_options['flush_before_find'] = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether to auto flush before find()
+ */
+ public function getFlushBeforeFind()
+ {
+ return $this->_options['flush_before_find'];
+ }
+
+ /**
+ * @param boolean enable or disable auto compile, default is true.
+ */
+ public function setAutoCompile($value)
+ {
+ $this->_options['auto_compile'] = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether to auto compile class files.
+ */
+ public function getAutoCompile()
+ {
+ return $this->_options['auto_compile'];
+ }
+
+ /**
+ * @param string default oid column name, default is 'eoid'.
+ */
+ public function setDefaultOidColumn($value)
+ {
+ $this->_options['default_oid_column'] = $value;
+ }
+
+ /**
+ * @return string default oid column name.
+ */
+ public function getDefaultOidColumn($value)
+ {
+ return $this->_options['default_oid_column'];
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index 8c79d6ee..028f7f75 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -1,309 +1,312 @@ -prado_application_singleton_required = Prado.Application must only be set once.
-prado_component_unknown = Unknown component type '{0}'.
-prado_using_invalid = '{0}' is not a valid namespace to be used. Make sure '.*' is appended if you want to use a namespace referring to a directory.
-prado_alias_redefined = Alias '{0}' cannot be redefined.
-prado_alias_invalid = Alias '{0}' refers to an invalid path '{1}'. Only existing directories can be aliased.
-prado_aliasname_invalid = Alias '{0}' contains invalid character '.'.
-
-component_property_undefined = Component property '{0}.{1}' is not defined.
-component_property_readonly = Component property '{0}.{1}' is read-only.
-component_event_undefined = Component event '{0}.{1}' is not defined.
-component_eventhandler_invalid = Component event '{0}.{1}' is attached with an invalid event handler.
-component_expression_invalid = Component '{0}' is evaluating an invalid expression '{1}' : {2}.
-component_statements_invalid = Component '{0}' is evaluating invalid PHP statements '{1}' : {2}.
-
-propertyvalue_enumvalue_invalid = Value '{0}' is a not valid enumeration value ({1}).
-
-list_index_invalid = Index '{0}' is out of range.
-list_item_inexistent = The item cannot be found in the list.
-list_data_not_iterable = Data must be either an array or an object implementing Traversable interface.
-list_readonly = {0} is read-only.
-
-map_addition_disallowed = The new item cannot be added to the map.
-map_item_unremovable = The item cannot be removed from the map.
-map_data_not_iterable = Data must be either an array or an object implementing Traversable interface.
-map_readonly = {0} is read-only.
-
-application_basepath_invalid = Application base path '{0}' does not exist or is not a directory.
-application_runtimepath_invalid = Application runtime path '{0}' does not exist or is not writable by Web server process.
-application_service_invalid = Service '{0}' must implement IService interface.
-application_service_unknown = Requested service '{0}' is not defined.
-application_service_unavailable = Service Unavailable.
-application_moduleid_duplicated = Application module ID '{0}' is not unique.
-application_runtimepath_failed = Unable to create runtime path '{0}'. Make sure the parent directory exists and is writable by the Web process.
-
-appconfig_aliaspath_invalid = Application configuration <alias id="{0}"> uses an invalid file path "{1}".
-appconfig_alias_invalid = Application configuration <alias> element must have an "id" attribute and a "path" attribute.
-appconfig_alias_redefined = Application configuration <alias id="{0}"> cannot be redefined.
-appconfig_using_invalid = Application configuration <using> element must have a "namespace" attribute.
-appconfig_moduleid_required = Application configuration <module> element must have an "id" attribute.
-appconfig_moduletype_required = Application configuration <module id="{0}"> must have a "class" attribute.
-appconfig_serviceid_required = Application configuration <service> element must have an "id" attribute.
-appconfig_servicetype_required = Application configuration <service id="{0}"> must have a "class" attribute.
-appconfig_parameterid_required = Application configuration <parameter> element must have an "id" attribute.
-
-securitymanager_validationkey_invalid = TSecurityManager.ValidationKey must not be empty.
-securitymanager_encryptionkey_invalid = TSecurityManager.EncryptionKey must not be empty.
-securitymanager_mcryptextension_required = Mcrypt PHP extension is required in order to use TSecurityManager's encryption feature.
-
-uri_format_invalid = '{0}' is not a valid URI.
-
-httpresponse_bufferoutput_unchangeable = THttpResponse.BufferOutput cannot be modified after THttpResponse is initialized.
-httpresponse_file_inexistent = THttpResponse cannot send file '{0}'. The file does not exist.
-
-httpsession_sessionid_unchangeable = THttpSession.SessionID cannot be modified after the session is started.
-httpsession_sessionname_unchangeable = THttpSession.SessionName cannot be modified after the session is started.
-httpsession_sessionname_invalid = THttpSession.SessionName must contain alphanumeric characters only.
-httpsession_savepath_unchangeable = THttpSession.SavePath cannot be modified after the session is started.
-httpsession_savepath_invalid = THttpSession.SavePath '{0}' is invalid.
-httpsession_storage_unchangeable = THttpSession.Storage cannot be modified after the session is started.
-httpsession_cookiemode_unchangeable = THttpSession.CookieMode cannot be modified after the session is started.
-httpsession_autostart_unchangeable = THttpSession.AutoStart cannot be modified after the session module is initialized.
-httpsession_gcprobability_unchangeable = THttpSession.GCProbability cannot be modified after the session is started.
-httpsession_gcprobability_invalid = THttpSession.GCProbability must be an integer between 0 and 100.
-httpsession_transid_unchangeable = THttpSession.UseTransparentSessionID cannot be modified after the session is started.
-httpsession_maxlifetime_unchangeable = THttpSession.Timeout cannot be modified after the session is started.
-
-assetmanager_basepath_invalid = TAssetManager.BasePath '{0}' is invalid. Make sure it is in namespace form and points to a directory writable by the Web server process.
-assetmanager_basepath_unchangeable = TAssetManager.BasePath cannot be modified after the module is initialized.
-assetmanager_baseurl_unchangeable = TAssetManager.BaseUrl cannot be modified after the module is initialized.
-assetmanager_filepath_invalid = TAssetManager is publishing an invalid file '{0}'.
-assetmanager_tarchecksum_invalid = TAssetManager is publishing a tar file with invalid checksum '{0}'.
-assetmanager_tarfile_invalid = TAssetManager is publishing an invalid tar file '{0}'.
-
-sqlitecache_extension_required = TSqliteCache requires SQLite PHP extension.
-sqlitecache_dbfile_required = TSqliteCache.DbFile is required.
-sqlitecache_connection_failed = TSqliteCache database connection failed. {0}.
-sqlitecache_table_creation_failed = TSqliteCache failed to create cache database. {0}.
-sqlitecache_dbfile_unchangeable = TSqliteCache.DbFile cannot be modified after the module is initialized.
-sqlitecache_dbfile_invalid = TSqliteCache.DbFile is invalid. Make sure it is in a proper namespace format.
-
-memcache_extension_required = TMemCache requires memcache PHP extension.
-memcache_connection_failed = TMemCache failed to connect to memcache server {0}:{1}.
-memcache_host_unchangeable = TMemCache.Host cannot be modified after the module is initialized.
-memcache_port_unchangeable = TMemCache.Port cannot be modified after the module is initialized.
-
-apccache_extension_required = TAPCCache requires APC PHP extension.
-apccache_add_unsupported = TAPCCache.add() is not supported.
-apccache_replace_unsupported = TAPCCache.replace() is not supported.
-
-errorhandler_errortemplatepath_invalid = TErrorHandler.ErrorTemplatePath '{0}' is invalid. Make sure it is in namespace form and points to a valid directory containing error template files.
-
-pageservice_page_unknown = Page '{0}' Not Found
-pageservice_pageclass_unknown = Page class '{0}' is unknown.
-pageservice_basepath_invalid = TPageService.BasePath '{0}' is not a valid directory.
-pageservice_page_required = Page Name Required
-pageservice_defaultpage_unchangeable = TPageService.DefaultPage cannot be modified after the service is initialized.
-pageservice_basepath_unchangeable = TPageService.BasePath cannot be modified after the service is initialized.
-
-pageserviceconf_file_invalid = Unable to open page directory configuration file '{0}'.
-pageserviceconf_aliaspath_invalid = <alias id="{0}"> uses an invalid file path "{1}" in page directory configuration file '{2}'.
-pageserviceconf_alias_invalid = <alias> element must have an "id" attribute and a "path" attribute in page directory configuration file '{0}'.
-pageserviceconf_using_invalid = <using> element must have a "namespace" attribute in page directory configuration file '{0}'.
-pageserviceconf_module_invalid = <module> element must have an "id" attribute in page directory configuration file '{0}'.
-pageserviceconf_moduletype_required = <module id="{0}"> must have a "class" attribute in page directory configuration file '{1}'.
-pageserviceconf_parameter_invalid = <parameter> element must have an "id" attribute in page directory configuration file '{0}'.
-pageserviceconf_page_invalid = <page> element must have an "id" attribute in page directory configuration file '{0}'.
-
-template_closingtag_unexpected = Unexpected closing tag '{0}' is found.
-template_closingtag_expected = Closing tag '{0}' is expected.
-template_directive_nonunique = Directive '<%@ ... %>' must appear at the beginning of the template and can appear at most once.
-template_comments_forbidden = Template comments are not allowed within property tags.
-template_matching_unexpected = Unexpected matching.
-template_property_unknown = {0} has no property called '{1}'.
-template_event_unknown = {0} has no event called '{1}'.
-template_property_readonly = {0} has a read-only property '{1}'.
-template_event_forbidden = {0} is a non-control component. No handler can be attached to its event '{1}' in a template.
-template_databind_forbidden = {0} is a non-control component. Expressions cannot be bound to its property '{1}'.
-template_component_required = '{0}' is not a component. Only components can appear in a template.
-template_format_invalid = Error in {0} (line {1}) : {2}
-template_format_invalid2 = Error at line {0} of the following template: {1} {2}
-template_property_duplicated = Property {0} is configured twice or more.
-template_eventhandler_invalid = {0}.{1} can only accept a static string.
-template_controlid_invalid = {0}.ID can only accept a static text string.
-template_controlskinid_invalid = {0}.SkinID can only accept a static text string.
-template_content_unexpected = Unexpected content is encountered when instantiating template: {0}.
-
-xmldocument_file_read_failed = TXmlDocument is unable to read file '{0}'.
-xmldocument_file_write_failed = TXmlDocument is unable to write file '{0}'.
-
-xmlelementlist_xmlelement_required = TXmlElementList can only accept TXmlElement objects.
-
-authorizationrule_action_invalid = TAuthorizationRule.Action can only take 'allow' or 'deny' as the value.
-authorizationrule_verb_invalid = TAuthorizationRule.Verb can only take 'get' or 'post' as the value.
-
-authorizationrulecollection_authorizationrule_required = TAuthorizationRuleCollection can only accept TAuthorizationRule objects.
-
-usermanager_userfile_invalid = TUserManager.UserFile '{0}' is not a valid file.
-usermanager_userfile_unchangeable = TUserManager.UserFile cannot be modified. The user module has been initialized already.
-
-authmanager_usermanager_required = TAuthManager.UserManager must be assigned a value.
-authmanager_usermanager_inexistent = TAuthManager.UserManager '{0}' does not refer to an ID of application module.
-authmanager_usermanager_invalid = TAuthManager.UserManager '{0}' does not refer to a valid TUserManager application module.
-authmanager_usermanager_unchangeable = TAuthManager.UserManager cannot be modified after the module is initialized.
-authmanager_session_required = TAuthManager requires a session application module.
-
-thememanager_basepath_invalid = TThemeManager.BasePath '{0}' is not a valid directory.
-thememanager_basepath_unchangeable = TThemeManager.BasePath cannot be modified after the module is initialized.
-
-theme_baseurl_required = TThemeManager.BasePath is required. By default, a directory named 'themes' under the directory containing the application entry script is assumed.
-theme_path_inexistent = Theme path '{0}' does not exist.
-theme_control_nested = Skin for control type '{0}' in theme '{1}' cannot be within another skin.
-theme_skinid_duplicated = SkinID '{0}.{1}' is duplicated in theme '{2}'.
-theme_databind_forbidden = Databind cannot be used in theme '{0}' for control skin '{1}.{2}' about property '{3}'.
-theme_property_readonly = Skin is being applied to a read-only control property '{0}.{1}'.
-theme_property_undefined = Skin is being applied to an inexistent control property '{0}.{1}'.
-
-control_object_reregistered = Duplicated object ID '{0}' found.
-control_id_invalid = {0}.ID '{1}' is invalid. Only alphanumeric and underline characters are allowed. The first character must be an alphabetic or underline character.
-control_skinid_unchangeable = {0}.SkinID cannot be modified after a skin has been applied to the control or the child controls have been created.
-control_enabletheming_unchangeable = {0}.EnableTheming cannot be modified after the child controls have been created.
-control_stylesheet_applied = StyleSheet skin has already been applied to {0}.
-control_id_nonunique = {0}.ID '{1}' is not unique among all controls under the same naming container.
-
-templatecontrol_mastercontrol_invalid = Master control must be of type TTemplateControl or a child class.
-templatecontrol_contentid_duplicated = TContent ID '{0}' is duplicated.
-templatecontrol_placeholderid_duplicated= TContentPlaceHolder ID '{0}' is duplicated.
-templatecontrol_directive_invalid = {0}.{1} can only accept a static text string through a template directive.
-templatecontrol_placeholder_inexistent = TContent '{0}' does not have a matching TContentPlaceHolder.
-
-page_form_duplicated = A page can contain at most one TForm. Use regular HTML form tags for the rest forms.
-page_isvalid_unknown = TPage.IsValid has not been evaluated yet.
-page_postbackcontrol_invalid = Unable to determine postback control '{0}'.
-page_control_outofform = {0} '{1}' must be enclosed within TForm.
-page_head_duplicated = A page can contain at most one THead.
-page_statepersister_invalid = Page state persister must implement IPageStatePersister interface.
-
-csmanager_pradoscript_invalid = Unknown Prado script library name '{0}'.
-
-contentplaceholder_id_required = TContentPlaceHolder must have an ID.
-
-content_id_required = TContent must have an ID.
-
-controlcollection_control_required = TControlList can only accept strings or TControl objects.
-
-webcontrol_accesskey_invalid = {0}.AccessKey '{1}' is invalid. It must be a single character only.
-webcontrol_style_invalid = {0}.Style must take string value only.
-
-listcontrol_selection_invalid = {0} has an invalid selection that is set before performing databinding.
-listcontrol_selectedindex_invalid = {0}.SelectedIndex has an invalid value {1}.
-listcontrol_selectedvalue_invalid = {0}.SelectedValue has an invalid value '{1}'.
-listcontrol_expression_invalid = {0} is evaluating an invalid expression '{1}' : {2}
-
-label_associatedcontrol_invalid = TLabel.AssociatedControl '{0}' cannot be found.
-
-hiddenfield_focus_unsupported = THiddenField does not support setting input focus.
-hiddenfield_theming_unsupported = THiddenField does not support theming.
-hiddenfield_skinid_unsupported = THiddenField does not support control skin.
-
-panel_defaultbutton_invalid = TPanel.DefaultButton '{0}' does not refer to an existing button control.
-
-tablestyle_cellpadding_invalid = TTableStyle.CellPadding must take an integer equal to or greater than -1.
-tablestyle_cellspacing_invalid = TTableStyle.CellSpacing must take an integer equal to or greater than -1.
-
-pagestatepersister_pagestate_corrupted = Page state is corrupted.
-
-sessionpagestatepersister_pagestate_corrupted = Page state is corrupted.
-sessionpagestatepersister_historysize_invalid = TSessionPageStatePersister.History must be an integer greater than 0.
-
-listitemcollection_item_invalid = TListItemCollection can only take strings or TListItem objects.
-
-dropdownlist_selectedindices_unsupported= TDropDownList.SelectedIndices is read-only.
-
-bulletedlist_autopostback_unsupported = TBulletedList.AutoPostBack is read-only.
-bulletedlist_selectedindex_unsupported = TBulletedList.SelectedIndex is read-only.
-bulletedlist_selectedindices_unsupported= TBulletedList.SelectedIndices is read-only.
-bulletedlist_selectedvalue_unsupported = TBulletedList.SelectedValue is read-only.
-
-radiobuttonlist_selectedindices_unsupported = TRadioButtonList.SelectedIndices is read-only.
-
-logrouter_configfile_invalid = TLogRouter.ConfigFile '{0}' does not exist.
-logrouter_routeclass_required = Class attribute is required in <route> configuration.
-logrouter_routetype_required = Log route must be an instance of TLogRoute or its derived class.
-
-filelogroute_logpath_invalid = TFileLogRoute.LogPath '{0}' must be a directory in namespace format and must be writable by the Web server process.
-filelogroute_maxfilesize_invalid = TFileLogRoute.MaxFileSize must be greater than 0.
-filelogroute_maxlogfiles_invalid = TFileLogRoute.MaxLogFiles must be greater than 0.
-
-emaillogroute_sentfrom_required = TEmailLogRoute.SentFrom cannot be empty.
-
-repeatinfo_repeatcolumns_invalid = TRepeatInfo.RepeatColumns must be no less than 0.
-
-basevalidator_controltovalidate_invalid = {0}.ControlToValidate is empty or contains an invalid control ID path.
-basevalidator_validatable_required = {0}.ControlToValidate must point to a control implementing IValidatable interface.
-basevalidator_forcontrol_unsupported = {0}.ForControl is not supported.
-
-comparevalidator_controltocompare_invalid = TCompareValidator.ControlToCompare contains an invalid control ID path.
-
-listcontrolvalidator_invalid_control = {0}.ControlToValidate contains an invalid TListControl ID path, "{1}" is a {2}.
-
-repeater_template_required = TRepeater.{0} requires a template instance implementing ITemplate interface.
-datalist_template_required = TDataList.{0} requires a template instance implementing ITemplate interface.
-templatecolumn_template_required = TTemplateColumn.{0} requires a template instance implementing ITemplate interface.
-
-datagrid_currentpageindex_invalid = TDataGrid.CurrentPageIndex must be no less than 0.
-datagrid_pagesize_invalid = TDataGrid.PageSize must be greater than 0.
-datagrid_virtualitemcount_invalid = TDataGrid.VirtualItemCount must be no less than 0.
-
-datagridpagerstyle_pagebuttoncount_invalid = TDataGridPagerStyle.PageButtonCount must be greater than 0.
-
-datafieldaccessor_data_invalid = TDataFieldAccessor is trying to evaluate a field value of an invalid data. Make sure the data is an array, TMap, TList, or object that contains the specified field '{0}'.
-datafieldaccessor_datafield_invalid = TDataFieldAccessor is trying to evaluate data value of an unknown field '{0}'.
-
-repeateritemcollection_repeateritem_required = TRepeaterItemCollection can only accept TRepeaterItem objects.
-
-datagriditemcollection_datagriditem_required = TDataGridItemCollection can only accept TDataGridItem objects.
-
-datagridcolumncollection_datagridcolumn_required = TDataGridColumnCollection can only accept TDataGridColumn objects.
-
-datalistitemcollection_datalistitem_required = TDataListItemCollection can only accept TDataListItem objects.
-
-tablerowcollection_tablerow_required = TTableRowCollection can only accept TTableRow objects.
-
-tablecellcollection_tablerow_required = TTableCellCollection can only accept TTableCell objects.
-
-multiview_view_required = TMultiView can only accept TView as child.
-multiview_activeviewindex_invalid = TMultiView.ActiveViewIndex has an invalid index '{0}'.
-multiview_view_inexistent = TMultiView cannot find the specified view.
-multiview_viewid_invalid = TMultiView cannot find the view '{0}' to switch to.
-
-viewcollection_view_required = TViewCollection can only accept TView as its element.
-
-view_visible_readonly = TView.Visible is read-only. Use TView.Active to toggle its visibility.
-
-wizard_step_invalid = The step to be activated cannot be found in wizard step collection.
-wizard_command_invalid = Invalid wizard navigation command '{0}'.
-
-table_tablesection_outoforder = TTable table sections must be in the order of: Header, Body and Footer.
-
-completewizardstep_steptype_readonly = TCompleteWizardStep.StepType is read-only.
-
-wizardstepcollection_wizardstep_required = TWizardStepCollection can only accept objects of TWizardStep or its derived classes.
-
-texthighlighter_stylesheet_invalid = Unable to find the stylesheet file for TTextHighlighter.
-
-hotspotcollection_hotspot_required = THotSpotCollection can only accept instance of THotSpot or its derived classes.
-
-htmlarea_textmode_readonly = THtmlArea.TextMode is read-only.
-htmlarea_tarfile_invalid = THtmlArea is unable to locate the TinyMCE tar file.
-
-parametermodule_parameterfile_unchangeable = TParameterModule.ParameterFile is not changeable because the module is already initialized.
-parametermodule_parameterfile_invalid = TParameterModule.ParameterFile '{0}' is invalid. Make sure it is in namespace format and the file extension is '.xml'.
-parametermodule_parameterid_required = Parameter element must have 'id' attribute.
-
-datagridcolumn_expression_invalid = {0} is evaluating an invalid expression '{1}' : {2}
-
-outputcache_duration_invalid = {0}.Duration must be an integer no less than 0.
-
-stack_data_not_iterable = TStack can only fetch data from an array or a traversable object.
-stack_empty = TStack is empty.
-
-queue_data_not_iterable = TQueue can only fetch data from an array or a traversable object.
-queue_empty = TQueue is empty.
-
-callback_not_support_no_priority_state_update = Callback request does not support unprioritized pagestate update.
-
-xmltransform_xslextension_required = TXmlTransform require the PHP's XSL extension
-xmltransform_transformpath_invalid = TransformPath '{0}' is invalid.
-xmltransform_documentpath_invalid = DocumentPath '{0}' is invalid.
-xmltransform_transform_required = Either TransformContent or TransformPath property must be set.
+prado_application_singleton_required = Prado.Application must only be set once. +prado_component_unknown = Unknown component type '{0}'. +prado_using_invalid = '{0}' is not a valid namespace to be used. Make sure '.*' is appended if you want to use a namespace referring to a directory. +prado_alias_redefined = Alias '{0}' cannot be redefined. +prado_alias_invalid = Alias '{0}' refers to an invalid path '{1}'. Only existing directories can be aliased. +prado_aliasname_invalid = Alias '{0}' contains invalid character '.'. + +component_property_undefined = Component property '{0}.{1}' is not defined. +component_property_readonly = Component property '{0}.{1}' is read-only. +component_event_undefined = Component event '{0}.{1}' is not defined. +component_eventhandler_invalid = Component event '{0}.{1}' is attached with an invalid event handler. +component_expression_invalid = Component '{0}' is evaluating an invalid expression '{1}' : {2}. +component_statements_invalid = Component '{0}' is evaluating invalid PHP statements '{1}' : {2}. + +propertyvalue_enumvalue_invalid = Value '{0}' is a not valid enumeration value ({1}). + +list_index_invalid = Index '{0}' is out of range. +list_item_inexistent = The item cannot be found in the list. +list_data_not_iterable = Data must be either an array or an object implementing Traversable interface. +list_readonly = {0} is read-only. + +map_addition_disallowed = The new item cannot be added to the map. +map_item_unremovable = The item cannot be removed from the map. +map_data_not_iterable = Data must be either an array or an object implementing Traversable interface. +map_readonly = {0} is read-only. + +application_basepath_invalid = Application base path '{0}' does not exist or is not a directory. +application_runtimepath_invalid = Application runtime path '{0}' does not exist or is not writable by Web server process. +application_service_invalid = Service '{0}' must implement IService interface. +application_service_unknown = Requested service '{0}' is not defined. +application_service_unavailable = Service Unavailable. +application_moduleid_duplicated = Application module ID '{0}' is not unique. +application_runtimepath_failed = Unable to create runtime path '{0}'. Make sure the parent directory exists and is writable by the Web process. + +appconfig_aliaspath_invalid = Application configuration <alias id="{0}"> uses an invalid file path "{1}". +appconfig_alias_invalid = Application configuration <alias> element must have an "id" attribute and a "path" attribute. +appconfig_alias_redefined = Application configuration <alias id="{0}"> cannot be redefined. +appconfig_using_invalid = Application configuration <using> element must have a "namespace" attribute. +appconfig_moduleid_required = Application configuration <module> element must have an "id" attribute. +appconfig_moduletype_required = Application configuration <module id="{0}"> must have a "class" attribute. +appconfig_serviceid_required = Application configuration <service> element must have an "id" attribute. +appconfig_servicetype_required = Application configuration <service id="{0}"> must have a "class" attribute. +appconfig_parameterid_required = Application configuration <parameter> element must have an "id" attribute. + +securitymanager_validationkey_invalid = TSecurityManager.ValidationKey must not be empty. +securitymanager_encryptionkey_invalid = TSecurityManager.EncryptionKey must not be empty. +securitymanager_mcryptextension_required = Mcrypt PHP extension is required in order to use TSecurityManager's encryption feature. + +uri_format_invalid = '{0}' is not a valid URI. + +httpresponse_bufferoutput_unchangeable = THttpResponse.BufferOutput cannot be modified after THttpResponse is initialized. +httpresponse_file_inexistent = THttpResponse cannot send file '{0}'. The file does not exist. + +httpsession_sessionid_unchangeable = THttpSession.SessionID cannot be modified after the session is started. +httpsession_sessionname_unchangeable = THttpSession.SessionName cannot be modified after the session is started. +httpsession_sessionname_invalid = THttpSession.SessionName must contain alphanumeric characters only. +httpsession_savepath_unchangeable = THttpSession.SavePath cannot be modified after the session is started. +httpsession_savepath_invalid = THttpSession.SavePath '{0}' is invalid. +httpsession_storage_unchangeable = THttpSession.Storage cannot be modified after the session is started. +httpsession_cookiemode_unchangeable = THttpSession.CookieMode cannot be modified after the session is started. +httpsession_autostart_unchangeable = THttpSession.AutoStart cannot be modified after the session module is initialized. +httpsession_gcprobability_unchangeable = THttpSession.GCProbability cannot be modified after the session is started. +httpsession_gcprobability_invalid = THttpSession.GCProbability must be an integer between 0 and 100. +httpsession_transid_unchangeable = THttpSession.UseTransparentSessionID cannot be modified after the session is started. +httpsession_maxlifetime_unchangeable = THttpSession.Timeout cannot be modified after the session is started. + +assetmanager_basepath_invalid = TAssetManager.BasePath '{0}' is invalid. Make sure it is in namespace form and points to a directory writable by the Web server process. +assetmanager_basepath_unchangeable = TAssetManager.BasePath cannot be modified after the module is initialized. +assetmanager_baseurl_unchangeable = TAssetManager.BaseUrl cannot be modified after the module is initialized. +assetmanager_filepath_invalid = TAssetManager is publishing an invalid file '{0}'. +assetmanager_tarchecksum_invalid = TAssetManager is publishing a tar file with invalid checksum '{0}'. +assetmanager_tarfile_invalid = TAssetManager is publishing an invalid tar file '{0}'. + +sqlitecache_extension_required = TSqliteCache requires SQLite PHP extension. +sqlitecache_dbfile_required = TSqliteCache.DbFile is required. +sqlitecache_connection_failed = TSqliteCache database connection failed. {0}. +sqlitecache_table_creation_failed = TSqliteCache failed to create cache database. {0}. +sqlitecache_dbfile_unchangeable = TSqliteCache.DbFile cannot be modified after the module is initialized. +sqlitecache_dbfile_invalid = TSqliteCache.DbFile is invalid. Make sure it is in a proper namespace format. + +memcache_extension_required = TMemCache requires memcache PHP extension. +memcache_connection_failed = TMemCache failed to connect to memcache server {0}:{1}. +memcache_host_unchangeable = TMemCache.Host cannot be modified after the module is initialized. +memcache_port_unchangeable = TMemCache.Port cannot be modified after the module is initialized. + +apccache_extension_required = TAPCCache requires APC PHP extension. +apccache_add_unsupported = TAPCCache.add() is not supported. +apccache_replace_unsupported = TAPCCache.replace() is not supported. + +errorhandler_errortemplatepath_invalid = TErrorHandler.ErrorTemplatePath '{0}' is invalid. Make sure it is in namespace form and points to a valid directory containing error template files. + +pageservice_page_unknown = Page '{0}' Not Found +pageservice_pageclass_unknown = Page class '{0}' is unknown. +pageservice_basepath_invalid = TPageService.BasePath '{0}' is not a valid directory. +pageservice_page_required = Page Name Required +pageservice_defaultpage_unchangeable = TPageService.DefaultPage cannot be modified after the service is initialized. +pageservice_basepath_unchangeable = TPageService.BasePath cannot be modified after the service is initialized. + +pageserviceconf_file_invalid = Unable to open page directory configuration file '{0}'. +pageserviceconf_aliaspath_invalid = <alias id="{0}"> uses an invalid file path "{1}" in page directory configuration file '{2}'. +pageserviceconf_alias_invalid = <alias> element must have an "id" attribute and a "path" attribute in page directory configuration file '{0}'. +pageserviceconf_using_invalid = <using> element must have a "namespace" attribute in page directory configuration file '{0}'. +pageserviceconf_module_invalid = <module> element must have an "id" attribute in page directory configuration file '{0}'. +pageserviceconf_moduletype_required = <module id="{0}"> must have a "class" attribute in page directory configuration file '{1}'. +pageserviceconf_parameter_invalid = <parameter> element must have an "id" attribute in page directory configuration file '{0}'. +pageserviceconf_page_invalid = <page> element must have an "id" attribute in page directory configuration file '{0}'. + +template_closingtag_unexpected = Unexpected closing tag '{0}' is found. +template_closingtag_expected = Closing tag '{0}' is expected. +template_directive_nonunique = Directive '<%@ ... %>' must appear at the beginning of the template and can appear at most once. +template_comments_forbidden = Template comments are not allowed within property tags. +template_matching_unexpected = Unexpected matching. +template_property_unknown = {0} has no property called '{1}'. +template_event_unknown = {0} has no event called '{1}'. +template_property_readonly = {0} has a read-only property '{1}'. +template_event_forbidden = {0} is a non-control component. No handler can be attached to its event '{1}' in a template. +template_databind_forbidden = {0} is a non-control component. Expressions cannot be bound to its property '{1}'. +template_component_required = '{0}' is not a component. Only components can appear in a template. +template_format_invalid = Error in {0} (line {1}) : {2} +template_format_invalid2 = Error at line {0} of the following template: {1} {2} +template_property_duplicated = Property {0} is configured twice or more. +template_eventhandler_invalid = {0}.{1} can only accept a static string. +template_controlid_invalid = {0}.ID can only accept a static text string. +template_controlskinid_invalid = {0}.SkinID can only accept a static text string. +template_content_unexpected = Unexpected content is encountered when instantiating template: {0}. + +xmldocument_file_read_failed = TXmlDocument is unable to read file '{0}'. +xmldocument_file_write_failed = TXmlDocument is unable to write file '{0}'. + +xmlelementlist_xmlelement_required = TXmlElementList can only accept TXmlElement objects. + +authorizationrule_action_invalid = TAuthorizationRule.Action can only take 'allow' or 'deny' as the value. +authorizationrule_verb_invalid = TAuthorizationRule.Verb can only take 'get' or 'post' as the value. + +authorizationrulecollection_authorizationrule_required = TAuthorizationRuleCollection can only accept TAuthorizationRule objects. + +usermanager_userfile_invalid = TUserManager.UserFile '{0}' is not a valid file. +usermanager_userfile_unchangeable = TUserManager.UserFile cannot be modified. The user module has been initialized already. + +authmanager_usermanager_required = TAuthManager.UserManager must be assigned a value. +authmanager_usermanager_inexistent = TAuthManager.UserManager '{0}' does not refer to an ID of application module. +authmanager_usermanager_invalid = TAuthManager.UserManager '{0}' does not refer to a valid TUserManager application module. +authmanager_usermanager_unchangeable = TAuthManager.UserManager cannot be modified after the module is initialized. +authmanager_session_required = TAuthManager requires a session application module. + +thememanager_basepath_invalid = TThemeManager.BasePath '{0}' is not a valid directory. +thememanager_basepath_unchangeable = TThemeManager.BasePath cannot be modified after the module is initialized. + +theme_baseurl_required = TThemeManager.BasePath is required. By default, a directory named 'themes' under the directory containing the application entry script is assumed. +theme_path_inexistent = Theme path '{0}' does not exist. +theme_control_nested = Skin for control type '{0}' in theme '{1}' cannot be within another skin. +theme_skinid_duplicated = SkinID '{0}.{1}' is duplicated in theme '{2}'. +theme_databind_forbidden = Databind cannot be used in theme '{0}' for control skin '{1}.{2}' about property '{3}'. +theme_property_readonly = Skin is being applied to a read-only control property '{0}.{1}'. +theme_property_undefined = Skin is being applied to an inexistent control property '{0}.{1}'. + +control_object_reregistered = Duplicated object ID '{0}' found. +control_id_invalid = {0}.ID '{1}' is invalid. Only alphanumeric and underline characters are allowed. The first character must be an alphabetic or underline character. +control_skinid_unchangeable = {0}.SkinID cannot be modified after a skin has been applied to the control or the child controls have been created. +control_enabletheming_unchangeable = {0}.EnableTheming cannot be modified after the child controls have been created. +control_stylesheet_applied = StyleSheet skin has already been applied to {0}. +control_id_nonunique = {0}.ID '{1}' is not unique among all controls under the same naming container. + +templatecontrol_mastercontrol_invalid = Master control must be of type TTemplateControl or a child class. +templatecontrol_contentid_duplicated = TContent ID '{0}' is duplicated. +templatecontrol_placeholderid_duplicated= TContentPlaceHolder ID '{0}' is duplicated. +templatecontrol_directive_invalid = {0}.{1} can only accept a static text string through a template directive. +templatecontrol_placeholder_inexistent = TContent '{0}' does not have a matching TContentPlaceHolder. + +page_form_duplicated = A page can contain at most one TForm. Use regular HTML form tags for the rest forms. +page_isvalid_unknown = TPage.IsValid has not been evaluated yet. +page_postbackcontrol_invalid = Unable to determine postback control '{0}'. +page_control_outofform = {0} '{1}' must be enclosed within TForm. +page_head_duplicated = A page can contain at most one THead. +page_statepersister_invalid = Page state persister must implement IPageStatePersister interface. + +csmanager_pradoscript_invalid = Unknown Prado script library name '{0}'. + +contentplaceholder_id_required = TContentPlaceHolder must have an ID. + +content_id_required = TContent must have an ID. + +controlcollection_control_required = TControlList can only accept strings or TControl objects. + +webcontrol_accesskey_invalid = {0}.AccessKey '{1}' is invalid. It must be a single character only. +webcontrol_style_invalid = {0}.Style must take string value only. + +listcontrol_selection_invalid = {0} has an invalid selection that is set before performing databinding. +listcontrol_selectedindex_invalid = {0}.SelectedIndex has an invalid value {1}. +listcontrol_selectedvalue_invalid = {0}.SelectedValue has an invalid value '{1}'. +listcontrol_expression_invalid = {0} is evaluating an invalid expression '{1}' : {2} + +label_associatedcontrol_invalid = TLabel.AssociatedControl '{0}' cannot be found. + +hiddenfield_focus_unsupported = THiddenField does not support setting input focus. +hiddenfield_theming_unsupported = THiddenField does not support theming. +hiddenfield_skinid_unsupported = THiddenField does not support control skin. + +panel_defaultbutton_invalid = TPanel.DefaultButton '{0}' does not refer to an existing button control. + +tablestyle_cellpadding_invalid = TTableStyle.CellPadding must take an integer equal to or greater than -1. +tablestyle_cellspacing_invalid = TTableStyle.CellSpacing must take an integer equal to or greater than -1. + +pagestatepersister_pagestate_corrupted = Page state is corrupted. + +sessionpagestatepersister_pagestate_corrupted = Page state is corrupted. +sessionpagestatepersister_historysize_invalid = TSessionPageStatePersister.History must be an integer greater than 0. + +listitemcollection_item_invalid = TListItemCollection can only take strings or TListItem objects. + +dropdownlist_selectedindices_unsupported= TDropDownList.SelectedIndices is read-only. + +bulletedlist_autopostback_unsupported = TBulletedList.AutoPostBack is read-only. +bulletedlist_selectedindex_unsupported = TBulletedList.SelectedIndex is read-only. +bulletedlist_selectedindices_unsupported= TBulletedList.SelectedIndices is read-only. +bulletedlist_selectedvalue_unsupported = TBulletedList.SelectedValue is read-only. + +radiobuttonlist_selectedindices_unsupported = TRadioButtonList.SelectedIndices is read-only. + +logrouter_configfile_invalid = TLogRouter.ConfigFile '{0}' does not exist. +logrouter_routeclass_required = Class attribute is required in <route> configuration. +logrouter_routetype_required = Log route must be an instance of TLogRoute or its derived class. + +filelogroute_logpath_invalid = TFileLogRoute.LogPath '{0}' must be a directory in namespace format and must be writable by the Web server process. +filelogroute_maxfilesize_invalid = TFileLogRoute.MaxFileSize must be greater than 0. +filelogroute_maxlogfiles_invalid = TFileLogRoute.MaxLogFiles must be greater than 0. + +emaillogroute_sentfrom_required = TEmailLogRoute.SentFrom cannot be empty. + +repeatinfo_repeatcolumns_invalid = TRepeatInfo.RepeatColumns must be no less than 0. + +basevalidator_controltovalidate_invalid = {0}.ControlToValidate is empty or contains an invalid control ID path. +basevalidator_validatable_required = {0}.ControlToValidate must point to a control implementing IValidatable interface. +basevalidator_forcontrol_unsupported = {0}.ForControl is not supported. + +comparevalidator_controltocompare_invalid = TCompareValidator.ControlToCompare contains an invalid control ID path. + +listcontrolvalidator_invalid_control = {0}.ControlToValidate contains an invalid TListControl ID path, "{1}" is a {2}. + +repeater_template_required = TRepeater.{0} requires a template instance implementing ITemplate interface. +datalist_template_required = TDataList.{0} requires a template instance implementing ITemplate interface. +templatecolumn_template_required = TTemplateColumn.{0} requires a template instance implementing ITemplate interface. + +datagrid_currentpageindex_invalid = TDataGrid.CurrentPageIndex must be no less than 0. +datagrid_pagesize_invalid = TDataGrid.PageSize must be greater than 0. +datagrid_virtualitemcount_invalid = TDataGrid.VirtualItemCount must be no less than 0. + +datagridpagerstyle_pagebuttoncount_invalid = TDataGridPagerStyle.PageButtonCount must be greater than 0. + +datafieldaccessor_data_invalid = TDataFieldAccessor is trying to evaluate a field value of an invalid data. Make sure the data is an array, TMap, TList, or object that contains the specified field '{0}'. +datafieldaccessor_datafield_invalid = TDataFieldAccessor is trying to evaluate data value of an unknown field '{0}'. + +repeateritemcollection_repeateritem_required = TRepeaterItemCollection can only accept TRepeaterItem objects. + +datagriditemcollection_datagriditem_required = TDataGridItemCollection can only accept TDataGridItem objects. + +datagridcolumncollection_datagridcolumn_required = TDataGridColumnCollection can only accept TDataGridColumn objects. + +datalistitemcollection_datalistitem_required = TDataListItemCollection can only accept TDataListItem objects. + +tablerowcollection_tablerow_required = TTableRowCollection can only accept TTableRow objects. + +tablecellcollection_tablerow_required = TTableCellCollection can only accept TTableCell objects. + +multiview_view_required = TMultiView can only accept TView as child. +multiview_activeviewindex_invalid = TMultiView.ActiveViewIndex has an invalid index '{0}'. +multiview_view_inexistent = TMultiView cannot find the specified view. +multiview_viewid_invalid = TMultiView cannot find the view '{0}' to switch to. + +viewcollection_view_required = TViewCollection can only accept TView as its element. + +view_visible_readonly = TView.Visible is read-only. Use TView.Active to toggle its visibility. + +wizard_step_invalid = The step to be activated cannot be found in wizard step collection. +wizard_command_invalid = Invalid wizard navigation command '{0}'. + +table_tablesection_outoforder = TTable table sections must be in the order of: Header, Body and Footer. + +completewizardstep_steptype_readonly = TCompleteWizardStep.StepType is read-only. + +wizardstepcollection_wizardstep_required = TWizardStepCollection can only accept objects of TWizardStep or its derived classes. + +texthighlighter_stylesheet_invalid = Unable to find the stylesheet file for TTextHighlighter. + +hotspotcollection_hotspot_required = THotSpotCollection can only accept instance of THotSpot or its derived classes. + +htmlarea_textmode_readonly = THtmlArea.TextMode is read-only. +htmlarea_tarfile_invalid = THtmlArea is unable to locate the TinyMCE tar file. + +parametermodule_parameterfile_unchangeable = TParameterModule.ParameterFile is not changeable because the module is already initialized. +parametermodule_parameterfile_invalid = TParameterModule.ParameterFile '{0}' is invalid. Make sure it is in namespace format and the file extension is '.xml'. +parametermodule_parameterid_required = Parameter element must have 'id' attribute. + +datagridcolumn_expression_invalid = {0} is evaluating an invalid expression '{1}' : {2} + +outputcache_duration_invalid = {0}.Duration must be an integer no less than 0. + +stack_data_not_iterable = TStack can only fetch data from an array or a traversable object. +stack_empty = TStack is empty. + +queue_data_not_iterable = TQueue can only fetch data from an array or a traversable object. +queue_empty = TQueue is empty. + +callback_not_support_no_priority_state_update = Callback request does not support unprioritized pagestate update. +callback_invalid_callback_options = '{1}' is not a valid TCallbackOptions control for Callback control '{0}'. +callback_invalid_clientside_options = Callback ClientSide property must be either a string that is the ID of a TCallbackOptions control or an instance of TCallbackClientSideOptions.======= +callback_not_support_no_priority_state_update = Callback request does not support unprioritized pagestate update. + +xmltransform_xslextension_required = TXmlTransform require the PHP's XSL extension +xmltransform_transformpath_invalid = TransformPath '{0}' is invalid. +xmltransform_documentpath_invalid = DocumentPath '{0}' is invalid. +xmltransform_transform_required = Either TransformContent or TransformPath property must be set. 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 © 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 © 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 © 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 © 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 © 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 © 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 © 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 © 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 © 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 © 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 © 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 <img> 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 © 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 <img> 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 © 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 © 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 © 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 © 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 diff --git a/tests/FunctionalTests/features/protected/pages/ActiveControls/Calculator2.page b/tests/FunctionalTests/features/protected/pages/ActiveControls/Calculator2.page index 9433154e..ca141c60 100644 --- a/tests/FunctionalTests/features/protected/pages/ActiveControls/Calculator2.page +++ b/tests/FunctionalTests/features/protected/pages/ActiveControls/Calculator2.page @@ -36,5 +36,5 @@ return false;
};
</script>
-
+
</com:TContent>
\ No newline at end of file diff --git a/tests/FunctionalTests/quickstart/Advanced/I18N.php b/tests/FunctionalTests/quickstart/Advanced/I18N.php index 6d81d3b1..5b2af8c4 100644 --- a/tests/FunctionalTests/quickstart/Advanced/I18N.php +++ b/tests/FunctionalTests/quickstart/Advanced/I18N.php @@ -6,43 +6,43 @@ class I18NTestCase extends SeleniumTestCase function test ()
{
$this->open("../../demos/quickstart/index.php?notheme=true&page=Advanced.Samples.I18N.Home&lang=en&notheme=true", "");
- $this->verifyTitle("Internationlization in PRADO", "");
+ $this->verifyTextPresent("Internationlization in PRADO", "");
$this->verifyTextPresent("46.412,42 €", "");
$this->verifyTextPresent("$12.40", "");
$this->verifyTextPresent("€100.00", "");
$this->verifyTextPresent("December 6, 2004", "");
$this->open("../../demos/quickstart/index.php?page=Advanced.Samples.I18N.Home&lang=zh&notheme=true", "");
- $this->verifyTitle("PRADO 国际化", "");
+ $this->verifyTextPresent("PRADO 国际化", "");
$this->verifyTextPresent("2004 十二月", "");
$this->verifyTextPresent("US$ 12.40", "");
$this->verifyTextPresent("46.412,42 €", "");
$this->verifyTextPresent("€100.00 ", "");
$this->open("../../demos/quickstart/index.php?page=Advanced.Samples.I18N.Home&lang=zh_TW&notheme=true", "");
- $this->verifyTitle("PRADO 國際化", "");
+ $this->verifyTextPresent("PRADO 國際化", "");
$this->verifyTextPresent("2004年12月6日", "");
$this->verifyTextPresent("US$12.40", "");
$this->verifyTextPresent("46.412,42 €", "");
$this->verifyTextPresent("€100.00", "");
$this->open("../../demos/quickstart/index.php?page=Advanced.Samples.I18N.Home&lang=de&notheme=true", "");
- $this->verifyTitle("Internationalisierung in PRADO", "");
+ $this->verifyTextPresent("Internationalisierung in PRADO", "");
$this->verifyTextPresent("6. Dezember 2004 ", "");
$this->verifyTextPresent("$ 12,40", "");
$this->verifyTextPresent("46.412,42 €", "");
$this->verifyTextPresent("€100.00", "");
$this->open("../../demos/quickstart/index.php?page=Advanced.Samples.I18N.Home&lang=es&notheme=true", "");
- $this->verifyTitle("Internationlization en PRADO", "");
+ $this->verifyTextPresent("Internationlization en PRADO", "");
$this->verifyTextPresent("6 de diciembre de 2004", "");
$this->verifyTextPresent("US$12.40", "");
$this->verifyTextPresent("46.412,42 €", "");
$this->verifyTextPresent("€100.00", "");
$this->open("../../demos/quickstart/index.php?page=Advanced.Samples.I18N.Home&lang=fr&notheme=true", "");
- $this->verifyTitle("Internationalisation dans PRADO", "");
+ $this->verifyTextPresent("Internationalisation avec PRADO", "");
$this->verifyTextPresent("6 décembre 2004", "");
$this->verifyTextPresent("12,40 $", "");
$this->verifyTextPresent("46.412,42 €", "");
$this->verifyTextPresent("€100.00", "");
$this->open("../../demos/quickstart/index.php?page=Advanced.Samples.I18N.Home&lang=pl&notheme=true", "");
- $this->verifyTitle("Internacjonalizacja w PRADO", "");
+ $this->verifyTextPresent("Internacjonalizacja w PRADO", "");
$this->verifyTextPresent("6 grudnia 2004", "");
$this->verifyTextPresent("US$ 12,40", "");
$this->verifyTextPresent("46.412,42 €", "");
diff --git a/tests/FunctionalTests/validators/protected/pages/RegularExpressionValidator.page b/tests/FunctionalTests/validators/protected/pages/RegularExpressionValidator.page index ac24cd0d..cfd7a333 100644 --- a/tests/FunctionalTests/validators/protected/pages/RegularExpressionValidator.page +++ b/tests/FunctionalTests/validators/protected/pages/RegularExpressionValidator.page @@ -14,6 +14,7 @@ ID="validator2"
ControlToValidate="text2"
ErrorMessage="Email Address!"
+ CheckMXRecord="false"
ControlCssClass="required" />
</div>
<com:TButton ID="submit1" Text="Test" />
diff --git a/tests/FunctionalTests/validators/tests/CompareValidatorTestCase.php b/tests/FunctionalTests/validators/tests/CompareValidatorTestCase.php index 5107a89f..b0f7c407 100644 --- a/tests/FunctionalTests/validators/tests/CompareValidatorTestCase.php +++ b/tests/FunctionalTests/validators/tests/CompareValidatorTestCase.php @@ -21,7 +21,6 @@ class CompareValidatorTestCase extends SeleniumTestCase $this->assertVisible("{$base}validator1");
$this->type("{$base}text2", "qwe");
- $this->assertNotVisible("{$base}validator1");
$this->clickAndWait("//input[@type='submit' and @value='Test']", "");
$this->assertNotVisible("{$base}validator1");
$this->assertNotVisible("{$base}validator2");
diff --git a/tests/UnitTests/framework/common.php b/tests/UnitTests/framework/common.php index 7df61c99..059dd142 100644 --- a/tests/UnitTests/framework/common.php +++ b/tests/UnitTests/framework/common.php @@ -10,18 +10,10 @@ require_once(SIMPLETEST_DIR.'/mock_objects.php'); require_once(SIMPLETEST_DIR.'/reporter.php');
require_once(SIMPLETEST_DIR.'/HtmlReporterWithCoverage.php');
-require_once(FRAMEWORK_DIR.'/PradoBase.php');
+require_once(FRAMEWORK_DIR.'/prado.php');
set_include_path(get_include_path().";".FRAMEWORK_DIR);
-class Prado extends PradoBase
-{
-}
-
-function __autoload($className)
-{
- require_once($className.Prado::CLASS_FILE_EXT);
-}
error_reporting(E_ALL);
restore_error_handler();
diff --git a/tests/unit/SQLMap/CacheTest.php b/tests/unit/SQLMap/CacheTest.php index 11c250a8..4fd69916 100644 --- a/tests/unit/SQLMap/CacheTest.php +++ b/tests/unit/SQLMap/CacheTest.php @@ -96,7 +96,7 @@ class CacheTest extends BaseTest protected function getCacheModel()
{
$cache = new TSqlMapCacheModel();
- $cache->setFlushInterval(5*60);
+ // $cache->setFlushInterval(5*60);
$cache->setImplementation('LRU');
$cache->initialize($this->sqlmap);
return $cache;
diff --git a/tests/unit/SQLMap/TAdodbConnectionTestCase.php b/tests/unit/SQLMap/TAdodbConnectionTestCase.php index c0d99867..1ba0ec04 100644 --- a/tests/unit/SQLMap/TAdodbConnectionTestCase.php +++ b/tests/unit/SQLMap/TAdodbConnectionTestCase.php @@ -1,11 +1,13 @@ <?php
-require_once(SQLMAP_DIR.'/TMapper.php');
+require_once dirname(__FILE__).'/../phpunit2.php';
+
+require_once(dirname(__FILE__).'/common.php');
/**
* @package System.DataAccess
*/
-class TAdodbConnectionTestCase extends UnitTestCase
+class TAdodbConnectionTestCase extends PHPUnit2_Framework_TestCase
{
protected $db_file;
@@ -15,7 +17,6 @@ class TAdodbConnectionTestCase extends UnitTestCase $this->db_file = dirname(__FILE__).'/resources/test.db';
copy($file,$this->db_file);
$provider = new TAdodb();
- $provider->importAdodbLibrary();
}
function getDsn()
diff --git a/tests/unit/SQLMap/resources/sqlmap.xml b/tests/unit/SQLMap/resources/sqlmap.xml index b15e9862..3d20321d 100644 --- a/tests/unit/SQLMap/resources/sqlmap.xml +++ b/tests/unit/SQLMap/resources/sqlmap.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?>
<sqlMapConfig>
- <provider class="TAdodbProvider">
+ <provider class="TAdodb">
<datasource driver="sqlite" host="resources/test.db" />
</provider>
diff --git a/tests/unit/SQLMap/resources/test.db b/tests/unit/SQLMap/resources/test.db Binary files differindex f939682e..b8c158cc 100644 --- a/tests/unit/SQLMap/resources/test.db +++ b/tests/unit/SQLMap/resources/test.db diff --git a/tests/unit/SQLMap/sqlite.xml b/tests/unit/SQLMap/sqlite.xml index 62ab2aa3..27febdcb 100644 --- a/tests/unit/SQLMap/sqlite.xml +++ b/tests/unit/SQLMap/sqlite.xml @@ -9,7 +9,7 @@ </settings>
<!-- ==== Database configuration ========= -->
- <provider class="TAdodbProvider" >
+ <provider class="TAdodb" >
<datasource driver="sqlite" database="sqlite/tests.db" />
</provider>
diff --git a/tests/unit/SQLMap/sqlite/tests.db b/tests/unit/SQLMap/sqlite/tests.db Binary files differindex 380ef8fa..fa66b2cc 100644 --- a/tests/unit/SQLMap/sqlite/tests.db +++ b/tests/unit/SQLMap/sqlite/tests.db |