MDL-65087 message: add button role to action links on bootstrapbase
[moodle.git] / mod / assign / module.js
blobf0ee769b8b2500b47fe6299b8822d974330b7fa5
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                 checkboxes = Y.all('td.c0 input');
80                 var selectedusers = [];
81                 checkboxes.each(function(node) {
82                     if (node.get('checked')) {
83                         selectedusers[selectedusers.length] = node.get('value');
84                     }
85                 });
87                 operation = Y.one('#id_operation');
88                 usersinput = Y.one('input.selectedusers');
89                 usersinput.set('value', selectedusers.join(','));
90                 if (selectedusers.length == 0) {
91                     alert(M.util.get_string('nousersselected', 'assign'));
92                     e.preventDefault();
93                 } else {
94                     action = operation.get('value');
95                     prefix = 'plugingradingbatchoperation_';
96                     if (action.indexOf(prefix) == 0) {
97                         pluginaction = action.substr(prefix.length);
98                         plugin = pluginaction.split('_')[0];
99                         action = pluginaction.substr(plugin.length + 1);
100                         confirmmessage = M.util.get_string('batchoperationconfirm' + action, 'assignfeedback_' + plugin);
101                     } else {
102                         confirmmessage = M.util.get_string('batchoperationconfirm' + operation.get('value'), 'assign');
103                     }
104                     if (!confirm(confirmmessage)) {
105                         e.preventDefault();
106                     }
107                 }
108             });
109         }
111         var quickgrade = Y.all('.gradingtable .quickgrade');
112         quickgrade.each(function(quick) {
113             quick.on('change', function(e) {
114                 this.get('parentNode').addClass('quickgrademodified');
115             });
116         });
117     });
120 M.mod_assign.init_grading_options = function(Y) {
121     Y.use('node', function(Y) {
122         var paginationelement = Y.one('#id_perpage');
123         paginationelement.on('change', function(e) {
124             Y.one('form.gradingoptionsform').submit();
125         });
126         var filterelement = Y.one('#id_filter');
127         if (filterelement) {
128             filterelement.on('change', function(e) {
129                 Y.one('form.gradingoptionsform').submit();
130             });
131         }
132         var markerfilterelement = Y.one('#id_markerfilter');
133         if (markerfilterelement) {
134             markerfilterelement.on('change', function(e) {
135                 Y.one('form.gradingoptionsform').submit();
136             });
137         }
138         var workflowfilterelement = Y.one('#id_workflowfilter');
139         if (workflowfilterelement) {
140             workflowfilterelement.on('change', function(e) {
141                 Y.one('form.gradingoptionsform').submit();
142             });
143         }
144         var quickgradingelement = Y.one('#id_quickgrading');
145         if (quickgradingelement) {
146             quickgradingelement.on('change', function(e) {
147                 Y.one('form.gradingoptionsform').submit();
148             });
149         }
150         var showonlyactiveenrolelement = Y.one('#id_showonlyactiveenrol');
151         if (showonlyactiveenrolelement) {
152             showonlyactiveenrolelement.on('change', function(e) {
153             Y.one('form.gradingoptionsform').submit();
154             });
155         }
156         var downloadasfolderselement = Y.one('#id_downloadasfolders');
157         if (downloadasfolderselement) {
158             downloadasfolderselement.on('change', function(e) {
159                 Y.one('form.gradingoptionsform').submit();
160             });
161         }
162     });
165 M.mod_assign.init_plugin_summary = function(Y, subtype, type, submissionid) {
166     suffix = subtype + '_' + type + '_' + submissionid;
167     classname = 'contract_' + suffix;
168     contract = Y.one('.' + classname);
169     if (contract) {
170         contract.on('click', function(e) {
171             img = e.target;
172             imgclasses = img.getAttribute('class').split(' ');
173             for (i = 0; i < imgclasses.length; i++) {
174                 classname = imgclasses[i];
175                 if (classname.indexOf('contract_') == 0) {
176                     thissuffix = classname.substr(9);
177                 }
178             }
179             fullclassname = 'full_' + thissuffix;
180             full = Y.one('.' + fullclassname);
181             if (full) {
182                 full.hide(false);
183             }
184             summaryclassname = 'summary_' + thissuffix;
185             summary = Y.one('.' + summaryclassname);
186             if (summary) {
187                 summary.show(false);
188             }
189         });
190     }
191     classname = 'expand_' + suffix;
192     expand = Y.one('.' + classname);
194     full = Y.one('.full_' + suffix);
195     if (full) {
196         full.hide(false);
197         full.toggleClass('hidefull');
198     }
199     if (expand) {
200         expand.on('click', function(e) {
201             img = e.target;
202             imgclasses = img.getAttribute('class').split(' ');
203             for (i = 0; i < imgclasses.length; i++) {
204                 classname = imgclasses[i];
205                 if (classname.indexOf('expand_') == 0) {
206                     thissuffix = classname.substr(7);
207                 }
208             }
209             summaryclassname = 'summary_' + thissuffix;
210             summary = Y.one('.' + summaryclassname);
211             if (summary) {
212                 summary.hide(false);
213             }
214             fullclassname = 'full_' + thissuffix;
215             full = Y.one('.' + fullclassname);
216             if (full) {
217                 full.show(false);
218             }
219         });
220     }