Merge branch 'wip-mdl-33506' of git://github.com/rajeshtaneja/moodle
[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.check_dirty_quickgrading_form = function(e) {
114     if (!M.core_formchangechecker.get_form_dirty_state()) {
115         // the form is not dirty, so don't display any message
116         return;
117     }
119     // This is the error message that we'll show to browsers which support it
120     var warningmessage = 'There are unsaved quickgrading changes. Do you really wanto to leave this page?';
122     // Most browsers are happy with the returnValue being set on the event
123     // But some browsers do not consistently pass the event
124     if (e) {
125         e.returnValue = warningmessage;
126     }
128     // But some require it to be returned instead
129     return warningmessage;
131 M.mod_assign.init_grading_options = function(Y) {
132     Y.use('node', function(Y) {
134         var paginationelement = Y.one('#id_perpage');
135         paginationelement.on('change', function(e) {
136             Y.one('form.gradingoptionsform').submit();
137         });
138         var filterelement = Y.one('#id_filter');
139         filterelement.on('change', function(e) {
140             Y.one('form.gradingoptionsform').submit();
141         });
142         var quickgradingelement = Y.one('#id_quickgrading');
143         if (quickgradingelement) {
144             quickgradingelement.on('change', function(e) {
145                 Y.one('form.gradingoptionsform').submit();
146             });
147         }
149     });
152 };
153 // override the default dirty form behaviour to ignore any input with the class "ignoredirty"
154 M.mod_assign.set_form_changed = M.core_formchangechecker.set_form_changed;
155 M.core_formchangechecker.set_form_changed = function(e) {
156     var target = e.currentTarget;
157     if (!target.hasClass('ignoredirty')) {
158         M.mod_assign.set_form_changed(e);
159     }
162 M.mod_assign.get_form_dirty_state = M.core_formchangechecker.get_form_dirty_state;
163 M.core_formchangechecker.get_form_dirty_state = function() {
164     var state = M.core_formchangechecker.stateinformation;
165     if (state.focused_element) {
166         if (state.focused_element.element.hasClass('ignoredirty')) {
167             state.focused_element.initial_value = state.focused_element.element.get('value')
168         }
169     }
170     return M.mod_assign.get_form_dirty_state();