Hello dear Moodlers,
I have a Javascript question for you. I need to execute some action after an activity has been manually marked as completed.
When a student mark the activity as completed, /course/completion.js sends the ".togglecompletion" form to /course/togglecompletion.php to toggle the activity completion. completion.js then receives 'OK' if success or an error on failure.
In completion.js, handle_success() function does use 'core/notification' but only to notify about exception, not success (see #1 below).
My question is: Is there a way I can override completion.js in my theme and add a success notification that I could listen in my theme AMD module to trigger my post-completion-toggle action? Or, is there a better solution to do this?
Just curious...since this is an AJAX request, why doesn't it use a proper webservice? I thought this was the "Moodle way" of doing ajax call.
Thank you in advance for your time and help
1 -
var handle_success = function(id, o, args) {
require(['core/templates', 'core/notification'], function(Templates, Notification) {
Templates.renderPix(iconkey, 'core', altstr).then(function(html) {
var id = button.get('id'),
postFocus = '$(document.getElementById("' + id + '")).focus();';
Templates.replaceNode(args.image.getDOMNode(), html, postFocus);
}).catch(Notification.exception);
});
};