Nitification when toggling activity completion

Nitification when toggling activity completion

by Nicolas Dalpe -
Number of replies: 2

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);
            });
    };
Average of ratings: -
In reply to Nicolas Dalpe

Re: Nitification when toggling activity completion

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
Looking at the code there is AJAX but using the old YUI way. There could be a way of overriding that but you'll need to learn YUI in order to do so.
In reply to Gareth J Barnard

Re: Nitification when toggling activity completion

by Nicolas Dalpe -
Gareth, thx for your answer. I think I will just code my own module + webservice and use this instead learning YUI. I will try to use the Notification javascript module to dispatch the result of the completion toggle so the JS in my theme can listen to the Notification and trigger their action. Wish me luck ;)

Thx