MDL-29509 move qeupgradehelper to admin tools
[moodle.git] / admin / report / spamcleaner / module.js
1 M.report_spamcleaner = {
2     Y: null,
3     row: null,
4     me: null,
6     del_all: function() {
7         var context = M.report_spamcleaner;
9         var yes = confirm(M.str.report_spamcleaner.spamdeleteallconfirm);
10         if (yes) {
11             var cfg = {
12                 method: "POST",
13                 on: {
14                     success : function(id, o, args) {
15                         try {
16                             var resp = context.Y.JSON.parse(o.responseText);
17                         } catch(e) {
18                             alert(M.str.report_spamcleaner.spaminvalidresult);
19                             return;
20                         }
21                         if (resp == true) {
22                             window.location.href=window.location.href;
23                         }
24                     }
25                 }
26             };
27             context.Y.io(context.me+'?delall=yes&sesskey='+M.cfg.sesskey, cfg);
28         }
29     },
31     del_user: function(obj, id) {
32         var context = M.report_spamcleaner;
34         if (context.Y == null) {
35             // not initialised yet
36             return;
37         }
39         var yes = confirm(M.str.report_spamcleaner.spamdeleteconfirm);
40         if (yes) {
41             context.row = obj;
42             var cfg = {
43                 method: "POST",
44                 on: {
45                     success : function(id, o, args) {
46                         try {
47                             var resp = context.Y.JSON.parse(o.responseText);
48                         } catch(e) {
49                             alert(M.str.report_spamcleaner.spaminvalidresult);
50                             return;
51                         }
52                         if (context.row) {
53                             if (resp == true) {
54                                 while(context.row.tagName != 'TR') {
55                                     context.row = context.row.parentNode;
56                                 }
57                                 context.row.parentNode.removeChild(context.row);
58                                 context.row = null;
59                             } else {
60                                 alert(M.str.report_spamcleaner.spamcannotdelete);
61                             }
62                         }
63                     }
64                 }
65             }
66             context.Y.io(context.me+'?del=yes&sesskey='+M.cfg.sesskey+'&id='+id, cfg);
67         }
68     },
70     ignore_user: function(obj, id) {
71         var context = M.report_spamcleaner;
73         if (context.Y == null) {
74             // not initilised yet
75             return;
76         }
78         context.row = obj;
79         var cfg = {
80             method: "POST",
81             on: {
82                 success : function(id, o, args) {
83                     try {
84                         var resp = context.Y.JSON.parse(o.responseText);
85                     } catch(e) {
86                         alert(M.str.report_spamcleaner.spaminvalidresult);
87                         return;
88                     }
89                     if (context.row) {
90                         if (resp == true){
91                             while(context.row.tagName != 'TR') {
92                                 context.row = context.row.parentNode;
93                             }
94                             context.row.parentNode.removeChild(context.row);
95                             context.row = null;
96                         }
97                     }
98                 }
99             }
100         }
101         context.Y.io(context.me+'?ignore=yes&sesskey='+M.cfg.sesskey+'&id='+id, cfg);
102     },
104     init: function(Y, me) {
105         var context = M.report_spamcleaner;
107         Y.use('json', 'io-base', function (Y) {
108             context.Y = Y;
109             context.me = me;
110             if (Y.one("#removeall_btn")) {
111                 Y.on("click", context.del_all, "#removeall_btn");
112             }
113         });
114     }