diff --git a/grade/report/singleview/classes/local/screen/screen.php b/grade/report/singleview/classes/local/screen/screen.php index 891dce8813c3b..5be42fd2783c1 100644 --- a/grade/report/singleview/classes/local/screen/screen.php +++ b/grade/report/singleview/classes/local/screen/screen.php @@ -268,6 +268,7 @@ public function js() { 'requires' => array('base', 'dom', 'event', 'event-simulate', 'io-base') ); + $PAGE->requires->string_for_js('overridenoneconfirm', 'gradereport_singleview'); $PAGE->requires->js_init_call('M.gradereport_singleview.init', array(), false, $module); } diff --git a/grade/report/singleview/js/singleview.js b/grade/report/singleview/js/singleview.js index 7ee45eb206bc0..e6f6a082547a2 100644 --- a/grade/report/singleview/js/singleview.js +++ b/grade/report/singleview/js/singleview.js @@ -1,6 +1,11 @@ M.gradereport_singleview = {}; M.gradereport_singleview.init = function(Y) { + if (this.initialised) { + return; + } + this.initialised = true; + var getColumnIndex = function(cell) { var rowNode = cell.ancestor('tr'); if (!rowNode || !cell) { @@ -104,7 +109,24 @@ M.gradereport_singleview.init = function(Y) { link.on('click', function(e) { e.preventDefault(); - Y.all('input[name^=' + type + ']').each(toggle(link.hasClass('all'))); + var selectall = link.hasClass('all'); + var self = this; + if ((type === 'override') && !selectall) { + Y.use('moodle-core-notification-confirm', function() { + var confirm = new M.core.confirm({ + title: M.util.get_string('confirm', 'moodle'), + question: M.util.get_string('overridenoneconfirm', 'gradereport_singleview'), + }); + confirm.on('complete-yes', function() { + confirm.hide(); + confirm.destroy(); + Y.all('input[name^=' + type + ']').each(toggle(link.hasClass('all'))); + }, self); + confirm.show(); + }); + } else { + Y.all('input[name^=' + type + ']').each(toggle(link.hasClass('all'))); + } }); }); diff --git a/grade/report/singleview/lang/en/gradereport_singleview.php b/grade/report/singleview/lang/en/gradereport_singleview.php index e6a913b247453..d27feb9049c9d 100644 --- a/grade/report/singleview/lang/en/gradereport_singleview.php +++ b/grade/report/singleview/lang/en/gradereport_singleview.php @@ -50,6 +50,7 @@ $string['overrideall'] = 'Override all grades'; $string['overridefor'] = 'Override for {$a}'; $string['overridenone'] = 'Do not override any grades'; +$string['overridenoneconfirm'] = 'You are trying to disable all grade overrides. After saving, all the previously overridden grades will be lost. Do you want to continue?'; $string['pluginname'] = 'Single view'; $string['privacy:metadata'] = 'The Grade single view report only shows data stored in other locations.'; $string['savegrades'] = 'Saving grades';