mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
Merge branch 'MDL-29333_rating_ajax' of git://github.com/andyjdavis/moodle
This commit is contained in:
commit
2a8702c158
2 changed files with 21 additions and 24 deletions
|
@ -396,13 +396,6 @@ class rating_manager {
|
||||||
*/
|
*/
|
||||||
protected $scales = array();
|
protected $scales = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets set to true when the JavaScript that controls AJAX rating has been
|
|
||||||
* initialised (so that it only gets initialised once.
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $javascriptinitialised = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete one or more ratings. Specify either a rating id, an item id or just the context id.
|
* Delete one or more ratings. Specify either a rating id, an item id or just the context id.
|
||||||
*
|
*
|
||||||
|
@ -1019,15 +1012,17 @@ class rating_manager {
|
||||||
public function initialise_rating_javascript(moodle_page $page) {
|
public function initialise_rating_javascript(moodle_page $page) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
if ($this->javascriptinitialised) {
|
//only needs to be initialized once
|
||||||
|
static $done = false;
|
||||||
|
if ($done) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($CFG->enableajax)) {
|
if (!empty($CFG->enableajax)) {
|
||||||
$page->requires->js_init_call('M.core_rating.init');
|
$page->requires->js_init_call('M.core_rating.init');
|
||||||
}
|
}
|
||||||
|
$done = true;
|
||||||
|
|
||||||
$this->javascriptinitialised = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
M.core_rating={
|
M.core_rating={
|
||||||
|
|
||||||
Y : null,
|
Y : null,
|
||||||
transaction : [],
|
api: M.cfg.wwwroot+'/rating/rate_ajax.php',
|
||||||
|
|
||||||
init : function(Y){
|
init : function(Y){
|
||||||
this.Y = Y;
|
this.Y = Y;
|
||||||
|
@ -27,11 +27,10 @@ M.core_rating={
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Y.io.queue.stop();
|
var scope = this;
|
||||||
this.transaction.push({transaction:this.Y.io.queue(M.cfg.wwwroot+'/rating/rate_ajax.php', {
|
var cfg = {
|
||||||
method : 'POST',
|
method: 'POST',
|
||||||
data : build_querystring(thedata),
|
on: {
|
||||||
on : {
|
|
||||||
complete : function(tid, outcome, args) {
|
complete : function(tid, outcome, args) {
|
||||||
try {
|
try {
|
||||||
if (!outcome) {
|
if (!outcome) {
|
||||||
|
@ -39,17 +38,17 @@ M.core_rating={
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = this.Y.JSON.parse(outcome.responseText);
|
var data = scope.Y.JSON.parse(outcome.responseText);
|
||||||
if (data.success){
|
if (data.success){
|
||||||
//if the user has access to the aggregate then update it
|
//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
|
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 itemid = data.itemid;
|
||||||
|
|
||||||
var node = this.Y.one('#ratingaggregate'+itemid);
|
var node = scope.Y.one('#ratingaggregate'+itemid);
|
||||||
node.set('innerHTML',data.aggregate);
|
node.set('innerHTML',data.aggregate);
|
||||||
|
|
||||||
//empty the count value if no ratings
|
//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) {
|
if (data.count > 0) {
|
||||||
node.set('innerHTML',"("+data.count+")");
|
node.set('innerHTML',"("+data.count+")");
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,11 +66,14 @@ M.core_rating={
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
context : this,
|
arguments: {
|
||||||
arguments : {
|
scope: scope
|
||||||
//query : this.query.get('value')
|
},
|
||||||
}
|
headers: {
|
||||||
}),complete:false,outcome:null});
|
},
|
||||||
this.Y.io.queue.start();
|
data: build_querystring(thedata)
|
||||||
|
};
|
||||||
|
this.Y.io(this.api, cfg);
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Add table
Add a link
Reference in a new issue