| 1 |
lars |
1 |
Prado.WebUI.TRatingList = Base.extend(
|
|
|
2 |
{
|
|
|
3 |
selectedIndex : -1,
|
|
|
4 |
rating: -1,
|
|
|
5 |
readOnly : false,
|
|
|
6 |
|
|
|
7 |
constructor : function(options)
|
|
|
8 |
{
|
|
|
9 |
var cap = $(options.CaptionID);
|
|
|
10 |
this.options = Object.extend(
|
|
|
11 |
{
|
|
|
12 |
caption : cap ? cap.innerHTML : ''
|
|
|
13 |
}, options || {});
|
|
|
14 |
|
|
|
15 |
Prado.WebUI.TRatingList.register(this);
|
|
|
16 |
this._init();
|
|
|
17 |
this.selectedIndex = options.SelectedIndex;
|
|
|
18 |
this.rating = options.Rating;
|
|
|
19 |
this.readOnly = options.ReadOnly
|
|
|
20 |
if(options.Rating <= 0 && options.SelectedIndex >= 0)
|
|
|
21 |
this.rating = options.SelectedIndex+1;
|
|
|
22 |
this.setReadOnly(this.readOnly);
|
|
|
23 |
},
|
|
|
24 |
|
|
|
25 |
_init: function(options)
|
|
|
26 |
{
|
|
|
27 |
Element.addClassName($(this.options.ListID),this.options.Style);
|
|
|
28 |
this.radios = new Array();
|
|
|
29 |
this._mouseOvers = new Array();
|
|
|
30 |
this._mouseOuts = new Array();
|
|
|
31 |
this._clicks = new Array();
|
|
|
32 |
var index=0;
|
|
|
33 |
for(var i = 0; i<this.options.ItemCount; i++)
|
|
|
34 |
{
|
|
|
35 |
var radio = $(this.options.ListID+'_c'+i);
|
|
|
36 |
var td = radio.parentNode.parentNode;
|
|
|
37 |
if(radio && td.tagName.toLowerCase()=='td')
|
|
|
38 |
{
|
|
|
39 |
this.radios.push(radio);
|
|
|
40 |
this._mouseOvers.push(this.hover.bindEvent(this,index));
|
|
|
41 |
this._mouseOuts.push(this.recover.bindEvent(this,index));
|
|
|
42 |
this._clicks.push(this.click.bindEvent(this,index));
|
|
|
43 |
index++;
|
|
|
44 |
Element.addClassName(td,"rating");
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
},
|
|
|
48 |
|
|
|
49 |
hover : function(ev,index)
|
|
|
50 |
{
|
|
|
51 |
if(this.readOnly==true) return;
|
|
|
52 |
for(var i = 0; i<this.radios.length; i++)
|
|
|
53 |
{
|
|
|
54 |
var node = this.radios[i].parentNode.parentNode;
|
|
|
55 |
var action = i <= index ? 'addClassName' : 'removeClassName'
|
|
|
56 |
Element[action](node,"rating_hover");
|
|
|
57 |
Element.removeClassName(node,"rating_selected");
|
|
|
58 |
Element.removeClassName(node,"rating_half");
|
|
|
59 |
}
|
|
|
60 |
this.showCaption(this.getIndexCaption(index));
|
|
|
61 |
},
|
|
|
62 |
|
|
|
63 |
recover : function(ev,index)
|
|
|
64 |
{
|
|
|
65 |
if(this.readOnly==true) return;
|
|
|
66 |
this.showRating(this.rating);
|
|
|
67 |
this.showCaption(this.options.caption);
|
|
|
68 |
},
|
|
|
69 |
|
|
|
70 |
click : function(ev, index)
|
|
|
71 |
{
|
|
|
72 |
if(this.readOnly==true) return;
|
|
|
73 |
for(var i = 0; i<this.radios.length; i++)
|
|
|
74 |
this.radios[i].checked = (i == index);
|
|
|
75 |
this.selectedIndex = index;
|
|
|
76 |
this.setRating(index+1);
|
|
|
77 |
|
|
|
78 |
if(this.options['AutoPostBack']==true){
|
|
|
79 |
this.dispatchRequest(ev);
|
|
|
80 |
}
|
|
|
81 |
},
|
|
|
82 |
|
|
|
83 |
dispatchRequest : function(ev)
|
|
|
84 |
{
|
|
|
85 |
var requestOptions = Object.extend(
|
|
|
86 |
{
|
|
|
87 |
ID : this.options.ListID+"_c"+this.selectedIndex,
|
|
|
88 |
EventTarget : this.options.ListName+"$c"+this.selectedIndex
|
|
|
89 |
},this.options);
|
|
|
90 |
Prado.PostBack(ev, requestOptions);
|
|
|
91 |
},
|
|
|
92 |
|
|
|
93 |
setRating : function(value)
|
|
|
94 |
{
|
|
|
95 |
this.rating = value;
|
|
|
96 |
var base = Math.floor(value-1);
|
|
|
97 |
var remainder = value - base-1;
|
|
|
98 |
var halfMax = this.options.HalfRating["1"];
|
|
|
99 |
var index = remainder > halfMax ? base+1 : base;
|
|
|
100 |
for(var i = 0; i<this.radios.length; i++)
|
|
|
101 |
this.radios[i].checked = (i == index);
|
|
|
102 |
|
|
|
103 |
var caption = this.getIndexCaption(index);
|
|
|
104 |
this.setCaption(caption);
|
|
|
105 |
this.showCaption(caption);
|
|
|
106 |
|
|
|
107 |
this.showRating(this.rating);
|
|
|
108 |
},
|
|
|
109 |
|
|
|
110 |
showRating: function(value)
|
|
|
111 |
{
|
|
|
112 |
var base = Math.floor(value-1);
|
|
|
113 |
var remainder = value - base-1;
|
|
|
114 |
var halfMin = this.options.HalfRating["0"];
|
|
|
115 |
var halfMax = this.options.HalfRating["1"];
|
|
|
116 |
var index = remainder > halfMax ? base+1 : base;
|
|
|
117 |
var hasHalf = remainder >= halfMin && remainder <= halfMax;
|
|
|
118 |
for(var i = 0; i<this.radios.length; i++)
|
|
|
119 |
{
|
|
|
120 |
var node = this.radios[i].parentNode.parentNode;
|
|
|
121 |
var action = i > index ? 'removeClassName' : 'addClassName';
|
|
|
122 |
Element[action](node, "rating_selected");
|
|
|
123 |
if(i==index+1 && hasHalf)
|
|
|
124 |
Element.addClassName(node, "rating_half");
|
|
|
125 |
else
|
|
|
126 |
Element.removeClassName(node, "rating_half");
|
|
|
127 |
Element.removeClassName(node,"rating_hover");
|
|
|
128 |
}
|
|
|
129 |
},
|
|
|
130 |
|
|
|
131 |
getIndexCaption : function(index)
|
|
|
132 |
{
|
|
|
133 |
return index > -1 ? this.radios[index].value : this.options.caption;
|
|
|
134 |
},
|
|
|
135 |
|
|
|
136 |
showCaption : function(value)
|
|
|
137 |
{
|
|
|
138 |
var caption = $(this.options.CaptionID);
|
|
|
139 |
if(caption) caption.innerHTML = value;
|
|
|
140 |
$(this.options.ListID).title = value;
|
|
|
141 |
},
|
|
|
142 |
|
|
|
143 |
setCaption : function(value)
|
|
|
144 |
{
|
|
|
145 |
this.options.caption = value;
|
|
|
146 |
this.showCaption(value);
|
|
|
147 |
},
|
|
|
148 |
|
|
|
149 |
setReadOnly : function(value)
|
|
|
150 |
{
|
|
|
151 |
this.readOnly = value;
|
|
|
152 |
for(var i = 0; i<this.radios.length; i++)
|
|
|
153 |
{
|
|
|
154 |
|
|
|
155 |
var action = value ? 'addClassName' : 'removeClassName';
|
|
|
156 |
Element[action](this.radios[i].parentNode.parentNode, "rating_disabled");
|
|
|
157 |
|
|
|
158 |
var action = value ? 'stopObserving' : 'observe';
|
|
|
159 |
var td = this.radios[i].parentNode.parentNode;
|
|
|
160 |
Event[action](td, "mouseover", this._mouseOvers[i]);
|
|
|
161 |
Event[action](td, "mouseout", this._mouseOuts[i]);
|
|
|
162 |
Event[action](td, "click", this._clicks[i]);
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
this.showRating(this.rating);
|
|
|
166 |
}
|
|
|
167 |
},
|
|
|
168 |
{
|
|
|
169 |
ratings : {},
|
|
|
170 |
register : function(rating)
|
|
|
171 |
{
|
|
|
172 |
Prado.WebUI.TRatingList.ratings[rating.options.ListID] = rating;
|
|
|
173 |
},
|
|
|
174 |
|
|
|
175 |
setReadOnly : function(id,value)
|
|
|
176 |
{
|
|
|
177 |
Prado.WebUI.TRatingList.ratings[id].setReadOnly(value);
|
|
|
178 |
},
|
|
|
179 |
|
|
|
180 |
setRating : function(id,value)
|
|
|
181 |
{
|
|
|
182 |
Prado.WebUI.TRatingList.ratings[id].setRating(value);
|
|
|
183 |
},
|
|
|
184 |
|
|
|
185 |
setCaption : function(id,value)
|
|
|
186 |
{
|
|
|
187 |
Prado.WebUI.TRatingList.ratings[id].setCaption(value);
|
|
|
188 |
}
|
|
|
189 |
});
|
|
|
190 |
|
|
|
191 |
Prado.WebUI.TActiveRatingList = Prado.WebUI.TRatingList.extend(
|
|
|
192 |
{
|
|
|
193 |
dispatchRequest : function(ev)
|
|
|
194 |
{
|
|
|
195 |
var requestOptions = Object.extend(
|
|
|
196 |
{
|
|
|
197 |
ID : this.options.ListID+"_c"+this.selectedIndex,
|
|
|
198 |
EventTarget : this.options.ListName+"$c"+this.selectedIndex
|
|
|
199 |
},this.options);
|
|
|
200 |
var request = new Prado.CallbackRequest(requestOptions.EventTarget, requestOptions);
|
|
|
201 |
if(request.dispatch()==false)
|
|
|
202 |
Event.stop(ev);
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
});
|