2010-04-01 20:33:15 +00:00
|
|
|
M.core_rating={
|
2010-03-16 05:57:51 +00:00
|
|
|
|
|
|
|
Y : null,
|
2011-09-21 14:54:32 +08:00
|
|
|
api: M.cfg.wwwroot+'/rating/rate_ajax.php',
|
2010-03-16 05:57:51 +00:00
|
|
|
|
|
|
|
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){
|
2010-09-17 19:46:57 +00:00
|
|
|
var theinputs = selectnode.ancestor('form').all('.ratinginput');
|
2010-03-16 05:57:51 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2010-09-17 19:46:57 +00:00
|
|
|
|
2011-09-21 14:54:32 +08:00
|
|
|
var scope = this;
|
|
|
|
var cfg = {
|
|
|
|
method: 'POST',
|
|
|
|
on: {
|
2010-03-16 05:57:51 +00:00
|
|
|
complete : function(tid, outcome, args) {
|
|
|
|
try {
|
2010-06-02 06:15:11 +00:00
|
|
|
if (!outcome) {
|
|
|
|
alert('IO FATAL');
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-22 05:15:23 +00:00
|
|
|
|
2011-09-21 14:54:32 +08:00
|
|
|
var data = scope.Y.JSON.parse(outcome.responseText);
|
2010-06-02 06:15:11 +00:00
|
|
|
if (data.success){
|
|
|
|
//if the user has access to the aggregate then update it
|
2010-08-17 07:18:10 +00:00
|
|
|
if (data.itemid) { //do not test data.aggregate or data.count otherwise it doesn't refresh value=0 or no value
|
2010-06-02 06:15:11 +00:00
|
|
|
var itemid = data.itemid;
|
2010-09-17 19:46:57 +00:00
|
|
|
|
2011-09-21 14:54:32 +08:00
|
|
|
var node = scope.Y.one('#ratingaggregate'+itemid);
|
2010-06-02 06:15:11 +00:00
|
|
|
node.set('innerHTML',data.aggregate);
|
2010-04-22 05:15:23 +00:00
|
|
|
|
2010-08-17 07:18:10 +00:00
|
|
|
//empty the count value if no ratings
|
2011-09-21 14:54:32 +08:00
|
|
|
var node = scope.Y.one('#ratingcount'+itemid);
|
2010-08-17 07:18:10 +00:00
|
|
|
if (data.count > 0) {
|
|
|
|
node.set('innerHTML',"("+data.count+")");
|
|
|
|
} else {
|
|
|
|
node.set('innerHTML',"");
|
|
|
|
}
|
2010-06-02 06:15:11 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (data.error){
|
|
|
|
alert(data.error);
|
2010-04-23 09:44:19 +00:00
|
|
|
}
|
2010-03-16 05:57:51 +00:00
|
|
|
} catch(e) {
|
2010-04-22 05:15:23 +00:00
|
|
|
alert(e.message+" "+outcome.responseText);
|
2010-03-16 05:57:51 +00:00
|
|
|
}
|
2010-06-02 06:15:11 +00:00
|
|
|
return false;
|
2010-03-16 05:57:51 +00:00
|
|
|
}
|
|
|
|
},
|
2011-09-21 14:54:32 +08:00
|
|
|
arguments: {
|
|
|
|
scope: scope
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
},
|
|
|
|
data: build_querystring(thedata)
|
|
|
|
};
|
|
|
|
this.Y.io(this.api, cfg);
|
|
|
|
|
2010-03-16 05:57:51 +00:00
|
|
|
}
|
2010-09-17 19:46:57 +00:00
|
|
|
};
|