Merge branch 'MDL-73386-400' of https://github.com/junpataleta/moodle into MOODLE_400...
[moodle.git] / mod / assign / module.js
blob9b7ad6b3c7e67e108294295e8ca5ba2f484689d8
1 M.mod_assign = {};
3 M.mod_assign.init_tree = function(Y, expand_all, htmlid) {
4     var treeElement = Y.one('#'+htmlid);
5     if (treeElement) {
6         Y.use('yui2-treeview', 'node-event-simulate', function(Y) {
7             var tree = new Y.YUI2.widget.TreeView(htmlid);
9             tree.subscribe("clickEvent", function(node, event) {
10                 // We want normal clicking which redirects to url.
11                 return false;
12             });
14             tree.subscribe("enterKeyPressed", function(node) {
15                 // We want keyboard activation to trigger a click on the first link.
16                 Y.one(node.getContentEl()).one('a').simulate('click');
17                 return false;
18             });
20             if (expand_all) {
21                 tree.expandAll();
22             }
23             tree.render();
24         });
25     }
28 M.mod_assign.init_grading_table = function(Y) {
29     Y.use('node', function(Y) {
30         checkboxes = Y.all('td.c0 input');
31         checkboxes.each(function(node) {
32             node.on('change', function(e) {
33                 rowelement = e.currentTarget.get('parentNode').get('parentNode');
34                 if (e.currentTarget.get('checked')) {
35                     rowelement.removeClass('unselectedrow');
36                     rowelement.addClass('selectedrow');
37                 } else {
38                     rowelement.removeClass('selectedrow');
39                     rowelement.addClass('unselectedrow');
40                 }
41             });
43             rowelement = node.get('parentNode').get('parentNode');
44             if (node.get('checked')) {
45                 rowelement.removeClass('unselectedrow');
46                 rowelement.addClass('selectedrow');
47             } else {
48                 rowelement.removeClass('selectedrow');
49                 rowelement.addClass('unselectedrow');
50             }
51         });
53         var selectall = Y.one('th.c0 input');
54         if (selectall) {
55             selectall.on('change', function(e) {
56                 if (e.currentTarget.get('checked')) {
57                     checkboxes = Y.all('td.c0 input[type="checkbox"]');
58                     checkboxes.each(function(node) {
59                         rowelement = node.get('parentNode').get('parentNode');
60                         node.set('checked', true);
61                         rowelement.removeClass('unselectedrow');
62                         rowelement.addClass('selectedrow');
63                     });
64                 } else {
65                     checkboxes = Y.all('td.c0 input[type="checkbox"]');
66                     checkboxes.each(function(node) {
67                         rowelement = node.get('parentNode').get('parentNode');
68                         node.set('checked', false);
69                         rowelement.removeClass('selectedrow');
70                         rowelement.addClass('unselectedrow');
71                     });
72                 }
73             });
74         }
76         var batchform = Y.one('form.gradingbatchoperationsform');
77         if (batchform) {
78             batchform.on('submit', function(e) {
79                 M.util.js_pending('mod_assign/module.js:batch:submit');
80                 checkboxes = Y.all('td.c0 input');
81                 var selectedusers = [];
82                 checkboxes.each(function(node) {
83                     if (node.get('checked')) {
84                         selectedusers[selectedusers.length] = node.get('value');
85                     }
86                 });
88                 operation = Y.one('#id_operation');
89                 usersinput = Y.one('input.selectedusers');
90                 usersinput.set('value', selectedusers.join(','));
91                 if (selectedusers.length == 0) {
92                     alert(M.util.get_string('nousersselected', 'assign'));
93                     e.preventDefault();
94                 } else {
95                     action = operation.get('value');
96                     prefix = 'plugingradingbatchoperation_';
97                     if (action.indexOf(prefix) == 0) {
98                         pluginaction = action.substr(prefix.length);
99                         plugin = pluginaction.split('_')[0];
100                         action = pluginaction.substr(plugin.length + 1);
101                         confirmmessage = M.util.get_string('batchoperationconfirm' + action, 'assignfeedback_' + plugin);
102                     } else {
103                         confirmmessage = M.util.get_string('batchoperationconfirm' + operation.get('value'), 'assign');
104                     }
105                     if (!confirm(confirmmessage)) {
106                         M.util.js_complete('mod_assign/module.js:batch:submit');
107                         e.preventDefault();
108                     }
109                     // Note: Do not js_complete. The page being reloaded will empty it.
110                 }
111             });
112         }
114         var quickgrade = Y.all('.gradingtable .quickgrade');
115         quickgrade.each(function(quick) {
116             quick.on('change', function(e) {
117                 this.get('parentNode').addClass('quickgrademodified');
118             });
119         });
120     });
123 M.mod_assign.init_grading_options = function(Y) {
124     Y.use('node', function(Y) {
125         var paginationelement = Y.one('#id_perpage');
126         paginationelement.on('change', function(e) {
127             Y.one('form.gradingoptionsform').submit();
128         });
129         var filterelement = Y.one('#id_filter');
130         if (filterelement) {
131             filterelement.on('change', function(e) {
132                 Y.one('form.gradingoptionsform').submit();
133             });
134         }
135         var markerfilterelement = Y.one('#id_markerfilter');
136         if (markerfilterelement) {
137             markerfilterelement.on('change', function(e) {
138                 Y.one('form.gradingoptionsform').submit();
139             });
140         }
141         var workflowfilterelement = Y.one('#id_workflowfilter');
142         if (workflowfilterelement) {
143             workflowfilterelement.on('change', function(e) {
144                 Y.one('form.gradingoptionsform').submit();
145             });
146         }
147         var quickgradingelement = Y.one('#id_quickgrading');
148         if (quickgradingelement) {
149             quickgradingelement.on('change', function(e) {
150                 Y.one('form.gradingoptionsform').submit();
151             });
152         }
153         var showonlyactiveenrolelement = Y.one('#id_showonlyactiveenrol');
154         if (showonlyactiveenrolelement) {
155             showonlyactiveenrolelement.on('change', function(e) {
156             Y.one('form.gradingoptionsform').submit();
157             });
158         }
159         var downloadasfolderselement = Y.one('#id_downloadasfolders');
160         if (downloadasfolderselement) {
161             downloadasfolderselement.on('change', function(e) {
162                 Y.one('form.gradingoptionsform').submit();
163             });
164         }
165     });
168 M.mod_assign.init_plugin_summary = function(Y, subtype, type, submissionid) {
169     var suffix = subtype + '_' + type + '_' + submissionid;
170     var classname = 'contract_' + suffix;
171     var contract = Y.one('.' + classname);
172     if (contract) {
173         contract.on('click', function(e) {
174             e.preventDefault();
175             var link = e.currentTarget || e.target;
176             var linkclasses = link.getAttribute('class').split(' ');
177             var thissuffix = '';
178             for (var i = 0; i < linkclasses.length; i++) {
179                 classname = linkclasses[i];
180                 if (classname.indexOf('contract_') == 0) {
181                     thissuffix = classname.substr(9);
182                 }
183             }
184             var fullclassname = 'full_' + thissuffix;
185             var full = Y.one('.' + fullclassname);
186             if (full) {
187                 full.hide(false);
188             }
189             var summaryclassname = 'summary_' + thissuffix;
190             var summary = Y.one('.' + summaryclassname);
191             if (summary) {
192                 summary.show(false);
193                 summary.one('a.expand_' + thissuffix).focus();
194             }
195         });
196     }
197     classname = 'expand_' + suffix;
198     var expand = Y.one('.' + classname);
200     var full = Y.one('.full_' + suffix);
201     if (full) {
202         full.hide(false);
203         full.toggleClass('hidefull');
204     }
205     if (expand) {
206         expand.on('click', function(e) {
207             e.preventDefault();
208             var link = e.currentTarget || e.target;
209             var linkclasses = link.getAttribute('class').split(' ');
210             var thissuffix = '';
211             for (var i = 0; i < linkclasses.length; i++) {
212                 classname = linkclasses[i];
213                 if (classname.indexOf('expand_') == 0) {
214                     thissuffix = classname.substr(7);
215                 }
216             }
217             var summaryclassname = 'summary_' + thissuffix;
218             var summary = Y.one('.' + summaryclassname);
219             if (summary) {
220                 summary.hide(false);
221             }
222             var fullclassname = 'full_' + thissuffix;
223             full = Y.one('.' + fullclassname);
224             if (full) {
225                 full.show(false);
226                 full.one('a.contract_' + thissuffix).focus();
227             }
228         });
229     }