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