2 M.core_completion = {};
4 M.core_completion.init = function(Y) {
5 // Check the reload-forcing
6 var changeDetector = Y.one('#completion_dynamic_change');
7 if (changeDetector.get('value') > 0) {
8 changeDetector.set('value', 0);
9 window.location.reload();
13 var handle_success = function(id, o, args) {
14 Y.one('#completion_dynamic_change').set('value', 1);
16 if (o.responseText != 'OK') {
17 alert('An error occurred when attempting to save your tick mark.\n\n('+o.responseText+'.)'); //TODO: localize
20 var current = args.state.get('value');
21 var modulename = args.modulename.get('value'),
25 altstr = M.util.get_string('completion-alt-manual-y', 'completion', modulename);
26 titlestr = M.util.get_string('completion-title-manual-y', 'completion', modulename);
27 args.state.set('value', 0);
28 args.image.set('src', M.util.image_url('i/completion-manual-y', 'moodle'));
29 args.image.set('alt', altstr);
30 args.image.set('title', titlestr);
32 altstr = M.util.get_string('completion-alt-manual-n', 'completion', modulename);
33 titlestr = M.util.get_string('completion-title-manual-n', 'completion', modulename);
34 args.state.set('value', 1);
35 args.image.set('src', M.util.image_url('i/completion-manual-n', 'moodle'));
36 args.image.set('alt', altstr);
37 args.image.set('title', titlestr);
44 var handle_failure = function(id, o, args) {
45 alert('An error occurred when attempting to save your tick mark.\n\n('+o.responseText+'.)'); //TODO: localize
49 var toggle = function(e) {
54 var completionstate = 0;
57 var modulename = null;
59 var inputs = Y.Node.getDOMNode(form).getElementsByTagName('input');
60 for (var i=0; i<inputs.length; i++) {
61 switch (inputs[i].name) {
63 cmid = inputs[i].value;
65 case 'completionstate':
66 completionstate = inputs[i].value;
67 state = Y.one(inputs[i]);
70 modulename = Y.one(inputs[i]);
73 if (inputs[i].type == 'image') {
74 image = Y.one(inputs[i]);
78 // start spinning the ajax indicator
79 var ajax = Y.Node.create('<div class="ajaxworking" />');
84 data: 'id='+cmid+'&completionstate='+completionstate+'&fromajax=1&sesskey='+M.cfg.sesskey,
86 success: handle_success,
87 failure: handle_failure
89 arguments: {state: state, image: image, ajax: ajax, modulename: modulename}
92 Y.use('io-base', function(Y) {
93 Y.io(M.cfg.wwwroot+'/course/togglecompletion.php', cfg);
97 // register submit handlers on manual tick completion forms
98 Y.all('form.togglecompletion').each(function(form) {
99 if (!form.hasClass('preventjs')) {
100 Y.on('submit', toggle, form);
104 // hide the help if there are no completion toggles or icons
105 var help = Y.one('#completionprogressid');
106 if (help && !(Y.one('form.togglecompletion') || Y.one('.autocompletion'))) {
107 help.setStyle('display', 'none');