diff options
author | wei <> | 2006-02-15 07:44:51 +0000 |
---|---|---|
committer | wei <> | 2006-02-15 07:44:51 +0000 |
commit | 6e29b055b3cbc2a46e29075608c7e82a328d5270 (patch) | |
tree | 13a197ad850f360125a96f5de83f1742a12e98ad /framework/Web | |
parent | d653bda6c6217f160a4de77e3f2f0ee62096be67 (diff) |
Adding new TRatingList component.
Diffstat (limited to 'framework/Web')
-rw-r--r-- | framework/Web/Javascripts/extended/builder.js | 2 | ||||
-rw-r--r-- | framework/Web/Javascripts/js/prado.js | 87 | ||||
-rw-r--r-- | framework/Web/Javascripts/prado/controls.js | 10 | ||||
-rw-r--r-- | framework/Web/Javascripts/ratings/10star_white.gif | bin | 0 -> 25048 bytes | |||
-rw-r--r-- | framework/Web/Javascripts/ratings/default.css | 21 | ||||
-rw-r--r-- | framework/Web/Javascripts/ratings/ratings.js | 70 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TColorPicker.php | 1 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TCompareValidator.php | 6 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/THtmlArea.php | 65 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TRatingList.php | 174 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TValueTypeValidator.php | 5 |
11 files changed, 399 insertions, 42 deletions
diff --git a/framework/Web/Javascripts/extended/builder.js b/framework/Web/Javascripts/extended/builder.js index 24b565e5..141eab51 100644 --- a/framework/Web/Javascripts/extended/builder.js +++ b/framework/Web/Javascripts/extended/builder.js @@ -2,7 +2,7 @@ Object.extend(Builder, {
exportTags:function()
{
- var tags=["BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG"];
+ var tags=["BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG", "CAPTION"];
tags.each(function(tag)
{
window[tag]=function()
diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index 0ca9d306..caae1134 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -1404,7 +1404,7 @@ _328.appendChild(Builder._text(_329)); return (typeof _330=="string"||typeof _330=="number"); }}; Object.extend(Builder,{exportTags:function(){ -var tags=["BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG"]; +var tags=["BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG","CAPTION"]; tags.each(function(tag){ window[tag]=function(){ var args=$A(arguments); @@ -1901,24 +1901,19 @@ Event.stop(e); } } }}); -Prado.WebUI.TListControl=Prado.WebUI.createPostBackComponent({onInit:function(_433){ -Event.observe(this.element,"change",Prado.PostBack.bindEvent(this,_433)); -}}); -Prado.WebUI.TListBox=Prado.WebUI.TListControl; -Prado.WebUI.TDropDownList=Prado.WebUI.TListControl; Prado.WebUI.DefaultButton=Class.create(); -Object.extend(Prado.WebUI.DefaultButton.prototype,{initialize:function(_434){ -this.options=_434; +Object.extend(Prado.WebUI.DefaultButton.prototype,{initialize:function(_433){ +this.options=_433; this._event=this.triggerEvent.bindEvent(this); -Event.observe(_434["Panel"],"keydown",this._event); -},triggerEvent:function(ev,_436){ -var _437=Event.keyCode(ev)==Event.KEY_RETURN; -var _438=Event.element(ev).tagName.toLowerCase()=="textarea"; -if(_437&&!_438){ -var _439=$(this.options["Target"]); -if(_439){ +Event.observe(_433["Panel"],"keydown",this._event); +},triggerEvent:function(ev,_435){ +var _436=Event.keyCode(ev)==Event.KEY_RETURN; +var _437=Event.element(ev).tagName.toLowerCase()=="textarea"; +if(_436&&!_437){ +var _438=$(this.options["Target"]); +if(_438){ this.triggered=true; -Event.fireEvent(_439,this.options["Event"]); +Event.fireEvent(_438,this.options["Event"]); Event.stop(ev); } } @@ -1928,15 +1923,15 @@ Prado.WebUI.TTextHighlighter.prototype={initialize:function(id){ if(!window.clipboardData){ return; } -var _440={href:"javascript:;//copy code to clipboard",onclick:"Prado.WebUI.TTextHighlighter.copy(this)",onmouseover:"Prado.WebUI.TTextHighlighter.hover(this)",onmouseout:"Prado.WebUI.TTextHighlighter.out(this)"}; -var div=DIV({className:"copycode"},A(_440,"Copy Code")); +var _439={href:"javascript:;//copy code to clipboard",onclick:"Prado.WebUI.TTextHighlighter.copy(this)",onmouseover:"Prado.WebUI.TTextHighlighter.hover(this)",onmouseout:"Prado.WebUI.TTextHighlighter.out(this)"}; +var div=DIV({className:"copycode"},A(_439,"Copy Code")); document.write(DIV(null,div).innerHTML); }}; Object.extend(Prado.WebUI.TTextHighlighter,{copy:function(obj){ -var _441=obj.parentNode.parentNode.parentNode; +var _440=obj.parentNode.parentNode.parentNode; var text=""; -for(var i=0;i<_441.childNodes.length;i++){ -var node=_441.childNodes[i]; +for(var i=0;i<_440.childNodes.length;i++){ +var node=_440.childNodes[i]; if(node.innerText){ text+=node.innerText=="Copy Code"?"":node.innerText; }else{ @@ -1951,4 +1946,54 @@ obj.parentNode.className="copycode copycode_hover"; },out:function(obj){ obj.parentNode.className="copycode"; }}); +Prado.WebUI.TRatingList=Class.create(); +Prado.WebUI.TRatingList.prototype={selectedIndex:-1,initialize:function(_441){ +this.options=_441; +this.element=$(_441["ID"]); +Element.addClassName(this.element,_441.cssClass); +var _442=_441.total*_441.dx; +this.element.style.width=_442+"px"; +Event.observe(this.element,"mouseover",this.hover.bindEvent(this)); +Event.observe(this.element,"mouseout",this.recover.bindEvent(this)); +Event.observe(this.element,"click",this.click.bindEvent(this)); +this._onMouseMoveEvent=this.mousemoved.bindEvent(this); +this.selectedIndex=_441.pos; +this.radios=document.getElementsByName(_441.field); +this.caption=CAPTION(); +this.element.appendChild(this.caption); +this.showPosition(this.selectedIndex,false); +},hover:function(){ +Event.observe(this.element,"mousemove",this._onMouseMoveEvent); +},recover:function(){ +Event.stopObserving(this.element,"mousemove",this._onMouseMoveEvent); +this.showPosition(this.selectedIndex,false); +},mousemoved:function(e){ +this.updatePosition(e,true); +},updatePosition:function(e,_443){ +var obj=Event.element(e); +var _444=Position.cumulativeOffset(obj); +var _445=Event.pointerX(e)-_444[0]; +var pos=parseInt(_445/this.options.dx); +if(!_443||this.options.pos!=pos){ +this.showPosition(pos,_443); +} +},click:function(ev){ +this.updatePosition(ev,false); +this.selectedIndex=this.options.pos; +for(var i=0;i<this.radios.length;i++){ +this.radios[i].checked=(i==this.selectedIndex); +} +if(isFunction(this.options.onChange)){ +this.options.onChange(this,this.selectedIndex); +} +},showPosition:function(pos,_446){ +if(pos>=this.options.total){ +return; +} +var dy=this.options.dy*(pos+1)+this.options.iy; +var dx=_446?this.options.hx+this.options.ix:this.options.ix; +this.element.style.backgroundPosition="-"+dx+"px -"+dy+"px"; +this.options.pos=pos; +this.caption.innerHTML=pos>=0?this.radios[this.options.pos].value:this.options.caption; +}}; diff --git a/framework/Web/Javascripts/prado/controls.js b/framework/Web/Javascripts/prado/controls.js index 7a1a8257..aae3201e 100644 --- a/framework/Web/Javascripts/prado/controls.js +++ b/framework/Web/Javascripts/prado/controls.js @@ -112,16 +112,6 @@ Prado.WebUI.TTextBox = Prado.WebUI.createPostBackComponent( }
});
-Prado.WebUI.TListControl = Prado.WebUI.createPostBackComponent(
-{
- onInit : function(options)
- {
- Event.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
- }
-});
-
-Prado.WebUI.TListBox = Prado.WebUI.TListControl;
-Prado.WebUI.TDropDownList = Prado.WebUI.TListControl;
Prado.WebUI.DefaultButton = Class.create();
Object.extend(Prado.WebUI.DefaultButton.prototype,
diff --git a/framework/Web/Javascripts/ratings/10star_white.gif b/framework/Web/Javascripts/ratings/10star_white.gif Binary files differnew file mode 100644 index 00000000..0acdf5c9 --- /dev/null +++ b/framework/Web/Javascripts/ratings/10star_white.gif diff --git a/framework/Web/Javascripts/ratings/default.css b/framework/Web/Javascripts/ratings/default.css new file mode 100644 index 00000000..1609ee05 --- /dev/null +++ b/framework/Web/Javascripts/ratings/default.css @@ -0,0 +1,21 @@ +.TRatingList_default tr
+{
+ display: none;
+}
+
+.TRatingList_default
+{
+ width: 120px;
+ height: 20px;
+ background-image: url(10star_white.gif);
+ background-position: -0px -4px;
+ background-repeat: no-repeat;
+ margin: 4px;
+ cursor: pointer;
+}
+
+.TRatingList_default caption
+{
+ padding-left: 4px;
+ text-align: left;
+}
\ No newline at end of file diff --git a/framework/Web/Javascripts/ratings/ratings.js b/framework/Web/Javascripts/ratings/ratings.js new file mode 100644 index 00000000..c5efc372 --- /dev/null +++ b/framework/Web/Javascripts/ratings/ratings.js @@ -0,0 +1,70 @@ +Prado.WebUI.TRatingList = Class.create();
+Prado.WebUI.TRatingList.prototype =
+{
+ selectedIndex : -1,
+
+ initialize : function(options)
+ {
+ this.options = options;
+ this.element = $(options['ID']);
+ Element.addClassName(this.element,options.cssClass);
+ var width = options.total * options.dx;
+ this.element.style.width = width+"px";
+ Event.observe(this.element, 'mouseover', this.hover.bindEvent(this));
+ Event.observe(this.element, 'mouseout', this.recover.bindEvent(this));
+ Event.observe(this.element, 'click', this.click.bindEvent(this));
+ this._onMouseMoveEvent = this.mousemoved.bindEvent(this);
+ this.selectedIndex = options.pos;
+ this.radios = document.getElementsByName(options.field);
+ this.caption = CAPTION();
+ this.element.appendChild(this.caption);
+ this.showPosition(this.selectedIndex,false);
+ },
+
+ hover : function()
+ {
+ Event.observe(this.element, "mousemove", this._onMouseMoveEvent);
+ },
+
+ recover : function()
+ {
+ Event.stopObserving(this.element, "mousemove", this._onMouseMoveEvent);
+ this.showPosition(this.selectedIndex,false);
+ },
+
+ mousemoved : function(e)
+ {
+ this.updatePosition(e,true);
+ },
+
+ updatePosition : function(e, hovering)
+ {
+ var obj = Event.element(e);
+ var elementPos = Position.cumulativeOffset(obj);
+ var clientX = Event.pointerX(e) - elementPos[0];
+ var pos = parseInt(clientX / this.options.dx);
+ if(!hovering || this.options.pos != pos)
+ this.showPosition(pos, hovering)
+ },
+
+ click : function(ev)
+ {
+ this.updatePosition(ev,false);
+ this.selectedIndex = this.options.pos;
+ for(var i = 0; i < this.radios.length; i++)
+ this.radios[i].checked = (i == this.selectedIndex);
+ if(isFunction(this.options.onChange))
+ this.options.onChange(this, this.selectedIndex);
+ },
+
+ showPosition : function(pos, hovering)
+ {
+ if(pos >= this.options.total) return;
+ var dy = this.options.dy * (pos+1) + this.options.iy;
+ var dx = hovering ? this.options.hx + this.options.ix : this.options.ix;
+ this.element.style.backgroundPosition = "-"+dx+"px -"+dy+"px";
+ this.options.pos = pos;
+ this.caption.innerHTML = pos >= 0 ?
+ this.radios[this.options.pos].value : this.options.caption;
+ }
+}
\ No newline at end of file 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 @@ * <com:THtmlArea>
* <prop:Options>
* plugins : "contextmenu,paste"
- * language : "zh_CN"
+ * language : "zh_cn"
* </prop:Options>
* </com:THtmlArea>
* </code>
@@ -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 @@ +<?php
+
+Prado::using('System.Web.UI.WebControls.TRadioButtonList');
+
+/**
+ * TRatingList
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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;
}
|