[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 2 M.core_completion = {}; 3 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(); 10 return; 11 } 12 13 var handle_success = function(id, o, args) { 14 Y.one('#completion_dynamic_change').set('value', 1); 15 16 if (o.responseText != 'OK') { 17 alert('An error occurred when attempting to save your tick mark.\n\n('+o.responseText+'.)'); //TODO: localize 18 19 } else { 20 var current = args.state.get('value'); 21 var modulename = args.modulename.get('value'), 22 altstr, 23 titlestr; 24 if (current == 1) { 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); 31 } else { 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); 38 } 39 } 40 41 args.ajax.remove(); 42 }; 43 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 46 args.ajax.remove(); 47 }; 48 49 var toggle = function(e) { 50 e.preventDefault(); 51 52 var form = e.target; 53 var cmid = 0; 54 var completionstate = 0; 55 var state = null; 56 var image = null; 57 var modulename = null; 58 59 var inputs = Y.Node.getDOMNode(form).getElementsByTagName('input'); 60 for (var i=0; i<inputs.length; i++) { 61 switch (inputs[i].name) { 62 case 'id': 63 cmid = inputs[i].value; 64 break; 65 case 'completionstate': 66 completionstate = inputs[i].value; 67 state = Y.one(inputs[i]); 68 break; 69 case 'modulename': 70 modulename = Y.one(inputs[i]); 71 break; 72 } 73 if (inputs[i].type == 'image') { 74 image = Y.one(inputs[i]); 75 } 76 } 77 78 // start spinning the ajax indicator 79 var ajax = Y.Node.create('<div class="ajaxworking" />'); 80 form.append(ajax); 81 82 var cfg = { 83 method: "POST", 84 data: 'id='+cmid+'&completionstate='+completionstate+'&fromajax=1&sesskey='+M.cfg.sesskey, 85 on: { 86 success: handle_success, 87 failure: handle_failure 88 }, 89 arguments: {state: state, image: image, ajax: ajax, modulename: modulename} 90 }; 91 92 Y.use('io-base', function(Y) { 93 Y.io(M.cfg.wwwroot+'/course/togglecompletion.php', cfg); 94 }); 95 }; 96 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); 101 } 102 }); 103 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'); 108 } 109 }; 110 111
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |