Changeset 2190 for branches/3.2-dev
- Timestamp:
- 09/03/2007 09:23:43 AM (16 months ago)
- Location:
- branches/3.2-dev
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2-dev/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.page
r2189 r2190 4 4 5 5 <p>Horizontal slider, with image handle, Javascript 'onSlide' handler, ServerSide 'onSliderChanged' handler and autopostback=true</p> 6 <com:TSlider id="hSlider" AutoPostBack="true" Handle.CssClass="handle-image" Direction="Horizontal" Enabled="true" MinValue="0" MaxValue="1 00" OnSliderChanged="sliderChanged">6 <com:TSlider id="hSlider" AutoPostBack="true" Handle.CssClass="handle-image" Direction="Horizontal" Enabled="true" MinValue="0" MaxValue="1" StepSize="0.1" OnValueChanged="sliderChanged"> 7 7 <prop:ClientSide.onSlide> 8 8 $('hslidervalue').innerHTML = value; … … 14 14 Vertical slider, cursor handle, no auto postback, no event handler 15 15 </p> 16 <com:TSlider id="vSlider" Direction="Vertical" Enabled="true" Height="200px" Values="(0,1,2,3,4,5)" MinValue="2" />16 <com:TSlider id="vSlider" Direction="Vertical" Enabled="true" Values="(-2,-1,0,1,6,2,7,3,4,5)" /> 17 17 <com:TButton onclick="testsubmit" text="Submit"/> 18 18 19 19 <br/> 20 <com:TSlider />20 <com:TSlider StepSize="0.1"/> 21 21 <p> 22 22 Results :<br/> -
branches/3.2-dev/framework/Web/Javascripts/source/prado/slider/slider.js
r2189 r2190 7 7 options.onChange=this.change.bind(this); 8 8 9 this.onSlide=options.onSlide;10 options.onSlide=this.slide.bind(this);11 12 9 this.hiddenField=$(this.options.ID+'_1'); 13 10 new Control.Slider(options.ID+'_handle',options.ID, options); … … 17 14 }, 18 15 19 round : function (v)20 {21 // round the value with specified decimals22 var d=Math.pow(10,this.options['decimals']);23 // Round24 return (Math.round(v*d)/d);25 },26 27 16 change : function (v) 28 17 { 29 v=this.round(v);30 18 this.hiddenField.value=v; 31 19 if (this.onChange) … … 37 25 Event.fireEvent(this.hiddenField, "change"); 38 26 } 39 },40 41 slide : function (v)42 {43 v=this.round(v);44 if (this.onSlide)45 {46 this.onSlide(v);47 }48 27 } 49 28 }); -
branches/3.2-dev/framework/Web/UI/WebControls/TSlider.php
r2189 r2190 58 58 */ 59 59 private $_handle; 60 /** 61 * @var string Custom handle class name 62 */ 63 private $_handleClass; 64 /** 60 /* 65 61 * @var boolean Wether the data has changed during postback 66 62 */ … … 84 80 public function setDirection($value) 85 81 { 86 $this->setViewState('Direction', TPropertyValue::ensureEnum($value, TSliderDirection));82 $this->setViewState('Direction', TPropertyValue::ensureEnum($value,'TSliderDirection')); 87 83 } 88 84 … … 104 100 105 101 /** 106 * @return string CssClass for an horizontal track of the slider control. Defaults to 'hslider' 107 */ 108 public function getHorizontalCssClass () 109 { 110 return $this->getViewState('HorizontalCssClass', 'hslider'); 111 } 112 113 /** 114 * @param string CssClass for an horizontal track of the slider control. Defaults to 'hslider' 115 */ 116 public function setHorizontalCssClass ($value) 117 { 118 $this->setViewState('HorizontalCssClass', $value, 'hslider'); 119 } 120 121 /** 122 * @return string CssClass for a vertical track of the slider control. Defaults to 'slider' 123 */ 124 public function getVerticalCssClass () 125 { 126 return $this->getViewState('VerticalCssClass', 'vslider'); 127 } 128 129 /** 130 * @param string CssClass for a vertical track of the slider control. Defaults to 'vslider' 131 */ 132 public function setVerticalCssClass ($value) 133 { 134 $this->setViewState('VerticalCssClass', $value, 'vslider'); 135 } 136 137 /** 138 * @return int Maximum value for the slider 102 * @return float Maximum value for the slider 139 103 */ 140 104 public function getMaxValue() … … 144 108 145 109 /** 146 * @param int Maximum value for slider110 * @param float Maximum value for slider 147 111 */ 148 112 public function setMaxValue($value) 149 113 { 150 $value=TPropertyValue::ensureInteger($value); 151 // Should I ensure the values are the same than the allowed values ? 152 /* 153 if (($values=$this->getValues())!==null && $value != max($values)) $value=max($values); 154 */ 155 $this->setViewState('MaxValue', $value,100); 156 } 157 158 /** 159 * @return int Minimum value for slider 114 $this->setViewState('MaxValue', TPropertyValue::ensureFloat($value),100); 115 } 116 117 /** 118 * @return float Minimum value for slider 160 119 */ 161 120 public function getMinValue() … … 165 124 166 125 /** 167 * @param int Minimum value for slider126 * @param float Minimum value for slider 168 127 */ 169 128 public function setMinValue($value) 170 129 { 171 $value=TPropertyValue::ensureInteger($value); 172 // Should I ensure the values are the same than the allowed values ? 173 /* 174 if (($values=$this->getValues())!==null && $value != min($values)) $value=min($values); 175 */ 176 $this->setViewState('MinValue', $value,0); 177 } 178 130 $this->setViewState('MinValue', TPropertyValue::ensureFloat($value),0); 131 } 132 133 /** 134 * @return float Step size. Defaults to 1 135 */ 136 public function getStepSize() 137 { 138 return $this->getViewState('StepSize', 1); 139 } 140 141 /** 142 * @param float Step size. Defaults to 1. 143 */ 144 public function setStepSize($value) 145 { 146 $this->setViewState('StepSize', $value, 1); 147 } 148 179 149 /** 180 150 * @return float current value of slider … … 208 178 $value=TPropertyValue::ensureArray($value); 209 179 $this->setViewState('Values', $value, null); 210 // Should I ensure Min/MaxValue are correct ??? 211 /* 212 if ($this->getMinValue() < min($value)) $this->setMinValue(min($value)); 213 if ($this->getMaxValue() > max($value)) $this->setMaxValue(max($value)); 214 */ 215 } 216 217 /** 218 * @return int number of decimals for the value. Defaults to 0 219 */ 220 public function getDecimals() 221 { 222 return $this->getViewState("Decimals", 0); 223 } 224 225 /** 226 * @param int number of decimas for the value. Defaults to 0. 227 */ 228 public function setDecimals($value) 229 { 230 $this->setViewState ('Decimals', TPropertyValue::ensureInteger($value), 0); 231 } 180 } 181 232 182 233 183 /** … … 254 204 public function getHandleClass () 255 205 { 256 return $this-> _handleClass?$this->_handleClass:TSliderHandle;206 return $this->getViewState('HandleClass', 'TSliderHandle'); 257 207 } 258 208 … … 267 217 if ($handle instanceof TSliderHandle) 268 218 { 269 $this-> _handleClass=$value;219 $this->setViewState('HandleClass', $value); 270 220 $this->_handle=$handle; 271 221 } else { … … 325 275 public function raisePostDataChangedEvent() 326 276 { 327 $this->on SliderChanged(null);328 } 329 330 /** 331 * Raises <b>On SliderChanged</b> event.277 $this->onValueChanged(null); 278 } 279 280 /** 281 * Raises <b>OnValueChanged</b> event. 332 282 * This method is invoked when the {@link getValue Value} 333 283 * property changes on postback. … … 336 286 * @param TEventParameter event parameter to be passed to the event handlers 337 287 */ 338 public function on SliderChanged($param)339 { 340 if ($this->getDataChanged()) $this->raiseEvent('On SliderChanged',$this,$param);288 public function onValueChanged($param) 289 { 290 if ($this->getDataChanged()) $this->raiseEvent('OnValueChanged',$this,$param); 341 291 } 342 292 … … 410 360 protected function addAttributesToRender($writer) 411 361 { 412 362 parent::addAttributesToRender($writer); 413 363 $writer->addAttribute('id',$this->getClientID()); 414 $class=($this->getDirection()==TSliderDirection::Horizontal)?$this->getHorizontalCssClass():$this->getVerticalCssClass(); 415 $writer->addAttribute('class', $class); 416 parent::addAttributesToRender($writer); 364 if ($this->getCssClass()==='') 365 $writer->addAttribute('class', $this->getDirection()===TSliderDirection::Horizontal?'hslider':'vslider'); 417 366 } 418 367 … … 469 418 470 419 // Slider Control options 420 $minValue=$this->getMinValue(); 421 $maxValue=$this->getMaxValue(); 471 422 $options['axis'] = strtolower($this->getDirection()); 472 $options['maximum'] = $ this->getMaxValue();473 $options['minimum'] = $ this->getMinValue();474 $options['range'] = 'javascript:$R('.$ this->getMinValue().",".$this->getMaxValue().")";423 $options['maximum'] = $maxValue; 424 $options['minimum'] = $minValue; 425 $options['range'] = 'javascript:$R('.$minValue.",".$maxValue.")"; 475 426 $options['sliderValue'] = $this->getValue(); 476 427 $options['disabled'] = !$this->getEnabled(); 477 428 if (($values=$this->getValues())) 429 { 430 // Values are provided. Check if min/max are present in them 431 if (!in_array($minValue, $values)) $values[]=$minValue; 432 if (!in_array($maxValue, $values)) $values[]=$maxValue; 433 // Remove all values outsize the range [min..max] 434 foreach ($values as $idx=>$value) 435 { 436 if ($value < $minValue) unset ($values[$idx]); 437 if ($value > $maxValue) unset ($values[$idx]); 438 } 439 } 440 else 441 { 442 // Values are not provided, generate automatically using stepsize 443 $step=$this->getStepSize(); 444 // We want at most 200 values, so, change the step if necessary 445 if (($maxValue-$minValue)/$step > 200) 446 { 447 $step=($maxValue-$minValue)/200; 448 } 449 $values=array(); 450 for ($i=$minValue;$i<=$maxValue;$i+=$step) 451 $values[]=$i; 452 // Add max if it's not in the array because of step 453 if (!in_array($maxValue, $values)) $values[]=$maxValue; 454 } 478 455 $options['values'] = TJavascript::Encode($values,false); 479 $options['decimals'] = $this->getDecimals();480 481 456 if(!is_null($this->_clientScript)) 482 457 $options = array_merge($options,$this->_clientScript->getOptions()->toArray());
