1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: 14: 15: 16: 17: 18: 19: 20:
21: class Form_Element_Slider extends Form_Element_Hidden
22: {
23:
24: 25: 26: 27: 28:
29: private $maxRange;
30:
31: 32: 33: 34: 35:
36: private $minRange;
37:
38: 39: 40: 41:
42: private $step;
43:
44: 45: 46: 47:
48: private $displayValue;
49:
50: private $unit;
51:
52:
53: 54: 55: 56: 57: 58:
59: public function __construct($nom,$form)
60: {
61: parent::__construct($nom,$form);
62: $this->nom = $nom;
63: $this->maxRange = 100;
64: $this->minRange = 0;
65: $this->start = 0;
66: $this->step = 1;
67: $this->displayValue = false;
68: }
69:
70: 71: 72: 73: 74: 75: 76:
77: public function setRange($min,$max)
78: {
79: $this->maxRange = $max;
80: $this->minRange = $min;
81: return $this;
82: }
83:
84: 85: 86: 87: 88:
89: public function step($val)
90: {
91: $this->step = $val;
92: return $this;
93: }
94:
95: 96: 97: 98:
99: public function setStartValue($val)
100: {
101: $this->start = $val;
102: return $this;
103: }
104:
105: 106: 107: 108: 109: 110:
111: public function displayValue($bool,$unit='%')
112: {
113: $this->displayValue = $bool;
114: $this->unit = $unit;
115: return $this;
116: }
117:
118: public function __toString()
119: {
120: $css = $this->cssClass();
121: $html = '';
122: if(!empty($this->label))
123: {
124: $html .= "\t".'<label for="'.$this->attrs['id'].'" class="'.$this->cssLabel.'">'.$this->label.'</label>'."\n";
125: if($this->labelNewLine)
126: $html.="\t".'<br />'."\n";
127: }
128:
129: $value = $this->form->getPostedvalue($this->attrs['name']);
130: if(empty($value))
131: $value = $this->start;
132:
133: $html .= '<div id="prynslide_'.$this->nom.'"></div>';
134: if($this->displayValue)
135: $html .='<div id="prynslidedisp_'.$this->nom.'">'.$value.$this->unit.'</div>';
136:
137: $this->form->javascript.='$("#prynslide_'.$this->nom.'").slider({
138: max : '.$this->maxRange.',
139: min : '.$this->minRange.',
140: step : '.$this->step.',
141: value : '.$value.',
142: change : function(event,ui){$("#'.$this->attrs['id'].'").val(ui.value)}';
143:
144: if($this->displayValue)
145: $this->form->javascript.=',slide:function(event,ui){$("#prynslidedisp_'.$this->nom.'").html(ui.value+"%")}';
146:
147: $this->form->javascript.='});';
148: $html.= parent::__toString();
149: return $html;
150: }
151: }
152: ?>