Merge branch 'MDL-33843' of git://github.com/netspotau/moodle-mod_assign
[moodle.git] / mod / assign / module.js
1 M.mod_assign = {};
3 M.mod_assign.init_tree = function(Y, expand_all, htmlid) {
4     Y.use('yui2-treeview', function(Y) {
5         var tree = new YAHOO.widget.TreeView(htmlid);
7         tree.subscribe("clickEvent", function(node, event) {
8             // we want normal clicking which redirects to url
9             return false;
10         });
12         if (expand_all) {
13             tree.expandAll();
14         }
15         tree.render();
16     });
17 };
20 M.mod_assign.init_grading_table = function(Y) {
21     Y.use('node', function(Y) {
22         checkboxes = Y.all('td.c0 input');
23         checkboxes.each(function(node) {
24             node.on('change', function(e) {
25                 rowelement = e.currentTarget.get('parentNode').get('parentNode');
26                 if (e.currentTarget.get('checked')) {
27                     rowelement.setAttribute('class', 'selectedrow');
28                 } else {
29                     rowelement.setAttribute('class', 'unselectedrow');
30                 }
31             });
33             rowelement = node.get('parentNode').get('parentNode');
34             if (node.get('checked')) {
35                 rowelement.setAttribute('class', 'selectedrow');
36             } else {
37                 rowelement.setAttribute('class', 'unselectedrow');
38             }
39         });
41         var selectall = Y.one('th.c0 input');
42         if (selectall) {
43             selectall.on('change', function(e) {
44                 if (e.currentTarget.get('checked')) {
45                     checkboxes = Y.all('td.c0 input');
46                     checkboxes.each(function(node) {
47                         rowelement = node.get('parentNode').get('parentNode');
48                         node.set('checked', true);
49                         rowelement.setAttribute('class', 'selectedrow');
50                     });
51                 } else {
52                     checkboxes = Y.all('td.c0 input');
53                     checkboxes.each(function(node) {
54                         rowelement = node.get('parentNode').get('parentNode');
55                         node.set('checked', false);
56                         rowelement.setAttribute('class', 'unselectedrow');
57                     });
58                 }
59             });
60         }
62         var batchform = Y.one('form.gradingbatchoperationsform');
63         batchform.on('submit', function(e) {
64             checkboxes = Y.all('td.c0 input');
65             var selectedusers = [];
66             checkboxes.each(function(node) {
67                 if (node.get('checked')) {
68                     selectedusers[selectedusers.length] = node.get('value');
69                 }
70             });
72             operation = Y.one('#id_operation');
73             usersinput = Y.one('input.selectedusers');
74             usersinput.set('value', selectedusers.join(','));
75             if (selectedusers.length == 0) {
76                 alert(M.str.assign.nousersselected);
77                 e.preventDefault();
78             } else {
79                 if (!confirm(eval('M.str.assign.batchoperationconfirm' + operation.get('value')))) {
80                     e.preventDefault();
81                 }
82             }
83         });
86         Y.use('node-menunav', function(Y) {
87             var menus = Y.all('.gradingtable .actionmenu');
89             menus.each(function(menu) {
90                 Y.on("contentready", function() {
91                     this.plug(Y.Plugin.NodeMenuNav, {autoSubmenuDisplay: true});
92                     var submenus = this.all('.yui3-loading');
93                     submenus.each(function (n) {
94                         n.removeClass('yui3-loading');
95                     });
97                 }, "#" + menu.getAttribute('id'));
100             });
103         });
104         var quickgrade = Y.all('.gradingtable .quickgrade');
105         quickgrade.each(function(quick) {
106             quick.on('change', function(e) {
107                 this.get('parentNode').addClass('quickgrademodified');
108             });
109         });
110     });
111 };
113 M.mod_assign.init_grading_options = function(Y) {
114     Y.use('node', function(Y) {
115         var paginationelement = Y.one('#id_perpage');
116         paginationelement.on('change', function(e) {
117             Y.one('form.gradingoptionsform').submit();
118         });
119         var filterelement = Y.one('#id_filter');
120         filterelement.on('change', function(e) {
121             Y.one('form.gradingoptionsform').submit();
122         });
123         var quickgradingelement = Y.one('#id_quickgrading');
124         if (quickgradingelement) {
125             quickgradingelement.on('change', function(e) {
126                 Y.one('form.gradingoptionsform').submit();
127             });
128         }
129     });
130 };