1 Prado.WebUI.TRatingList = jQuery.klass(Prado.WebUI.Control,
7 onInit : function(options)
9 var cap = $('#'+options.CaptionID).get(0);
10 this.options = jQuery.extend(
12 caption : cap ? cap.innerHTML : ''
17 $('#'+options.ID).addClass(options.Style);
18 for(var i = 0; i<options.ItemCount; i++)
20 var radio = $('#'+options.ID+"_c"+i).get(0);
21 var td = radio.parentNode.parentNode;
23 if(radio && td.tagName.toLowerCase()=='td')
25 this.radios.push(radio);
26 $(td).addClass("rating");
30 this.selectedIndex = options.SelectedIndex;
31 this.rating = options.Rating;
32 this.readOnly = options.ReadOnly
33 if(options.Rating <= 0 && options.SelectedIndex >= 0)
34 this.rating = options.SelectedIndex+1;
35 this.setReadOnly(this.readOnly);
38 hover : function(index, ev)
40 if(this.readOnly==true) return;
42 for(var i = 0; i<this.radios.length; i++)
44 var node = this.radios[i].parentNode.parentNode;
46 $(node).addClass('rating_hover');
48 $(node).removeClass('rating_hover');
49 $(node).removeClass("rating_selected");
50 $(node).removeClass("rating_half");
52 this.showCaption(this.getIndexCaption(index));
55 recover : function(index, ev)
57 if(this.readOnly==true) return;
58 this.showRating(this.rating);
59 this.showCaption(this.options.caption);
62 click : function(index, ev)
64 if(this.readOnly==true) return;
65 this.selectedIndex = index;
66 this.setRating(index+1);
68 if(this.options['AutoPostBack']==true){
69 this.dispatchRequest(ev);
73 dispatchRequest : function(ev)
75 var requestOptions =jQuery.extend({}, this.options,
77 ID : this.options.ID+"_c"+this.selectedIndex,
78 EventTarget : this.options.ListName+"$c"+this.selectedIndex
80 new Prado.PostBack(requestOptions, ev);
83 setRating : function(value)
86 var base = Math.floor(value-1);
87 var remainder = value - base-1;
88 var halfMax = this.options.HalfRating["1"];
89 var index = remainder > halfMax ? base+1 : base;
90 for(var i = 0; i<this.radios.length; i++)
91 this.radios[i].checked = (i == index);
93 var caption = this.getIndexCaption(index);
94 this.setCaption(caption);
95 this.showCaption(caption);
97 this.showRating(this.rating);
100 showRating: function(value)
102 var base = Math.floor(value-1);
103 var remainder = value - base-1;
104 var halfMin = this.options.HalfRating["0"];
105 var halfMax = this.options.HalfRating["1"];
106 var index = remainder > halfMax ? base+1 : base;
107 var hasHalf = remainder >= halfMin && remainder <= halfMax;
108 for(var i = 0; i<this.radios.length; i++)
110 var node = this.radios[i].parentNode.parentNode;
112 $(node).addClass('rating_selected');
114 $(node).removeClass('rating_selected');
116 if(i==index+1 && hasHalf)
117 $(node).addClass("rating_half");
119 $(node).removeClass("rating_half");
120 $(node).removeClass("rating_hover");
124 getIndexCaption : function(index)
126 return index > -1 ? this.radios[index].value : this.options.caption;
129 showCaption : function(value)
131 $('#'+this.options.CaptionID).html(value);
132 $('#'+this.options.ID).attr( "title", value);
135 setCaption : function(value)
137 this.options.caption = value;
138 this.showCaption(value);
141 setReadOnly : function(value)
143 this.readOnly = value;
144 for(var i = 0; i<this.radios.length; i++)
146 var node = this.radios[i].parentNode.parentNode;
149 $(node).addClass('rating_disabled');
150 $(node).off('mouseover', jQuery.proxy(this.hover, this, i));
151 $(node).off('mouseout', jQuery.proxy(this.recover, this, i));
152 $(node).off('click', jQuery.proxy(this.click, this, i));
154 $(node).removeClass('rating_disabled');
155 $(node).on('mouseover', jQuery.proxy(this.hover, this, i));
156 $(node).on('mouseout', jQuery.proxy(this.recover, this, i));
157 $(node).on('click', jQuery.proxy(this.click, this, i));
161 this.showRating(this.rating);
165 Prado.WebUI.TActiveRatingList = jQuery.klass(Prado.WebUI.TRatingList,
167 dispatchRequest : function(ev)
169 var requestOptions =jQuery.extend({}, this.options,
171 ID : this.options.ID+"_c"+this.selectedIndex,
172 EventTarget : this.options.ListName+"$c"+this.selectedIndex
174 var request = new Prado.CallbackRequest(requestOptions.EventTarget, requestOptions);
175 if(request.dispatch()==false)