From 1afc913c386bba8e6072c278b0eb4fd9818ab310 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 25 Apr 2006 01:27:04 +0000 Subject: Undo previous checkin (which goes int 3.0 branch and will be merged back). --- framework/Web/UI/WebControls/TBaseValidator.php | 6 +- framework/Web/UI/WebControls/TCheckBox.php | 4 +- framework/Web/UI/WebControls/TCheckBoxList.php | 12 +- framework/Web/UI/WebControls/TCompareValidator.php | 16 +- .../Web/UI/WebControls/TDataTypeValidator.php | 8 +- framework/Web/UI/WebControls/TDatePicker.php | 45 +---- framework/Web/UI/WebControls/THtmlArea.php | 2 +- .../Web/UI/WebControls/TListControlValidator.php | 214 --------------------- framework/Web/UI/WebControls/TRadioButton.php | 7 +- framework/Web/UI/WebControls/TRangeValidator.php | 41 +++- .../Web/UI/WebControls/TRequiredFieldValidator.php | 30 +-- 11 files changed, 75 insertions(+), 310 deletions(-) delete mode 100644 framework/Web/UI/WebControls/TListControlValidator.php (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index adbc85ae..c5b5e7a5 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -131,7 +131,6 @@ abstract class TBaseValidator extends TLabel implements IValidator */ protected function getClientScriptOptions() { - $control = $this->getValidationTarget(); $options['ID'] = $this->getClientID(); $options['FormID'] = $this->getPage()->getForm()->getClientID(); $options['Display'] = $this->getDisplay(); @@ -142,9 +141,8 @@ abstract class TBaseValidator extends TLabel implements IValidator $options['FocusElementID'] = $this->getFocusElementID(); } $options['ValidationGroup'] = $this->getValidationGroup(); - $options['ControlToValidate'] = $control->getClientID(); + $options['ControlToValidate'] = $this->getValidationTarget()->getClientID(); $options['ControlCssClass'] = $this->getControlCssClass(); - $options['ControlType'] = get_class($control); return $options; } @@ -165,7 +163,7 @@ abstract class TBaseValidator extends TLabel implements IValidator $manager['FormID'] = $formID; $options = TJavaScript::encode($manager); $scripts->registerPradoScript('validator'); - $scripts->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});"); + $scripts->registerEndScript($scriptKey, "new Prado.Validation({$options});"); } if($this->getEnableClientScript()) $this->registerClientScriptValidator(); diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php index 681c8748..ff7f57f7 100644 --- a/framework/Web/UI/WebControls/TCheckBox.php +++ b/framework/Web/UI/WebControls/TCheckBox.php @@ -340,7 +340,7 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl if($clientID!=='') $writer->addAttribute('id',$clientID); $writer->addAttribute('type','checkbox'); - if(($value = $this->getValueAttribute()) !== '') + if(($value=$this->getValueAttribute())!=='') $writer->addAttribute('value',$value); if(($uniqueID=$this->getUniqueID())!=='') $writer->addAttribute('name',$uniqueID); @@ -378,4 +378,4 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl } -?> +?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php index de332897..2f0cce7c 100644 --- a/framework/Web/UI/WebControls/TCheckBoxList.php +++ b/framework/Web/UI/WebControls/TCheckBoxList.php @@ -47,7 +47,7 @@ Prado::using('System.Web.UI.WebControls.TCheckBox'); * @package System.Web.UI.WebControls * @since 3.0 */ -class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler, IValidatable +class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler { private $_repeatedControl; private $_isEnabled; @@ -381,16 +381,6 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont $this->setTabIndex($tabIndex); } } - - /** - * Returns the value to be validated. - * This methid is required by IValidatable interface. - * @return mixed the value of the property to be validated. - */ - public function getValidationPropertyValue() - { - return $this->getSelectedValue(); - } } ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php index b5ebd3ab..172e472f 100644 --- a/framework/Web/UI/WebControls/TCompareValidator.php +++ b/framework/Web/UI/WebControls/TCompareValidator.php @@ -31,6 +31,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * type before the comparison operation is performed. The following value types are supported: * - Integer A 32-bit signed integer data type. * - Float A double-precision floating point number data type. + * - Currency A decimal data type that can contain currency symbols. * - Date A date data type. The format can be specified by the * {@link setDateFormat DateFormat} property * - String A string data type. @@ -55,13 +56,12 @@ class TCompareValidator extends TBaseValidator } /** - * Sets the data type (Integer, Float, Date, String) that the values being - * compared are converted to before the comparison is made. + * Sets the data type (Integer, Float, Currency, Date, String) that the values being compared are converted to before the comparison is made. * @param string the data type */ public function setDataType($value) { - $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String'); + $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); } /** @@ -188,6 +188,16 @@ class TCompareValidator extends TBaseValidator return array(intval($value1), intval($value2)); case 'Float': return array(floatval($value1), floatval($value2)); + case 'Currency': + if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value1,$matches)) + $value1=floatval($matches[0]); + else + $value1=0; + if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value2,$matches)) + $value2=floatval($matches[0]); + else + $value2=0; + return array($value1, $value2); case 'Date': $dateFormat = $this->getDateFormat(); if($dateFormat!=='') diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php index d78be7bf..81c23ce4 100644 --- a/framework/Web/UI/WebControls/TDataTypeValidator.php +++ b/framework/Web/UI/WebControls/TDataTypeValidator.php @@ -23,6 +23,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * The following data types are supported: * - Integer A 32-bit signed integer data type. * - Float A double-precision floating point number data type. + * - Currency A decimal data type that can contain currency symbols. * - Date A date data type. * - String A string data type. * For Date type, the property {@link setDateFormat DateFormat} @@ -45,13 +46,12 @@ class TDataTypeValidator extends TBaseValidator } /** - * Sets the data type (Integer, Float, Date, String) that the values being - * compared are converted to before the comparison is made. + * Sets the data type (Integer, Float, Currency, Date, String) that the values being compared are converted to before the comparison is made. * @param string the data type */ public function setDataType($value) { - $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String'); + $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); } /** @@ -85,6 +85,8 @@ class TDataTypeValidator extends TBaseValidator return preg_match('/^[-+]?[0-9]+$/',trim($value)); case 'Float': return preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value)); + case 'Currency': + return preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value)); case 'Date': $dateFormat = $this->getDateFormat(); if(strlen($dateFormat)) diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php index 02386515..c6a2345b 100644 --- a/framework/Web/UI/WebControls/TDatePicker.php +++ b/framework/Web/UI/WebControls/TDatePicker.php @@ -245,16 +245,17 @@ class TDatePicker extends TTextBox /** * @return integer current selected date from the date picker as timestamp. */ - public function getTimeStamp() + public function getDate() { - return $this->getTimeStampFromText(); + $date = $this->getDateFromText(); + return $date[0]; } /** * Sets the date for the date picker using timestamp. * @param integer time stamp for the date picker */ - public function setTimeStamp($value) + public function setDate($value) { $date = TPropertyValue::ensureInteger($value); $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', @@ -262,34 +263,6 @@ class TDatePicker extends TTextBox $this->setText($formatter->format($date)); } - /** - * @return string the date string. - */ - public function getDate() - { - return $this->getText(); - } - - /** - * @param string date string - */ - public function setDate($value) - { - $this->setText($value); - } - - /** - * Returns the value to be validated. - * This methid is required by IValidatable interface. - * @return integer the value of the property to be validated. - */ - public function getValidationPropertyValue() - { - if($this->getText() === '') - return ''; - return $this->getTimeStamp(); - } - /** * Publish the date picker Css asset files. */ @@ -423,7 +396,6 @@ class TDatePicker extends TTextBox $date = $this->getLocalizedCalendarInfo(); $options['MonthNames'] = TJavaScript::encode($date->getMonthNames(),false); - $options['AbbreviatedMonthNames'] = TJavaScript::encode($date->getAbbreviatedMonthNames(),false); $options['ShortWeekDayNames'] = TJavaScript::encode($date->getAbbreviatedDayNames(),false); return $options; @@ -467,8 +439,7 @@ class TDatePicker extends TTextBox $writer->addAttribute('class', $class); $writer->renderBeginTag('span'); - $date = @getdate($this->getTimeStampFromText()); - + $date = $this->getDateFromText(); $this->renderCalendarSelections($writer, $date); //render a hidden input field @@ -510,9 +481,9 @@ class TDatePicker extends TTextBox /** * Gets the date from the text input using TSimpleDateFormatter - * @return integer current selected date timestamp + * @return array current selected date */ - protected function getTimeStampFromText() + protected function getDateFromText() { $pattern = $this->getDateFormat(); $pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern); @@ -588,7 +559,7 @@ class TDatePicker extends TTextBox case 'MMM': case 'MM': return $info->getAbbreviatedMonthNames(); case 'M': - $array = array(); for($i=1;$i<=12;$i++) $array[$i-1] = $i; + $array = array(); for($i=1;$i<=12;$i++) $array[$i] = $i; return $array; default : return $info->getMonthNames(); } diff --git a/framework/Web/UI/WebControls/THtmlArea.php b/framework/Web/UI/WebControls/THtmlArea.php index 8e5fcd16..7e47d638 100644 --- a/framework/Web/UI/WebControls/THtmlArea.php +++ b/framework/Web/UI/WebControls/THtmlArea.php @@ -315,7 +315,7 @@ class THtmlArea extends TTextBox //default the variant to "en" if(count($variants) == 0) { - if(empty($culture)) + if($empty($culture)) return 'en'; $variants[] = strtolower($culture); } diff --git a/framework/Web/UI/WebControls/TListControlValidator.php b/framework/Web/UI/WebControls/TListControlValidator.php deleted file mode 100644 index 9264e891..00000000 --- a/framework/Web/UI/WebControls/TListControlValidator.php +++ /dev/null @@ -1,214 +0,0 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Revision: $ $Date: $ - * @package System.Web.UI.WebControls - */ - -/** - * Using TBaseValidator class - */ -Prado::using('System.Web.UI.WebControls.TBaseValidator'); - -/** - * TListControlValidator class. - * - * TListControlValidator checks the number of selection and their values - * for a TListControl that allows multiple selection. - * - * You can specify the minimum or maximum (or both) number of selections - * required using the {@link setMinSelection MinSelection} and - * {@link setMaxSelection MaxSelection} properties, respectively. In addition, - * you can specify a comma separated list of required selected values via the - * {@link setRequiredSelections RequiredSelections} property. - * - * Examples - * - At least two selections - * - * - * - * - * - * - * - * - * - * - "value1" must be selected and at least 1 other - * - * - * - * - * - * - * - * - * - * - * @author Xiang Wei Zhuo - * @version $Revision: $ $Date: $ - * @package System.Web.UI.WebControls - * @since 3.0 - */ -class TListControlValidator extends TBaseValidator -{ - /** - * @return int min number of selections - */ - function getMinSelection() - { - return $this->getViewState('MinSelection',''); - } - - /** - * @param int minimum number of selections. - */ - function setMinSelection($value) - { - $this->setViewState('MinSelection',$value,''); - } - - /** - * @return int max number of selections - */ - function getMaxSelection() - { - return $this->getViewState('MaxSelection',''); - } - - /** - * @param int max number of selections. - */ - function setMaxSelection($value) - { - $this->setViewState('MaxSelection',$value,''); - } - - /** - * Get a comma separated list of required selected values. - * @return string comma separated list of required values. - */ - function getRequiredSelections() - { - return $this->getViewState('RequiredSelections',''); - } - - /** - * Set the list of required values, using aa comma separated list. - * @param string comma separated list of required values. - */ - function setRequiredSelections($value) - { - $this->setViewState('RequiredSelections',$value,''); - } - - /** - * This method overrides the parent's implementation. - * The validation succeeds if the input component changes its data - * from the InitialValue or the input component is not given. - * @return boolean whether the validation succeeds - */ - public function evaluateIsValid() - { - $control=$this->getValidationTarget(); - - $exists = true; - list($count, $values) = $this->getSelection($control); - $required = $this->getRequiredValues(); - - //if required, check the values - if(!empty($required)) - { - if(count($values) < count($required) ) - return false; - foreach($required as $require) - $exists = $exists && in_array($require, $values); - } - - $min = $this->getMinSelection(); - $max = $this->getMaxSelection(); - - if($min !== '' && $max !=- '') - return $exists && $count >= intval($min) && $count <= intval($max); - else if($min === '' && $max !== '') - return $exists && $count <= intval($max); - else if($min !== '' && $max === '') - return $exists && $count >= intval($min); - } - - /** - * @param TListControl control to validate - * @return array number of selected values and its values. - */ - protected function getSelection($control) - { - $count = 0; - $values = array(); - - //get the data - foreach($control->getItems() as $item) - { - if($item->getSelected()) - { - $count++; - $values[] = $item->getValue(); - } - } - return array($count, $values); - } - - /** - * @return array list of required values. - */ - protected function getRequiredValues() - { - $required = array(); - $string = $this->getRequiredSelections(); - if(!empty($string)) - $required = preg_split('/,\s*/', $string); - return $required; - } - - /** - * Returns an array of javascript validator options. - * @return array javascript validator options. - */ - protected function getClientScriptOptions() - { - $options = parent::getClientScriptOptions(); - $control = $this->getValidationTarget(); - - if(!$control instanceof TListControl) - { - throw new TConfigurationException( - 'tlistcontrolvalidator_invalid_control', - $this->getID(),$this->getControlToValidate(), get_class($control)); - } - - $min = $this->getMinSelection(); - $max = $this->getMaxSelection(); - if($min !== '') - $options['Min']= intval($min); - if($max !== '') - $options['Max']= intval($max); - $required = $this->getRequiredSelections(); - if(strlen($required) > 0) - $options['Required']= $required; - $options['TotalItems'] = $control->getItemCount(); - - return $options; - } -} -?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php index fd13e88c..9a523b55 100644 --- a/framework/Web/UI/WebControls/TRadioButton.php +++ b/framework/Web/UI/WebControls/TRadioButton.php @@ -101,14 +101,14 @@ class TRadioButton extends TCheckBox $this->setViewState('GroupName',$value,''); } -/* protected function getValueAttribute() + protected function getValueAttribute() { if(($value=parent::getValueAttribute())==='') return $this->getUniqueID(); else return $value; } -*/ + /** * @return string the name used to fetch radiobutton post data */ @@ -146,8 +146,7 @@ class TRadioButton extends TCheckBox $writer->addAttribute('id',$clientID); $writer->addAttribute('type','radio'); $writer->addAttribute('name',$this->getUniqueGroupName()); - if(($value = $this->getValueAttribute()) !== '') - $writer->addAttribute('value',$value); + $writer->addAttribute('value',$this->getValueAttribute()); if($this->getChecked()) $writer->addAttribute('checked','checked'); if(!$this->getEnabled(true)) diff --git a/framework/Web/UI/WebControls/TRangeValidator.php b/framework/Web/UI/WebControls/TRangeValidator.php index b7387522..56cc16bc 100644 --- a/framework/Web/UI/WebControls/TRangeValidator.php +++ b/framework/Web/UI/WebControls/TRangeValidator.php @@ -29,6 +29,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * operation is performed. The following value types are supported: * - Integer A 32-bit signed integer data type. * - Float A double-precision floating point number data type. + * - Currency A decimal data type that can contain currency symbols. * - Date A date data type. The date format can be specified by * setting {@link setDateFormat DateFormat} property, which must be recognizable * by {@link TSimpleDateFormatter}. If the property is not set, @@ -86,13 +87,13 @@ class TRangeValidator extends TBaseValidator } /** - * Sets the data type (Integer, Float, Date, String) that the values being - * compared are converted to before the comparison is made. + * Sets the data type (Integer, Float, Currency, Date, String) that the values + * being compared are converted to before the comparison is made. * @param string the data type */ public function setDataType($value) { - $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String'); + $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); } /** @@ -130,6 +131,8 @@ class TRangeValidator extends TBaseValidator return $this->isValidInteger($value); case 'Float': return $this->isValidFloat($value); + case 'Currency': + return $this->isValidCurrency($value); case 'Date': return $this->isValidDate($value); default: @@ -175,6 +178,38 @@ class TRangeValidator extends TBaseValidator return $valid; } + /** + * Determine if the value is a valid currency range, + * @param string currency value + * @return boolean true if within range. + */ + protected function isValidCurrency($value) + { + $minValue=$this->getMinValue(); + $maxValue=$this->getMaxValue(); + + $valid=true; + $value = $this->getCurrencyValue($value); + if($minValue!=='') + $valid=$valid && ($value>= $this->getCurrencyValue($minValue)); + if($maxValue!=='') + $valid=$valid && ($value<= $this->getCurrencyValue($minValue)); + return $valid; + } + + /** + * Parse the string into a currency value, return the float value of the currency. + * @param string currency as string + * @return float currency value. + */ + protected function getCurrencyValue($value) + { + if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value,$matches)) + return floatval($matches[0]); + else + return 0.0; + } + /** * Determine if the date is within the specified range. * Uses pradoParseDate and strtotime to get the date from string. diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php index 04e333eb..ddbb12c8 100644 --- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php +++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php @@ -21,9 +21,6 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * TRequiredFieldValidator makes the associated input control a required field. * The input control fails validation if its value does not change from * the {@link setInitialValue InitialValue} property upon losing focus. - * - * Validation will also succeed if input is of TListControl type and the number - * of selected values different from the initial value is greater than zero. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -56,32 +53,12 @@ class TRequiredFieldValidator extends TBaseValidator * This method overrides the parent's implementation. * The validation succeeds if the input component changes its data * from the {@link getInitialValue InitialValue} or the input control is not given. - * - * Validation will also succeed if input is of TListControl type and the - * number of selected values different from the initial value is greater - * than zero. - * * @return boolean whether the validation succeeds */ protected function evaluateIsValid() { - $control = $this->getValidationTarget(); - $initial = trim($this->getInitialValue()); - if($control instanceof TListControl) - { - $count = 0; - foreach($control->getItems() as $item) - { - if($item->getSelected() && $item->getValue() != $initial) - $count++; - } - return $count > 0; - } - else - { - $value=$this->getValidationValue($control); - return trim($value)!==$initial || (is_bool($value) && $value); - } + $value=$this->getValidationValue($this->getValidationTarget()); + return trim($value)!==trim($this->getInitialValue()) || (is_bool($value) && $value); } /** @@ -92,9 +69,6 @@ class TRequiredFieldValidator extends TBaseValidator { $options = parent::getClientScriptOptions(); $options['InitialValue']=$this->getInitialValue(); - $control = $this->getValidationTarget(); - if($control instanceof TListControl) - $options['TotalItems'] = $control->getItemCount(); return $options; } } -- cgit v1.2.3