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