Merge branch 'MDL-69613-Master' of https://github.com/tuanngocnguyen/moodle
authorVíctor Déniz <victor@moodle.com>
Thu, 1 Oct 2020 16:44:31 +0000 (17:44 +0100)
committerVíctor Déniz <victor@moodle.com>
Thu, 1 Oct 2020 16:44:31 +0000 (17:44 +0100)
grade/report/singleview/classes/local/screen/screen.php
grade/report/singleview/js/singleview.js
grade/report/singleview/lang/en/gradereport_singleview.php

index 891dce8..5be42fd 100644 (file)
@@ -268,6 +268,7 @@ abstract class screen {
             '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);
     }
 
index 7ee45eb..e6f6a08 100644 (file)
@@ -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')));
+            }
         });
     });
 
index e6a913b..d27feb9 100644 (file)
@@ -50,6 +50,7 @@ $string['override'] = 'Override';
 $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';