]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/Javascripts/source/prado/ratings/ratings.js
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / Javascripts / source / prado / ratings / ratings.js
1 Prado.WebUI.TRatingList = jQuery.klass(Prado.WebUI.Control,
2 {
3         selectedIndex : -1,
4         rating: -1,
5         readOnly : false,
6
7         onInit : function(options)
8         {
9                 var cap = $('#'+options.CaptionID).get(0);
10                 this.options = jQuery.extend(
11                 {
12                         caption : cap ? cap.innerHTML : ''
13                 }, options || {});
14
15                 this.radios = [];
16
17                 $('#'+options.ID).addClass(options.Style);
18                 for(var i = 0; i<options.ItemCount; i++)
19                 {
20                         var radio = $('#'+options.ID+"_c"+i).get(0);
21                         var td = radio.parentNode.parentNode;
22
23                         if(radio && td.tagName.toLowerCase()=='td')
24                         {
25                                 this.radios.push(radio);
26                                 $(td).addClass("rating");
27                         }
28                 }
29
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);
36         },
37
38         hover : function(index, ev)
39         {
40                 if(this.readOnly==true) return;
41
42                 for(var i = 0; i<this.radios.length; i++)
43                 {
44                         var node = this.radios[i].parentNode.parentNode;
45                         if(i <= index)
46                                 $(node).addClass('rating_hover');
47                         else
48                                 $(node).removeClass('rating_hover');
49                         $(node).removeClass("rating_selected");
50                         $(node).removeClass("rating_half");
51                 }
52                 this.showCaption(this.getIndexCaption(index));
53         },
54
55         recover : function(index, ev)
56         {
57                 if(this.readOnly==true) return;
58                 this.showRating(this.rating);
59                 this.showCaption(this.options.caption);
60         },
61
62         click : function(index, ev)
63         {
64                 if(this.readOnly==true) return;
65                 this.selectedIndex = index;
66                 this.setRating(index+1);
67
68                 if(this.options['AutoPostBack']==true){
69                         this.dispatchRequest(ev);
70                 }
71         },
72
73         dispatchRequest : function(ev)
74         {
75                 var requestOptions =jQuery.extend({}, this.options,
76                 {
77                         ID : this.options.ID+"_c"+this.selectedIndex,
78                         EventTarget : this.options.ListName+"$c"+this.selectedIndex
79                 });
80                 new Prado.PostBack(requestOptions, ev);
81         },
82
83         setRating : function(value)
84         {
85                 this.rating = 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);
92
93                 var caption = this.getIndexCaption(index);
94                 this.setCaption(caption);
95                 this.showCaption(caption);
96
97                 this.showRating(this.rating);
98         },
99
100         showRating: function(value)
101         {
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++)
109                 {
110                         var node = this.radios[i].parentNode.parentNode;
111                         if(i <= index)
112                                 $(node).addClass('rating_selected');
113                         else
114                                 $(node).removeClass('rating_selected');
115
116                         if(i==index+1 && hasHalf)
117                                 $(node).addClass("rating_half");
118                         else
119                                 $(node).removeClass("rating_half");
120                         $(node).removeClass("rating_hover");
121                 }
122         },
123
124         getIndexCaption : function(index)
125         {
126                 return index > -1 ? this.radios[index].value : this.options.caption;
127         },
128
129         showCaption : function(value)
130         {
131                 $('#'+this.options.CaptionID).html(value);
132                 $('#'+this.options.ID).attr( "title", value);
133         },
134
135         setCaption : function(value)
136         {
137                 this.options.caption = value;
138                 this.showCaption(value);
139         },
140
141         setReadOnly : function(value)
142         {
143                 this.readOnly = value;
144                 for(var i = 0; i<this.radios.length; i++)
145                 {
146                         var node = this.radios[i].parentNode.parentNode;
147                         if(value)
148                         {
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));
153                         } else {
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));
158                         }
159                 }
160
161                 this.showRating(this.rating);
162         }
163 });
164
165 Prado.WebUI.TActiveRatingList = jQuery.klass(Prado.WebUI.TRatingList,
166 {
167         dispatchRequest : function(ev)
168         {
169                 var requestOptions =jQuery.extend({}, this.options,
170                 {
171                         ID : this.options.ID+"_c"+this.selectedIndex,
172                         EventTarget : this.options.ListName+"$c"+this.selectedIndex
173                 });
174                 var request = new Prado.CallbackRequest(requestOptions.EventTarget, requestOptions);
175                 if(request.dispatch()==false)
176                         ev.preventDefault();
177         }
178
179 });