jonof / moodle-block_completion_progress

A time management tool for students using activity completion
https://moodle.org/plugins/block_completion_progress
GNU General Public License v3.0
17 stars 65 forks source link

Error on select when no student is checked #90

Closed liesugahara closed 2 years ago

liesugahara commented 2 years ago

Hello,

After playing around with the plugin i noticed that when you navigate to "Overview of students", scroll down to "With selected users..." and select either "send a message" or "add a note" without selecting a user, it throws the following error:

image

This was tested on moodle 4.0, using the plugin version 2022042000.

A possible solution would be disabling this dropdown via javascript when no student is selected.

Best regards!!

liesugahara commented 2 years ago

This is the sugggested solution:

define(['jquery','core_user/participants'],
    function($,Participants) {
        return /** @alias module:block_completion_progress/overview */ {
            /**
             * Initialise the overview page.
             *
             * @param {object} options initialisation options.
             */
            init: function(options) {
                Participants.init(options);
                disable_select();
                $('.overviewTable tbody').on('change', ':input', function() {
                    disable_select();
                });
                function disable_select() {
                    let countchecks = 0;
                    $('.overviewTable tbody :checkbox').each(function() {
                        if (this.checked) {
                            countchecks = 1;
                            $('#formactionid').removeAttr('disabled');
                            return;
                        }
                    });
                    if (!countchecks) {
                        $('#formactionid').attr('disabled', 'disabled');
                    }
                }
            }
        };
    });