forked from pollen8/fabrik
-
Notifications
You must be signed in to change notification settings - Fork 381
/
list-rating.js
139 lines (126 loc) · 3.94 KB
/
list-rating.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
/**
* Ratings Element - List
*
* @copyright: Copyright (C) 2005-2013, fabrikar.com - All rights reserved.
* @license: GNU/GPL http://www.gnu.org/copyleft/gpl.html
*/
var FbRatingList = new Class({
options: {
'userid': 0,
'mode' : '',
'formid': 0
},
Implements: [Events, Options],
initialize: function (id, options) {
options.element = id;
this.setOptions(options);
if (this.options.mode === 'creator-rating') {
return;
}
this.col = $$('.' + id);
this.origRating = {};
this.col.each(function (tr) {
var stars = tr.getElements('.starRating');
stars.each(function (star) {
star.addEvent('mouseover', function (e) {
this.origRating[tr.id] = star.getParent('.fabrik_element').getElement('.ratingMessage').innerHTML.toInt();
stars.each(function (ii) {
if (this._getRating(star) >= this._getRating(ii)) {
if (Fabrik.bootstrapped) {
ii.removeClass('icon-star-empty').addClass('icon-star');
} else {
ii.src = this.options.insrc;
}
} else {
if (Fabrik.bootstrapped) {
ii.addClass('icon-star-empty').removeClass('icon-star');
} else {
ii.src = this.options.insrc;
}
}
}.bind(this));
star.getParent('.fabrik_element').getElement('.ratingMessage').innerHTML = star.get('data-fabrik-rating');
}.bind(this));
star.addEvent('mouseout', function (e) {
stars.each(function (ii) {
if (this.origRating[tr.id] >= this._getRating(ii)) {
if (Fabrik.bootstrapped) {
ii.removeClass('icon-star-empty').addClass('icon-star');
} else {
ii.src = this.options.insrc;
}
} else {
if (Fabrik.bootstrapped) {
ii.addClass('icon-star-empty').removeClass('icon-star');
} else {
ii.src = this.options.insrc;
}
}
}.bind(this));
star.getParent('.fabrik_element').getElement('.ratingMessage').innerHTML = this.origRating[tr.id];
}.bind(this));
}.bind(this));
stars.each(function (star) {
star.addEvent('click', function (e) {
this.doAjax(e, star);
}.bind(this));
}.bind(this));
}.bind(this));
},
_getRating: function (i) {
var r = i.get('data-fabrik-rating');
return r.toInt();
},
doAjax : function (e, star) {
e.stop();
this.rating = this._getRating(star);
var ratingmsg = star.getParent('.fabrik_element').getElement('.ratingMessage');
Fabrik.loader.start(ratingmsg);
var starRatingCover = new Element('div', {id: 'starRatingCover', styles: {bottom: 0, top: 0, right: 0, left: 0, position: 'absolute', cursor: 'progress'} });
var starRatingContainer = star.getParent('.fabrik_element').getElement('div');
starRatingContainer.grab(starRatingCover, 'top');
var row = document.id(star).getParent('.fabrik_row');
var rowid = row.id.replace('list_' + this.options.listRef + '_row_', '');
var data = {
'option': 'com_fabrik',
'format': 'raw',
'task': 'plugin.pluginAjax',
'plugin': 'rating',
'g': 'element',
'method': 'ajax_rate',
'formid': this.options.formid,
'element_id': this.options.elid,
'row_id' : rowid,
'elementname' : this.options.elid,
'userid' : this.options.userid,
'rating' : this.rating,
'mode' : this.options.mode
};
new Request({url: '',
'data': data,
onComplete: function (r) {
r = r.toInt();
this.rating = r;
ratingmsg.set('html', this.rating);
Fabrik.loader.stop(ratingmsg);
var tag = Fabrik.bootstrapped ? 'i' : 'img';
star.getParent('.fabrik_element').getElements(tag).each(function (i, x) {
if (x < r) {
if (Fabrik.bootstrapped) {
i.removeClass('icon-star-empty').addClass('icon-star');
} else {
i.src = this.options.insrc;
}
} else {
if (Fabrik.bootstrapped) {
i.addClass('icon-star-empty').removeClass('icon-star');
} else {
i.src = this.options.insrc;
}
}
}.bind(this));
document.id('starRatingCover').destroy();
}.bind(this)
}).send();
}
});