Merge branch 'MDL-62983-master' of git://github.com/sarjona/moodle
[moodle.git] / mod / assign / module.js
blobc37dedf113bfcfa09e3cac297e952e30112b90fe
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', 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             if (expand_all) {
15                 tree.expandAll();
16             }
17             tree.render();
18         });
19     }
22 M.mod_assign.init_grading_table = function(Y) {
23     Y.use('node', function(Y) {
24         checkboxes = Y.all('td.c0 input');
25         checkboxes.each(function(node) {
26             node.on('change', function(e) {
27                 rowelement = e.currentTarget.get('parentNode').get('parentNode');
28                 if (e.currentTarget.get('checked')) {
29                     rowelement.removeClass('unselectedrow');
30                     rowelement.addClass('selectedrow');
31                 } else {
32                     rowelement.removeClass('selectedrow');
33                     rowelement.addClass('unselectedrow');
34                 }
35             });
37             rowelement = node.get('parentNode').get('parentNode');
38             if (node.get('checked')) {
39                 rowelement.removeClass('unselectedrow');
40                 rowelement.addClass('selectedrow');
41             } else {
42                 rowelement.removeClass('selectedrow');
43                 rowelement.addClass('unselectedrow');
44             }
45         });
47         var selectall = Y.one('th.c0 input');
48         if (selectall) {
49             selectall.on('change', function(e) {
50                 if (e.currentTarget.get('checked')) {
51                     checkboxes = Y.all('td.c0 input[type="checkbox"]');
52                     checkboxes.each(function(node) {
53                         rowelement = node.get('parentNode').get('parentNode');
54                         node.set('checked', true);
55                         rowelement.removeClass('unselectedrow');
56                         rowelement.addClass('selectedrow');
57                     });
58                 } else {
59                     checkboxes = Y.all('td.c0 input[type="checkbox"]');
60                     checkboxes.each(function(node) {
61                         rowelement = node.get('parentNode').get('parentNode');
62                         node.set('checked', false);
63                         rowelement.removeClass('selectedrow');
64                         rowelement.addClass('unselectedrow');
65                     });
66                 }
67             });
68         }
70         var batchform = Y.one('form.gradingbatchoperationsform');
71         if (batchform) {
72             batchform.on('submit', function(e) {
73                 checkboxes = Y.all('td.c0 input');
74                 var selectedusers = [];
75                 checkboxes.each(function(node) {
76                     if (node.get('checked')) {
77                         selectedusers[selectedusers.length] = node.get('value');
78                     }
79                 });
81                 operation = Y.one('#id_operation');
82                 usersinput = Y.one('input.selectedusers');
83                 usersinput.set('value', selectedusers.join(','));
84                 if (selectedusers.length == 0) {
85                     alert(M.util.get_string('nousersselected', 'assign'));
86                     e.preventDefault();
87                 } else {
88                     action = operation.get('value');
89                     prefix = 'plugingradingbatchoperation_';
90                     if (action.indexOf(prefix) == 0) {
91                         pluginaction = action.substr(prefix.length);
92                         plugin = pluginaction.split('_')[0];
93                         action = pluginaction.substr(plugin.length + 1);
94                         confirmmessage = M.util.get_string('batchoperationconfirm' + action, 'assignfeedback_' + plugin);
95                     } else {
96                         confirmmessage = M.util.get_string('batchoperationconfirm' + operation.get('value'), 'assign');
97                     }
98                     if (!confirm(confirmmessage)) {
99                         e.preventDefault();
100                     }
101                 }
102             });
103         }
105         var quickgrade = Y.all('.gradingtable .quickgrade');
106         quickgrade.each(function(quick) {
107             quick.on('change', function(e) {
108                 this.get('parentNode').addClass('quickgrademodified');
109             });
110         });
111     });
114 M.mod_assign.init_grading_options = function(Y) {
115     Y.use('node', function(Y) {
116         var paginationelement = Y.one('#id_perpage');
117         paginationelement.on('change', function(e) {
118             Y.one('form.gradingoptionsform').submit();
119         });
120         var filterelement = Y.one('#id_filter');
121         if (filterelement) {
122             filterelement.on('change', function(e) {
123                 Y.one('form.gradingoptionsform').submit();
124             });
125         }
126         var markerfilterelement = Y.one('#id_markerfilter');
127         if (markerfilterelement) {
128             markerfilterelement.on('change', function(e) {
129                 Y.one('form.gradingoptionsform').submit();
130             });
131         }
132         var workflowfilterelement = Y.one('#id_workflowfilter');
133         if (workflowfilterelement) {
134             workflowfilterelement.on('change', function(e) {
135                 Y.one('form.gradingoptionsform').submit();
136             });
137         }
138         var quickgradingelement = Y.one('#id_quickgrading');
139         if (quickgradingelement) {
140             quickgradingelement.on('change', function(e) {
141                 Y.one('form.gradingoptionsform').submit();
142             });
143         }
144         var showonlyactiveenrolelement = Y.one('#id_showonlyactiveenrol');
145         if (showonlyactiveenrolelement) {
146             showonlyactiveenrolelement.on('change', function(e) {
147             Y.one('form.gradingoptionsform').submit();
148             });
149         }
150         var downloadasfolderselement = Y.one('#id_downloadasfolders');
151         if (downloadasfolderselement) {
152             downloadasfolderselement.on('change', function(e) {
153                 Y.one('form.gradingoptionsform').submit();
154             });
155         }
156     });
159 M.mod_assign.init_plugin_summary = function(Y, subtype, type, submissionid) {
160     suffix = subtype + '_' + type + '_' + submissionid;
161     classname = 'contract_' + suffix;
162     contract = Y.one('.' + classname);
163     if (contract) {
164         contract.on('click', function(e) {
165             img = e.target;
166             imgclasses = img.getAttribute('class').split(' ');
167             for (i = 0; i < imgclasses.length; i++) {
168                 classname = imgclasses[i];
169                 if (classname.indexOf('contract_') == 0) {
170                     thissuffix = classname.substr(9);
171                 }
172             }
173             fullclassname = 'full_' + thissuffix;
174             full = Y.one('.' + fullclassname);
175             if (full) {
176                 full.hide(false);
177             }
178             summaryclassname = 'summary_' + thissuffix;
179             summary = Y.one('.' + summaryclassname);
180             if (summary) {
181                 summary.show(false);
182             }
183         });
184     }
185     classname = 'expand_' + suffix;
186     expand = Y.one('.' + classname);
188     full = Y.one('.full_' + suffix);
189     if (full) {
190         full.hide(false);
191         full.toggleClass('hidefull');
192     }
193     if (expand) {
194         expand.on('click', function(e) {
195             img = e.target;
196             imgclasses = img.getAttribute('class').split(' ');
197             for (i = 0; i < imgclasses.length; i++) {
198                 classname = imgclasses[i];
199                 if (classname.indexOf('expand_') == 0) {
200                     thissuffix = classname.substr(7);
201                 }
202             }
203             summaryclassname = 'summary_' + thissuffix;
204             summary = Y.one('.' + summaryclassname);
205             if (summary) {
206                 summary.hide(false);
207             }
208             fullclassname = 'full_' + thissuffix;
209             full = Y.one('.' + fullclassname);
210             if (full) {
211                 full.show(false);
212             }
213         });
214     }