Skip to content

Commit

Permalink
MDL-29333 rating: refactored the ratings ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjdavis committed Sep 21, 2011
1 parent 9cfaebb commit 5c0452c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions rating/module.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
M.core_rating={

Y : null,
transaction : [],
api: M.cfg.wwwroot+'/rating/rate_ajax.php',

init : function(Y){
this.Y = Y;
Expand All @@ -27,29 +27,28 @@ M.core_rating={
}
}

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 : {
var scope = this;
var cfg = {
method: 'POST',
on: {
complete : function(tid, outcome, args) {
try {
if (!outcome) {
alert('IO FATAL');
return false;
}

var data = this.Y.JSON.parse(outcome.responseText);
var data = scope.Y.JSON.parse(outcome.responseText);
if (data.success){
//if the user has access to the aggregate then update it
if (data.itemid) { //do not test data.aggregate or data.count otherwise it doesn't refresh value=0 or no value
var itemid = data.itemid;

var node = this.Y.one('#ratingaggregate'+itemid);
var node = scope.Y.one('#ratingaggregate'+itemid);
node.set('innerHTML',data.aggregate);

//empty the count value if no ratings
var node = this.Y.one('#ratingcount'+itemid);
var node = scope.Y.one('#ratingcount'+itemid);
if (data.count > 0) {
node.set('innerHTML',"("+data.count+")");
} else {
Expand All @@ -67,11 +66,14 @@ M.core_rating={
return false;
}
},
context : this,
arguments : {
//query : this.query.get('value')
}
}),complete:false,outcome:null});
this.Y.io.queue.start();
arguments: {
scope: scope
},
headers: {
},
data: build_querystring(thedata)
};
this.Y.io(this.api, cfg);

}
};

0 comments on commit 5c0452c

Please sign in to comment.