MDL-32895: Improvements to assignment upgrade tool for large numbers of assignments.
[moodle.git] / admin / tool / assignmentupgrade / module.js
CommitLineData
bbd0e548
DW
1
2M.tool_assignmentupgrade = {
3 init_upgrade_table: function(Y) {
4
5 Y.use('node', function(Y) {
6 checkboxes = Y.all('td.c0 input');
7 checkboxes.each(function(node) {
8 node.on('change', function(e) {
9 rowelement = e.currentTarget.get('parentNode').get('parentNode');
10 if (e.currentTarget.get('checked')) {
11 rowelement.setAttribute('class', 'selectedrow');
12 } else {
13 rowelement.setAttribute('class', 'unselectedrow');
14 }
15 });
16
17 rowelement = node.get('parentNode').get('parentNode');
18 if (node.get('checked')) {
19 rowelement.setAttribute('class', 'selectedrow');
20 } else {
21 rowelement.setAttribute('class', 'unselectedrow');
22 }
23 });
24 });
25
26 var selectall = Y.one('th.c0 input');
27 selectall.on('change', function(e) {
28 if (e.currentTarget.get('checked')) {
29 checkboxes = Y.all('td.c0 input');
30 checkboxes.each(function(node) {
31 rowelement = node.get('parentNode').get('parentNode');
32 node.set('checked', true);
33 rowelement.setAttribute('class', 'selectedrow');
34 });
35 } else {
36 checkboxes = Y.all('td.c0 input');
37 checkboxes.each(function(node) {
38 rowelement = node.get('parentNode').get('parentNode');
39 node.set('checked', false);
40 rowelement.setAttribute('class', 'unselectedrow');
41 });
42 }
43 });
44
45 var batchform = Y.one('.tool_assignmentupgrade_batchform form');
46 batchform.on('submit', function(e) {
47 checkboxes = Y.all('td.c0 input');
48 var selectedassignments = [];
49 checkboxes.each(function(node) {
50 if (node.get('checked')) {
51 selectedassignments[selectedassignments.length] = node.get('value');
52 }
53 });
54
55 operation = Y.one('#id_operation');
56 assignmentsinput = Y.one('input.selectedassignments');
57 assignmentsinput.set('value', selectedassignments.join(','));
58 if (selectedassignments.length == 0) {
59 alert(M.str.assign.noassignmentsselected);
60 e.preventDefault();
61 }
62 });
63
5b121144
DW
64 var perpage = Y.one('#id_perpage');
65 perpage.on('change', function(e) {
66 window.onbeforeunload = null;
67 Y.one('.tool_assignmentupgrade_paginationform form').submit();
68 });
bbd0e548
DW
69
70 }
71}