mongoid-letsrate 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -7
- data/lib/generators/mongoid_letsrate/mongoid_letsrate_generator.rb +1 -1
- data/lib/generators/mongoid_letsrate/templates/jquery.raty.js +454 -454
- data/lib/generators/mongoid_letsrate/templates/rater_controller.rb +2 -2
- data/lib/mongoid/letsrate/helpers.rb +2 -2
- data/lib/mongoid/letsrate/model.rb +1 -1
- data/lib/mongoid/letsrate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 074c706c0437cdd6bfa96e193dc8dd51981cd2df
|
4
|
+
data.tar.gz: 29d5427cdb2961d846ccbf1ab67d701005a82b2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb6a25a527a3e60c9b53ba5e6d0e0bd91e8a4da13f3764e440c76ec190e5cb82573182bb8eb5e39332b4123cc54369a368805272da17769bca3326cae5c979a0
|
7
|
+
data.tar.gz: 6eb10ddea4bf364375473495850f19449c8c8122b90577cd04a13cd4a43a73a3702cd17f4a4ae0fcbbebb6b5cb2e4ea049e8e2f7a4c42af7d9cb0a01a5ada747
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -23,11 +23,11 @@ gem 'mongoid-letsrate'
|
|
23
23
|
### Generate
|
24
24
|
|
25
25
|
```
|
26
|
-
rails g
|
26
|
+
rails g mongoid_letsrate User
|
27
27
|
```
|
28
28
|
|
29
|
-
The generator takes one argument which is the name of your existing devise user model UserModelName. This is necessary to bind the user and rating
|
30
|
-
Also the generator copies necessary files (jquery
|
29
|
+
The generator takes one argument which is the name of your existing devise user model UserModelName. This is necessary to bind the user and rating data.
|
30
|
+
Also the generator copies necessary files (jquery.raty plugin files, star icons and javascripts)
|
31
31
|
|
32
32
|
Example:
|
33
33
|
|
@@ -37,14 +37,14 @@ Suppose you will have a devise user model which name is User. The devise generat
|
|
37
37
|
rails g devise:install
|
38
38
|
rails g devise user
|
39
39
|
|
40
|
-
rails g
|
40
|
+
rails g mongoid_letsrate user # => user is the model generated by devise
|
41
41
|
```
|
42
42
|
|
43
|
-
This generator will create Rate and RatingCache models and link to your user model.
|
43
|
+
This generator will create Rate and RatingCache models and link them to your user model.
|
44
44
|
|
45
45
|
### Prepare
|
46
46
|
|
47
|
-
|
47
|
+
Suppose you have a car model
|
48
48
|
|
49
49
|
```
|
50
50
|
rails g model car name:string
|
@@ -56,6 +56,7 @@ You should add the letsrate_rateable function.
|
|
56
56
|
class Car
|
57
57
|
include Mongoid::Document
|
58
58
|
include Mongoid::Timestamps
|
59
|
+
include Mongoid::Letsrate
|
59
60
|
|
60
61
|
letsrate_rateable
|
61
62
|
end
|
@@ -66,6 +67,8 @@ Then you need to add a call letsrate_rater in the user model.
|
|
66
67
|
```ruby
|
67
68
|
class User
|
68
69
|
include Mongoid::Document
|
70
|
+
include Mongoid::Timestamps
|
71
|
+
include Mongoid::Letsrate
|
69
72
|
|
70
73
|
letsrate_rater
|
71
74
|
end
|
@@ -74,7 +77,7 @@ end
|
|
74
77
|
### Using
|
75
78
|
|
76
79
|
There is a helper method which name is rating_for to add the star links. By default rating_for will display the average rating and accept the
|
77
|
-
new rating value from authenticated
|
80
|
+
new rating value from authenticated users.
|
78
81
|
|
79
82
|
```erb
|
80
83
|
<%# show.html.erb -> /cars/1 %>
|
@@ -9,7 +9,6 @@ class MongoidLetsrateGenerator < Rails::Generators::NamedBase
|
|
9
9
|
copy_file 'star-off.png', 'app/assets/images/star-off.png'
|
10
10
|
copy_file 'star-half.png', 'app/assets/images/star-half.png'
|
11
11
|
copy_file 'letsrate.js.erb', 'app/assets/javascripts/letsrate.js.erb'
|
12
|
-
copy_file 'rater_controller.rb', 'app/controllers/rater_controller.rb'
|
13
12
|
end
|
14
13
|
|
15
14
|
desc 'model is being created...'
|
@@ -19,6 +18,7 @@ class MongoidLetsrateGenerator < Rails::Generators::NamedBase
|
|
19
18
|
class_collisions 'Rate'
|
20
19
|
template 'model.rb', File.join('app/models', 'rate.rb')
|
21
20
|
template 'cache_model.rb', File.join('app/models', 'rating_cache.rb')
|
21
|
+
template 'rater_controller.rb', File.join('app/controllers', 'rater_controller.rb')
|
22
22
|
end
|
23
23
|
|
24
24
|
def add_rate_path_to_route
|
@@ -1,464 +1,464 @@
|
|
1
1
|
/*!
|
2
|
-
* jQuery Raty - A Star Rating Plugin
|
3
|
-
* -------------------------------------------------------------------
|
4
|
-
*
|
5
|
-
* jQuery Raty is a plugin that generates a customizable star rating.
|
2
|
+
* jQuery Raty - A Star Rating Plugin
|
6
3
|
*
|
7
4
|
* Licensed under The MIT License
|
8
5
|
*
|
9
|
-
* @
|
10
|
-
* @
|
11
|
-
* @
|
12
|
-
* @documentation wbotelhos.com/raty
|
13
|
-
* @twitter twitter.com/wbotelhos
|
14
|
-
*
|
15
|
-
* Usage:
|
16
|
-
* -------------------------------------------------------------------
|
17
|
-
* $('#star').raty();
|
18
|
-
*
|
19
|
-
* <div id="star"></div>
|
6
|
+
* @author : Washington Botelho
|
7
|
+
* @doc : http://wbotelhos.com/raty
|
8
|
+
* @version : 2.5.2
|
20
9
|
*
|
21
10
|
*/
|
22
11
|
|
23
12
|
;(function($) {
|
24
13
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
$this.prepend(' ').prepend(self.cancel);
|
87
|
-
} else {
|
88
|
-
$this.append(' ').append(self.cancel);
|
89
|
-
}
|
90
|
-
|
91
|
-
width += (self.opt.size + space);
|
92
|
-
}
|
93
|
-
|
94
|
-
if (self.opt.readOnly) {
|
95
|
-
methods.fixHint.call(self);
|
96
|
-
|
97
|
-
if (self.cancel) {
|
98
|
-
self.cancel.hide();
|
99
|
-
}
|
100
|
-
} else {
|
101
|
-
$this.css('cursor', 'pointer');
|
14
|
+
var methods = {
|
15
|
+
init: function(settings) {
|
16
|
+
return this.each(function() {
|
17
|
+
methods.destroy.call(this);
|
18
|
+
|
19
|
+
this.opt = $.extend(true, {}, $.fn.raty.defaults, settings);
|
20
|
+
|
21
|
+
var that = $(this),
|
22
|
+
inits = ['number', 'readOnly', 'score', 'scoreName'];
|
23
|
+
|
24
|
+
methods._callback.call(this, inits);
|
25
|
+
|
26
|
+
if (this.opt.precision) {
|
27
|
+
methods._adjustPrecision.call(this);
|
28
|
+
}
|
29
|
+
|
30
|
+
this.opt.number = methods._between(this.opt.number, 0, this.opt.numberMax);
|
31
|
+
|
32
|
+
this.opt.path = this.opt.path || '';
|
33
|
+
|
34
|
+
if (this.opt.path && this.opt.path.charAt( this.opt.path.length - 1 ) !== '/') {
|
35
|
+
this.opt.path += '/';
|
36
|
+
}
|
37
|
+
|
38
|
+
this.stars = methods._createStars.call(this);
|
39
|
+
this.score = methods._createScore.call(this);
|
40
|
+
|
41
|
+
methods._apply.call(this, this.opt.score);
|
42
|
+
|
43
|
+
var space = this.opt.space ? 4 : 0,
|
44
|
+
width = this.opt.width || (this.opt.number * this.opt.size + this.opt.number * space);
|
45
|
+
|
46
|
+
if (this.opt.cancel) {
|
47
|
+
this.cancel = methods._createCancel.call(this);
|
48
|
+
|
49
|
+
width += (this.opt.size + space);
|
50
|
+
}
|
51
|
+
|
52
|
+
if (this.opt.readOnly) {
|
53
|
+
methods._lock.call(this);
|
54
|
+
} else {
|
55
|
+
that.css('cursor', 'pointer');
|
56
|
+
methods._binds.call(this);
|
57
|
+
}
|
58
|
+
|
59
|
+
if (this.opt.width !== false) {
|
60
|
+
that.css('width', width);
|
61
|
+
}
|
62
|
+
|
63
|
+
methods._target.call(this, this.opt.score);
|
64
|
+
|
65
|
+
that.data({ 'settings': this.opt, 'raty': true });
|
66
|
+
});
|
67
|
+
}, _adjustPrecision: function() {
|
68
|
+
this.opt.targetType = 'score';
|
69
|
+
this.opt.half = true;
|
70
|
+
}, _apply: function(score) {
|
71
|
+
if (score && score > 0) {
|
72
|
+
score = methods._between(score, 0, this.opt.number);
|
73
|
+
this.score.val(score);
|
74
|
+
}
|
102
75
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
76
|
+
methods._fill.call(this, score);
|
77
|
+
|
78
|
+
if (score) {
|
79
|
+
methods._roundStars.call(this, score);
|
80
|
+
}
|
81
|
+
}, _between: function(value, min, max) {
|
82
|
+
return Math.min(Math.max(parseFloat(value), min), max);
|
83
|
+
}, _binds: function() {
|
84
|
+
if (this.cancel) {
|
85
|
+
methods._bindCancel.call(this);
|
86
|
+
}
|
87
|
+
|
88
|
+
methods._bindClick.call(this);
|
89
|
+
methods._bindOut.call(this);
|
90
|
+
methods._bindOver.call(this);
|
91
|
+
}, _bindCancel: function() {
|
92
|
+
methods._bindClickCancel.call(this);
|
93
|
+
methods._bindOutCancel.call(this);
|
94
|
+
methods._bindOverCancel.call(this);
|
95
|
+
}, _bindClick: function() {
|
96
|
+
var self = this,
|
97
|
+
that = $(self);
|
98
|
+
|
99
|
+
self.stars.on('click.raty', function(evt) {
|
100
|
+
self.score.val((self.opt.half || self.opt.precision) ? that.data('score') : this.alt);
|
101
|
+
|
102
|
+
if (self.opt.click) {
|
103
|
+
self.opt.click.call(self, parseFloat(self.score.val()), evt);
|
104
|
+
}
|
105
|
+
});
|
106
|
+
}, _bindClickCancel: function() {
|
107
|
+
var self = this;
|
108
|
+
|
109
|
+
self.cancel.on('click.raty', function(evt) {
|
110
|
+
self.score.removeAttr('value');
|
111
|
+
|
112
|
+
if (self.opt.click) {
|
113
|
+
self.opt.click.call(self, null, evt);
|
114
|
+
}
|
115
|
+
});
|
116
|
+
}, _bindOut: function() {
|
117
|
+
var self = this;
|
118
|
+
|
119
|
+
$(this).on('mouseleave.raty', function(evt) {
|
120
|
+
var score = parseFloat(self.score.val()) || undefined;
|
121
|
+
|
122
|
+
methods._apply.call(self, score);
|
123
|
+
methods._target.call(self, score, evt);
|
124
|
+
|
125
|
+
if (self.opt.mouseout) {
|
126
|
+
self.opt.mouseout.call(self, score, evt);
|
127
|
+
}
|
128
|
+
});
|
129
|
+
}, _bindOutCancel: function() {
|
130
|
+
var self = this;
|
131
|
+
|
132
|
+
self.cancel.on('mouseleave.raty', function(evt) {
|
133
|
+
$(this).attr('src', self.opt.path + self.opt.cancelOff);
|
134
|
+
|
135
|
+
if (self.opt.mouseout) {
|
136
|
+
self.opt.mouseout.call(self, self.score.val() || null, evt);
|
137
|
+
}
|
138
|
+
});
|
139
|
+
}, _bindOverCancel: function() {
|
140
|
+
var self = this;
|
141
|
+
|
142
|
+
self.cancel.on('mouseover.raty', function(evt) {
|
143
|
+
$(this).attr('src', self.opt.path + self.opt.cancelOn);
|
144
|
+
|
145
|
+
self.stars.attr('src', self.opt.path + self.opt.starOff);
|
146
|
+
|
147
|
+
methods._target.call(self, null, evt);
|
148
|
+
|
149
|
+
if (self.opt.mouseover) {
|
150
|
+
self.opt.mouseover.call(self, null);
|
151
|
+
}
|
152
|
+
});
|
153
|
+
}, _bindOver: function() {
|
154
|
+
var self = this,
|
155
|
+
that = $(self),
|
156
|
+
action = self.opt.half ? 'mousemove.raty' : 'mouseover.raty';
|
157
|
+
|
158
|
+
self.stars.on(action, function(evt) {
|
159
|
+
var score = parseInt(this.alt, 10);
|
160
|
+
|
161
|
+
if (self.opt.half) {
|
162
|
+
var position = parseFloat((evt.pageX - $(this).offset().left) / self.opt.size),
|
163
|
+
plus = (position > .5) ? 1 : .5;
|
164
|
+
|
165
|
+
score = score - 1 + plus;
|
166
|
+
|
167
|
+
methods._fill.call(self, score);
|
168
|
+
|
169
|
+
if (self.opt.precision) {
|
170
|
+
score = score - plus + position;
|
171
|
+
}
|
172
|
+
|
173
|
+
methods._roundStars.call(self, score);
|
174
|
+
|
175
|
+
that.data('score', score);
|
176
|
+
} else {
|
177
|
+
methods._fill.call(self, score);
|
178
|
+
}
|
179
|
+
|
180
|
+
methods._target.call(self, score, evt);
|
181
|
+
|
182
|
+
if (self.opt.mouseover) {
|
183
|
+
self.opt.mouseover.call(self, score, evt);
|
184
|
+
}
|
185
|
+
});
|
186
|
+
}, _callback: function(options) {
|
187
|
+
for (var i in options) {
|
188
|
+
if (typeof this.opt[options[i]] === 'function') {
|
189
|
+
this.opt[options[i]] = this.opt[options[i]].call(this);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}, _createCancel: function() {
|
193
|
+
var that = $(this),
|
194
|
+
icon = this.opt.path + this.opt.cancelOff,
|
195
|
+
cancel = $('<img />', { src: icon, alt: 'x', title: this.opt.cancelHint, 'class': 'raty-cancel' });
|
196
|
+
|
197
|
+
if (this.opt.cancelPlace == 'left') {
|
198
|
+
that.prepend(' ').prepend(cancel);
|
199
|
+
} else {
|
200
|
+
that.append(' ').append(cancel);
|
201
|
+
}
|
202
|
+
|
203
|
+
return cancel;
|
204
|
+
}, _createScore: function() {
|
205
|
+
return $('<input />', { type: 'hidden', name: this.opt.scoreName }).appendTo(this);
|
206
|
+
}, _createStars: function() {
|
207
|
+
var that = $(this);
|
208
|
+
|
209
|
+
for (var i = 1; i <= this.opt.number; i++) {
|
210
|
+
var title = methods._getHint.call(this, i),
|
211
|
+
icon = (this.opt.score && this.opt.score >= i) ? 'starOn' : 'starOff';
|
212
|
+
|
213
|
+
icon = this.opt.path + this.opt[icon];
|
214
|
+
|
215
|
+
$('<img />', { src : icon, alt: i, title: title }).appendTo(this);
|
216
|
+
|
217
|
+
if (this.opt.space) {
|
218
|
+
that.append((i < this.opt.number) ? ' ' : '');
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
return that.children('img');
|
223
|
+
}, _error: function(message) {
|
224
|
+
$(this).html(message);
|
225
|
+
|
226
|
+
$.error(message);
|
227
|
+
}, _fill: function(score) {
|
228
|
+
var self = this,
|
229
|
+
hash = 0;
|
230
|
+
|
231
|
+
for (var i = 1; i <= self.stars.length; i++) {
|
232
|
+
var star = self.stars.eq(i - 1),
|
233
|
+
select = self.opt.single ? (i == score) : (i <= score);
|
234
|
+
|
235
|
+
if (self.opt.iconRange && self.opt.iconRange.length > hash) {
|
236
|
+
var irange = self.opt.iconRange[hash],
|
237
|
+
on = irange.on || self.opt.starOn,
|
238
|
+
off = irange.off || self.opt.starOff,
|
239
|
+
icon = select ? on : off;
|
240
|
+
|
241
|
+
if (i <= irange.range) {
|
242
|
+
star.attr('src', self.opt.path + icon);
|
243
|
+
}
|
244
|
+
|
245
|
+
if (i == irange.range) {
|
246
|
+
hash++;
|
247
|
+
}
|
248
|
+
} else {
|
249
|
+
var icon = select ? 'starOn' : 'starOff';
|
250
|
+
|
251
|
+
star.attr('src', this.opt.path + this.opt[icon]);
|
252
|
+
}
|
253
|
+
}
|
254
|
+
}, _getHint: function(score) {
|
255
|
+
var hint = this.opt.hints[score - 1];
|
256
|
+
return (hint === '') ? '' : (hint || score);
|
257
|
+
}, _lock: function() {
|
258
|
+
var score = parseInt(this.score.val(), 10), // TODO: 3.1 >> [['1'], ['2'], ['3', '.1', '.2']]
|
259
|
+
hint = score ? methods._getHint.call(this, score) : this.opt.noRatedMsg;
|
260
|
+
|
261
|
+
$(this).data('readonly', true).css('cursor', '').attr('title', hint);
|
262
|
+
|
263
|
+
this.score.attr('readonly', 'readonly');
|
264
|
+
this.stars.attr('title', hint);
|
265
|
+
|
266
|
+
if (this.cancel) {
|
267
|
+
this.cancel.hide();
|
268
|
+
}
|
269
|
+
}, _roundStars: function(score) {
|
270
|
+
var rest = (score - Math.floor(score)).toFixed(2);
|
271
|
+
|
272
|
+
if (rest > this.opt.round.down) {
|
273
|
+
var icon = 'starOn'; // Up: [x.76 .. x.99]
|
274
|
+
|
275
|
+
if (this.opt.halfShow && rest < this.opt.round.up) { // Half: [x.26 .. x.75]
|
276
|
+
icon = 'starHalf';
|
277
|
+
} else if (rest < this.opt.round.full) { // Down: [x.00 .. x.5]
|
278
|
+
icon = 'starOff';
|
279
|
+
}
|
280
|
+
|
281
|
+
this.stars.eq(Math.ceil(score) - 1).attr('src', this.opt.path + this.opt[icon]);
|
282
|
+
} // Full down: [x.00 .. x.25]
|
283
|
+
}, _target: function(score, evt) {
|
284
|
+
if (this.opt.target) {
|
285
|
+
var target = $(this.opt.target);
|
286
|
+
|
287
|
+
if (target.length === 0) {
|
288
|
+
methods._error.call(this, 'Target selector invalid or missing!');
|
289
|
+
}
|
290
|
+
|
291
|
+
if (this.opt.targetFormat.indexOf('{score}') < 0) {
|
292
|
+
methods._error.call(this, 'Template "{score}" missing!');
|
293
|
+
}
|
294
|
+
|
295
|
+
var mouseover = evt && evt.type == 'mouseover';
|
296
|
+
|
297
|
+
if (score === undefined) {
|
298
|
+
score = this.opt.targetText;
|
299
|
+
} else if (score === null) {
|
300
|
+
score = mouseover ? this.opt.cancelHint : this.opt.targetText;
|
301
|
+
} else {
|
302
|
+
if (this.opt.targetType == 'hint') {
|
303
|
+
score = methods._getHint.call(this, Math.ceil(score));
|
304
|
+
} else if (this.opt.precision) {
|
305
|
+
score = parseFloat(score).toFixed(1);
|
306
|
+
}
|
307
|
+
|
308
|
+
if (!mouseover && !this.opt.targetKeep) {
|
309
|
+
score = this.opt.targetText;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
if (score) {
|
314
|
+
score = this.opt.targetFormat.toString().replace('{score}', score);
|
315
|
+
}
|
316
|
+
|
317
|
+
if (target.is(':input')) {
|
318
|
+
target.val(score);
|
319
|
+
} else {
|
320
|
+
target.html(score);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}, _unlock: function() {
|
324
|
+
$(this).data('readonly', false).css('cursor', 'pointer').removeAttr('title');
|
325
|
+
|
326
|
+
this.score.removeAttr('readonly', 'readonly');
|
327
|
+
|
328
|
+
for (var i = 0; i < this.opt.number; i++) {
|
329
|
+
this.stars.eq(i).attr('title', methods._getHint.call(this, i + 1));
|
330
|
+
}
|
331
|
+
|
332
|
+
if (this.cancel) {
|
333
|
+
this.cancel.css('display', '');
|
334
|
+
}
|
335
|
+
}, cancel: function(click) {
|
336
|
+
return this.each(function() {
|
337
|
+
if ($(this).data('readonly') !== true) {
|
338
|
+
methods[click ? 'click' : 'score'].call(this, null);
|
339
|
+
this.score.removeAttr('value');
|
340
|
+
}
|
341
|
+
});
|
342
|
+
}, click: function(score) {
|
343
|
+
return $(this).each(function() {
|
344
|
+
if ($(this).data('readonly') !== true) {
|
345
|
+
methods._apply.call(this, score);
|
346
|
+
|
347
|
+
if (!this.opt.click) {
|
348
|
+
methods._error.call(this, 'You must add the "click: function(score, evt) { }" callback.');
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
this.opt.click.call(this, score, $.Event('click'));
|
353
|
+
|
354
|
+
methods._target.call(this, score);
|
355
|
+
}
|
356
|
+
});
|
357
|
+
}, destroy: function() {
|
358
|
+
return $(this).each(function() {
|
359
|
+
var that = $(this),
|
360
|
+
raw = that.data('raw');
|
361
|
+
|
362
|
+
if (raw) {
|
363
|
+
that.off('.raty').empty().css({ cursor: raw.style.cursor, width: raw.style.width }).removeData('readonly');
|
364
|
+
} else {
|
365
|
+
that.data('raw', that.clone()[0]);
|
366
|
+
}
|
367
|
+
});
|
368
|
+
}, getScore: function() {
|
369
|
+
var score = [],
|
370
|
+
value ;
|
371
|
+
|
372
|
+
$(this).each(function() {
|
373
|
+
value = this.score.val();
|
374
|
+
|
375
|
+
score.push(value ? parseFloat(value) : undefined);
|
376
|
+
});
|
377
|
+
|
378
|
+
return (score.length > 1) ? score : score[0];
|
379
|
+
}, readOnly: function(readonly) {
|
380
|
+
return this.each(function() {
|
381
|
+
var that = $(this);
|
382
|
+
|
383
|
+
if (that.data('readonly') !== readonly) {
|
384
|
+
if (readonly) {
|
385
|
+
that.off('.raty').children('img').off('.raty');
|
386
|
+
|
387
|
+
methods._lock.call(this);
|
388
|
+
} else {
|
389
|
+
methods._binds.call(this);
|
390
|
+
methods._unlock.call(this);
|
391
|
+
}
|
392
|
+
|
393
|
+
that.data('readonly', readonly);
|
394
|
+
}
|
395
|
+
});
|
396
|
+
}, reload: function() {
|
397
|
+
return methods.set.call(this, {});
|
398
|
+
}, score: function() {
|
399
|
+
return arguments.length ? methods.setScore.apply(this, arguments) : methods.getScore.call(this);
|
400
|
+
}, set: function(settings) {
|
401
|
+
return this.each(function() {
|
402
|
+
var that = $(this),
|
403
|
+
actual = that.data('settings'),
|
404
|
+
news = $.extend({}, actual, settings);
|
405
|
+
|
406
|
+
that.raty(news);
|
407
|
+
});
|
408
|
+
}, setScore: function(score) {
|
409
|
+
return $(this).each(function() {
|
410
|
+
if ($(this).data('readonly') !== true) {
|
411
|
+
methods._apply.call(this, score);
|
412
|
+
methods._target.call(this, score);
|
413
|
+
}
|
414
|
+
});
|
415
|
+
}
|
416
|
+
};
|
417
|
+
|
418
|
+
$.fn.raty = function(method) {
|
419
|
+
if (methods[method]) {
|
420
|
+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
421
|
+
} else if (typeof method === 'object' || !method) {
|
422
|
+
return methods.init.apply(this, arguments);
|
423
|
+
} else {
|
424
|
+
$.error('Method ' + method + ' does not exist!');
|
425
|
+
}
|
426
|
+
};
|
427
|
+
|
428
|
+
$.fn.raty.defaults = {
|
429
|
+
cancel : false,
|
430
|
+
cancelHint : 'Cancel this rating!',
|
431
|
+
cancelOff : 'cancel-off.png',
|
432
|
+
cancelOn : 'cancel-on.png',
|
433
|
+
cancelPlace : 'left',
|
434
|
+
click : undefined,
|
435
|
+
half : false,
|
436
|
+
halfShow : true,
|
437
|
+
hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'],
|
438
|
+
iconRange : undefined,
|
439
|
+
mouseout : undefined,
|
440
|
+
mouseover : undefined,
|
441
|
+
noRatedMsg : 'Not rated yet!',
|
442
|
+
number : 5,
|
443
|
+
numberMax : 20,
|
444
|
+
path : '',
|
445
|
+
precision : false,
|
446
|
+
readOnly : false,
|
447
|
+
round : { down: .25, full: .6, up: .76 },
|
448
|
+
score : undefined,
|
449
|
+
scoreName : 'score',
|
450
|
+
single : false,
|
451
|
+
size : 16,
|
452
|
+
space : true,
|
453
|
+
starHalf : 'star-half.png',
|
454
|
+
starOff : 'star-off.png',
|
455
|
+
starOn : 'star-on.png',
|
456
|
+
target : undefined,
|
457
|
+
targetFormat : '{score}',
|
458
|
+
targetKeep : false,
|
459
|
+
targetText : '',
|
460
|
+
targetType : 'hint',
|
461
|
+
width : undefined
|
462
|
+
};
|
463
|
+
|
464
|
+
})(jQuery);
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
class RaterController < ApplicationController
|
3
3
|
def create
|
4
|
-
if
|
4
|
+
if <%= file_name %>_signed_in?
|
5
5
|
obj = params[:klass].classify.constantize.find(params[:id])
|
6
|
-
obj.rate params[:score].to_i,
|
6
|
+
obj.rate params[:score].to_i, current_<%= file_name %>
|
7
7
|
|
8
8
|
render :json => true
|
9
9
|
else
|
@@ -8,7 +8,7 @@ module Helpers
|
|
8
8
|
|
9
9
|
star = options[:star] || 5
|
10
10
|
|
11
|
-
disable_after_rate = options[:disable_after_rate]
|
11
|
+
disable_after_rate = options[:disable_after_rate].nil? ? true : options[:disable_after_rate]
|
12
12
|
|
13
13
|
readonly = !(current_user && rateable_obj.can_rate?(current_user))
|
14
14
|
|
@@ -25,7 +25,7 @@ module Helpers
|
|
25
25
|
@rating = Rate.find_by_rater_id_and_rateable_id(@user.id, @object.id)
|
26
26
|
stars = @rating ? @rating.stars : 0
|
27
27
|
|
28
|
-
disable_after_rate = options[:disable_after_rate]
|
28
|
+
disable_after_rate = options[:disable_after_rate].nil? ? true : options[:disable_after_rate]
|
29
29
|
|
30
30
|
readonly=false
|
31
31
|
if disable_after_rate
|
@@ -73,7 +73,7 @@ module Mongoid
|
|
73
73
|
|
74
74
|
def letsrate_rateable
|
75
75
|
has_many :rates, :as => :rateable, :class_name => 'Rate', :dependent => :destroy
|
76
|
-
has_many :raters
|
76
|
+
has_many :raters, class_name: 'User'
|
77
77
|
|
78
78
|
has_one :average, :as => :cacheable,
|
79
79
|
:class_name => 'RatingCache', :dependent => :destroy
|