MDL-29487 enrol: Fixed typo in enrol_sharing_course
[moodle.git] / rating / module.js
1 M.core_rating={
3     Y : null,
4     transaction : [],
6     init : function(Y){
7         this.Y = Y;
8         Y.all('select.postratingmenu').each(this.attach_rating_events, this);
10         //hide the submit buttons
11         this.Y.all('input.postratingmenusubmit').setStyle('display', 'none');
12     },
14     attach_rating_events : function(selectnode) {
15         selectnode.on('change', this.submit_rating, this, selectnode);
16     },
18     submit_rating : function(e, selectnode){
19         var theinputs = selectnode.ancestor('form').all('.ratinginput');
20         var thedata = [];
22         var inputssize = theinputs.size();
23         for ( var i=0; i<inputssize; i++ )
24         {
25             if(theinputs.item(i).get("name")!="returnurl") {//dont include return url for ajax requests
26                 thedata[theinputs.item(i).get("name")] = theinputs.item(i).get("value");
27             }
28         }
30         this.Y.io.queue.stop();
31         this.transaction.push({transaction:this.Y.io.queue(M.cfg.wwwroot+'/rating/rate_ajax.php', {
32             method : 'POST',
33             data : build_querystring(thedata),
34             on : {
35                 complete : function(tid, outcome, args) {
36                     try {
37                         if (!outcome) {
38                             alert('IO FATAL');
39                             return false;
40                         }
42                         var data = this.Y.JSON.parse(outcome.responseText);
43                         if (data.success){
44                             //if the user has access to the aggregate then update it
45                             if (data.itemid) { //do not test data.aggregate or data.count otherwise it doesn't refresh value=0 or no value
46                                 var itemid = data.itemid;
48                                 var node = this.Y.one('#ratingaggregate'+itemid);
49                                 node.set('innerHTML',data.aggregate);
51                                 //empty the count value if no ratings
52                                 var node = this.Y.one('#ratingcount'+itemid);
53                                 if (data.count > 0) {
54                                     node.set('innerHTML',"("+data.count+")");
55                                 } else {
56                                     node.set('innerHTML',"");
57                                 }
58                             }
59                             return true;
60                         }
61                         else if (data.error){
62                             alert(data.error);
63                         }
64                     } catch(e) {
65                         alert(e.message+" "+outcome.responseText);
66                     }
67                     return false;
68                 }
69             },
70             context : this,
71             arguments : {
72                 //query : this.query.get('value')
73             }
74         }),complete:false,outcome:null});
75         this.Y.io.queue.start();
76     }
77 };