From 6e29b055b3cbc2a46e29075608c7e82a328d5270 Mon Sep 17 00:00:00 2001 From: wei <> Date: Wed, 15 Feb 2006 07:44:51 +0000 Subject: Adding new TRatingList component. --- framework/Web/UI/WebControls/TColorPicker.php | 1 - framework/Web/UI/WebControls/TCompareValidator.php | 6 +- framework/Web/UI/WebControls/THtmlArea.php | 65 +++++++- framework/Web/UI/WebControls/TRatingList.php | 174 +++++++++++++++++++++ .../Web/UI/WebControls/TValueTypeValidator.php | 5 +- 5 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 framework/Web/UI/WebControls/TRatingList.php (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/WebControls/TColorPicker.php b/framework/Web/UI/WebControls/TColorPicker.php index 0212b3fd..f168aa5f 100644 --- a/framework/Web/UI/WebControls/TColorPicker.php +++ b/framework/Web/UI/WebControls/TColorPicker.php @@ -152,7 +152,6 @@ class TColorPicker extends TTextBox 'target_white' => '.gif', 'background' => '.png', 'slider' => '.gif', 'hue' => '.gif'); - $cs = $this->getPage()->getClientScript(); $list = array(); foreach($images as $filename => $ext) diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php index eeebb946..39086b48 100644 --- a/framework/Web/UI/WebControls/TCompareValidator.php +++ b/framework/Web/UI/WebControls/TCompareValidator.php @@ -205,10 +205,12 @@ class TCompareValidator extends TBaseValidator $value2=0; return array($value1, $value2); case 'Date': - throw new TNotSupportedException('Date comparison for TCompareValidator is currently not supported. It will be supported in future.'); $dateFormat = $this->getDateFormat(); if (strlen($dateFormat)) - return array(pradoParseDate($value1, $dateFormat), pradoParseDate($value2, $dateFormat)); + { + $formatter = Prado::createComponent('System.Data.TDateTimeSimpleFormatter', $dateFormat); + return array($formatter->parse($value1), $formatter->parse($value2)); + } else return array(strtotime($value1), strtotime($value2)); } diff --git a/framework/Web/UI/WebControls/THtmlArea.php b/framework/Web/UI/WebControls/THtmlArea.php index 4196de3a..eb2c452f 100644 --- a/framework/Web/UI/WebControls/THtmlArea.php +++ b/framework/Web/UI/WebControls/THtmlArea.php @@ -37,7 +37,7 @@ * * * plugins : "contextmenu,paste" - * language : "zh_CN" + * language : "zh_cn" * * * @@ -73,6 +73,45 @@ */ class THtmlArea extends TTextBox { + protected $langs = array( + 'da' => array('da'), + 'fa' => array('fa'), + 'hu' => array('hu'), + 'nb' => array('nb'), + 'pt_br' => array('pt_BR'), + 'sk' => array('sk'), + 'zh_tw_utf8' => array('zh_TW', 'zh_HK'), + 'ar' => array('ar'), + 'de' => array('de'), + 'fi' => array('fi'), + 'is' => array('is'), + 'nl' => array('nl'), + 'sv' => array('sv'), + 'ca' => array('ca'), + 'el' => array('el'), + 'fr' => array('fr'), + 'it' => array('it'), + 'nn' => array('nn'), //what is nn? +// 'ru' => array('ru'), + 'th' => array('th'), + 'cs' => array('cs'), + 'en' => array('en'), + 'fr_ca' => array('fr_CA'), + 'ja' => array('ja'), + 'pl' => array('pl'), +// 'ru_KOI8-R' => array('ru'), /// what is this? + 'zh_cn' => array('zh_CN'), + 'cy' => array('cy'), //what is this? + 'es' => array('es'), + 'he' => array('he'), + 'ko' => array('ko'), + 'pt' => array('pt'), + 'ru_UTF-8' => array('ru'), + 'tr' => array('tr'), + 'si' => array('si'), +// 'zh_tw' => array('zh_TW'), + ); + /** * Overrides the parent implementation. * TextMode for THtmlArea control is always 'MultiLine' @@ -294,13 +333,27 @@ class THtmlArea extends TTextBox */ protected function getLanguageSuffix($culture) { - if(empty($culture)) + $app = $this->getApplication()->getGlobalization(); + if(empty($culture) && !is_null($app)) + $culture = $app->getCulture(); + $variants = array(); + if(!is_null($app)) + $variants = $app->getCultureVariants($culture); + + //default the variant to "en" + if(count($variants) == 0) + $variants[] = empty($culture) ? 'en' : strtolower($culture); + + foreach($this->langs as $js => $langs) { - $app = $this->getApplication()->getGlobalization(); - if(!is_null($app)) - $culture = $app->Culture; + foreach($variants as $variant) + { + if(in_array($variant, $langs)) + return $js; + } } - return empty($culture) ? 'en' : strtolower($culture); + + return 'en'; } } diff --git a/framework/Web/UI/WebControls/TRatingList.php b/framework/Web/UI/WebControls/TRatingList.php new file mode 100644 index 00000000..ad9b0256 --- /dev/null +++ b/framework/Web/UI/WebControls/TRatingList.php @@ -0,0 +1,174 @@ + + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TRatingList extends TRadioButtonList +{ + + public function __construct() + { + parent::__construct(); + $this->getRepeatInfo()->setRepeatDirection('Horizontal'); + } + + /** + * @param string the direction (Vertical, Horizontal) of traversing the list + */ + public function setRepeatDirection($value) + { + throw new TNotSupportedException('ratinglits_repeatdirection_unsupported'); + } + + /** + * @param string set the rating style + */ + public function setRatingStyle($value) + { + $this->setViewState('RatingStyle', $value, 'default'); + } + + /** + * @return TRatingListStyle current rating style + */ + public function getRatingStyle() + { + $style = $this->getViewState('RatingStyle', 'default'); + return is_string($style) ? $this->createRatingStyle($style) : $style; + } + + protected function createRatingStyle($type) + { + return new TRatingListDefaultStyle; + } + + /** + * @return string caption text. Default is "Rate It:". + */ + public function getCaptionText() + { + return $this->getViewState('Caption', 'Rate It:'); + } + + /** + * @param string caption text + */ + public function setCaptionText($value) + { + $this->setViewState('Caption', $value, 'Rate It:'); + } + + public function getRatingClientOptions() + { + $options = $this->getRatingStyle()->getOptions(); + $options['ID'] = $this->getClientID(); + $options['caption'] = $this->getCaptionText(); + $options['field'] = $this->getUniqueID(); + $options['total'] = $this->getItems()->getCount(); + $options['pos'] = $this->getSelectedIndex(); + var_dump($this->getSelectedIndex()); + return $options; + } + + protected function publishRatingListStyle() + { + $cs = $this->getPage()->getClientScript(); + $style = $this->getRatingStyle()->getStyleSheet(); + $url = $this->getService()->getAsset($style); + if(!$cs->isStyleSheetFileRegistered($style)) + $cs->registerStyleSheetFile($style, $url); + return $url; + } + + protected function publishRatingListAssets() + { + $cs = $this->getPage()->getClientScript(); + $assets = $this->getRatingStyle()->getAssets(); + $list = array(); + foreach($assets as $file) + $list[] = $this->getService()->getAsset($file); + return $list; + } + + /** + * @param THtmlWriter writer + */ + public function onPreRender($param) + { + parent::onPreRender($param); + $this->publishRatingListStyle(); + $this->publishRatingListAssets(); + $id = $this->getClientID(); + $scripts = $this->getPage()->getClientScript(); + $serializer = new TJavascriptSerializer($this->getRatingClientOptions()); + $options = $serializer->toJavascript(); + $code = "new Prado.WebUI.TRatingList($options);"; + $scripts->registerEndScript("prado:$id", $code); + } +} + +abstract class TRatingListStyle +{ + private $_options = array(); + + public function __construct() + { + $options['pos'] = -1; + $options['dx'] = 22; + $options['dy'] = 30; + $options['ix'] = 4; + $options['iy'] = 4; + $options['hx'] = 240; + $options['total'] = -1; + $this->_options = $options; + } + + public function getOptions() + { + return $this->_options; + } + + public function setOptions($options) + { + $this->_options = $options; + } + + abstract function getStyleSheet(); + + abstract function getAssets(); +} + +class TRatingListDefaultStyle extends TRatingListStyle +{ + public function __construct() + { + parent::__construct(); + $options = $this->getOptions(); + $options['cssClass'] = 'TRatingList_default'; + $this->setOptions($options); + } + + public function getStyleSheet() + { + $style = 'System.Web.Javascripts.ratings.default'; + $cssFile=Prado::getPathOfNamespace($style,'.css'); + return $cssFile; + } + + public function getAssets() + { + $assets = array(); + $image = 'System.Web.Javascripts.ratings.10star_white'; + $assets[] = Prado::getPathOfNamespace($image, '.gif'); + return $assets; + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TValueTypeValidator.php b/framework/Web/UI/WebControls/TValueTypeValidator.php index d24fda4f..f0f61d52 100644 --- a/framework/Web/UI/WebControls/TValueTypeValidator.php +++ b/framework/Web/UI/WebControls/TValueTypeValidator.php @@ -64,7 +64,10 @@ class TValueTypeValidator case 'Date': $dateFormat = $this->getDateFormat(); if(strlen($dateFormat)) - return pradoParseDate($value, $dateFormat) !== null; + { + $formatter = Prado::createComponent('System.Data.TDateTimeSimpleFormatter',$dateFormat); + return $formatter->isValidDate($value); + } else return strtotime($value) > 0; } -- cgit v1.2.3