forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.js
68 lines (59 loc) · 2.46 KB
/
module.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
M.core_rating={
Y : null,
transaction : [],
init : function(Y){
this.Y = Y;
Y.all('select.postratingmenu').each(this.attach_rating_events, this);
//hide the submit buttons
this.Y.all('input.postratingmenusubmit').setStyle('display', 'none');
},
attach_rating_events : function(selectnode) {
selectnode.on('change', this.submit_rating, this, selectnode);
},
submit_rating : function(e, selectnode){
var theinputs = selectnode.ancestor('form').all('.ratinginput')
var thedata = [];
var inputssize = theinputs.size();
for ( var i=0; i<inputssize; i++ )
{
if(theinputs.item(i).get("name")!="returnurl") {//dont include return url for ajax requests
thedata[theinputs.item(i).get("name")] = theinputs.item(i).get("value");
}
}
this.Y.io.queue.stop();
this.transaction.push({transaction:this.Y.io.queue(M.cfg.wwwroot+'/rating/rate_ajax.php', {
method : 'POST',
data : build_querystring(thedata),
on : {
complete : function(tid, outcome, args) {
try {
var responseobj = this.Y.JSON.parse(outcome.responseText);
var itemid = responseobj.itemid;
//if the user has access to the aggregate
if (responseobj.aggregate) {
var node = this.Y.one('#ratingaggregate'+itemid);
node.set('innerHTML',responseobj.aggregate);
var node = this.Y.one('#ratingcount'+itemid);
node.set('innerHTML',"("+responseobj.count+")");
}
} catch(e) {
//should put up an overlay or similar rather than an alert
alert(e.message+" "+outcome.responseText);
}
if(outcome.success){
//do nothing
}
else if (outcome.error){
//todo put up an overlay or similar rather than an alert
alert(outcome.error);
}
}
},
context : this,
arguments : {
//query : this.query.get('value')
}
}),complete:false,outcome:null});
this.Y.io.queue.start();
}
}