Merge branch 'MDL-47603' of git://github.com/timhunt/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 13 Oct 2014 12:33:56 +0000 (13:33 +0100)
committerDan Poltawski <dan@moodle.com>
Mon, 13 Oct 2014 12:33:56 +0000 (13:33 +0100)
grade/import/csv/classes/load_data.php
grade/import/direct/index.php
grade/tests/behat/grade_natural_normalisation.feature
lib/editor/atto/autosave-ajax.php
lib/editor/atto/lang/en/editor_atto.php
lib/editor/atto/lib.php
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js
lib/editor/atto/yui/src/editor/js/autosave.js
lib/grade/grade_category.php

index 3cbb069..21477b9 100644 (file)
@@ -77,17 +77,21 @@ class gradeimport_csv_load_data {
         $csvimport->load_csv_content($text, $encoding, $separator);
         $this->error = $csvimport->get_error();
 
-        // Get header (field names).
-        $this->headers = $csvimport->get_columns();
-        $this->trim_headers();
+        // If there are no import errors then proceed.
+        if (empty($this->error)) {
 
-        $csvimport->init();
-        $this->previewdata = array();
+            // Get header (field names).
+            $this->headers = $csvimport->get_columns();
+            $this->trim_headers();
 
-        for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
-            $lines = $csvimport->next();
-            if ($lines) {
-                $this->previewdata[] = $lines;
+            $csvimport->init();
+            $this->previewdata = array();
+
+            for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
+                $lines = $csvimport->next();
+                if ($lines) {
+                    $this->previewdata[] = $lines;
+                }
             }
         }
     }
index 1a9fc67..d1b6a4b 100644 (file)
@@ -69,7 +69,7 @@ if (!$iid) {
         $csvimport->load_csv_content($text, $formdata->encoding, 'tab', $formdata->previewrows);
         $csvimporterror = $csvimport->get_error();
         if (!empty($csvimporterror)) {
-            echo $renderer->errors($csvimport->get_error());
+            echo $renderer->errors(array($csvimport->get_error()));
             echo $OUTPUT->footer();
             die();
         }
index 5512a3f..a2d50cb 100644 (file)
@@ -250,3 +250,18 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
   Then the field "Weight of Test assignment five" matches value "80.0"
   And the field "Weight of Test assignment six" matches value "40.0"
   And the field "Weight of Test assignment seven" matches value "60.0"
+
+  @javascript
+  Scenario: Overriding a grade item with a negative value results in the value being changed to zero.
+
+  When I set the field "Override weight of Test assignment five" to "1"
+  And I set the field "Weight of Test assignment five" to "-15"
+  And I press "Save changes"
+  Then the field "Weight of Test assignment five" matches value "0.0"
+  And the field "Weight of Test assignment six" matches value "40.0"
+  And the field "Weight of Test assignment seven" matches value "60.0"
+  And I set the field "Override weight of Test assignment six" to "1"
+  And I set the field "Weight of Test assignment six" to "-25"
+  And I press "Save changes"
+  Then the field "Weight of Test assignment six" matches value "0.0"
+  And the field "Weight of Test assignment seven" matches value "100.0"
index 36dcc06..fa45fd4 100644 (file)
@@ -45,6 +45,8 @@ require_sesskey();
 
 $action = required_param('action', PARAM_ALPHA);
 
+$response = array();
+
 if ($action === 'save') {
     $drafttext = required_param('drafttext', PARAM_RAW);
     $params = array('elementid' => $elementid,
@@ -138,7 +140,8 @@ if ($action === 'save') {
 
         // A response means the draft has been restored and here is the auto-saved text.
         if (!$stale) {
-            echo $record->drafttext;
+            $response['result'] = $record->drafttext;
+            echo json_encode($response);
         }
         die();
     }
index d1c2b68..c151c0a 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 $string['autosavefailed'] = 'Could not connect to the server. If you submit this page now, your changes may be lost.';
-$string['autosavefrequency'] = 'Autosave frequency (seconds).';
+$string['autosavefrequency'] = 'Autosave frequency';
 $string['autosavefrequency_desc'] = 'This is the number of seconds between auto save attempts. Atto will automatically save the text in the editor according to this setting, so that text can be automatically restored when the same user returns to the same form.';
 $string['autosavesucceeded'] = 'Draft saved.';
 $string['errorcannotparseline'] = 'The line \'{$a}\' is not in the correct format.';
@@ -31,6 +31,7 @@ $string['errorgroupisusedtwice'] = 'The group \'{$a}\' is defined twice; group n
 $string['errornopluginsorgroupsfound'] = 'No plugins or groups found; please add some groups and plugins.';
 $string['errorpluginnotfound'] = 'The plugin \'{$a}\' cannot be used; it does not appear to be installed.';
 $string['errorpluginisusedtwice'] = 'The plugin \'{$a}\' is used twice; plugins can only be defined once.';
+$string['errortextrecovery'] = 'The draft version of this text was unable to be restored.';
 $string['pluginname'] = 'Atto HTML editor';
 $string['subplugintype_atto'] = 'Atto plugin';
 $string['subplugintype_atto_plural'] = 'Atto plugins';
index 00cd928..65caee5 100644 (file)
@@ -127,7 +127,8 @@ class atto_texteditor extends texteditor {
                 'plugin_title_shortcut',
                 'textrecovered',
                 'autosavefailed',
-                'autosavesucceeded'
+                'autosavesucceeded',
+                'errortextrecovery'
             ), 'editor_atto');
         $PAGE->requires->strings_for_js(array(
                 'warning',
index 6969164..2254cc0 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js differ
index 5ce80c8..0a8ea93 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js differ
index d743822..8f3a664 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js differ
index 07598bc..ee2ec44 100644 (file)
@@ -145,10 +145,19 @@ EditorAutosave.prototype = {
                     if (typeof o.responseText !== "undefined" &&
                             o.responseText !== "" &&
                             o.responseText !== this.textarea.get('value')) {
-                        Y.log('Autosave text found - recover it.', 'debug', LOGNAME_AUTOSAVE);
-                        this.recoverText(o.responseText);
+                        response_json = JSON.parse(o.responseText);
+                        if (!response_json.error && response_json.result) {
+                            Y.log('Autosave text found - recover it.', 'debug', LOGNAME_AUTOSAVE);
+                            this.recoverText(response_json.result);
+                        } else {
+                            Y.log('Error occurred recovering draft text: ' + response_json.error, 'debug', LOGNAME_AUTOSAVE);
+                            this.showMessage(M.util.get_string('errortextrecovery', 'editor_atto'), NOTIFY_WARNING, RECOVER_MESSAGE_TIMEOUT);
+                        }
                         this._fireSelectionChanged();
                     }
+                },
+                failure: function() {
+                    this.showMessage(M.util.get_string('errortextrecovery', 'editor_atto'), NOTIFY_WARNING, RECOVER_MESSAGE_TIMEOUT);
                 }
             }
         });
index b70030c..32fd6f5 100644 (file)
@@ -1373,10 +1373,13 @@ class grade_category extends grade_object {
                             (1 - $totaloverriddenweight);
                 }
                 $gradeitem->update();
-            } else if ((!$automaticgradeitemspresent && $normalisetotal != 1) || ($requiresnormalising)) {
+            } else if ((!$automaticgradeitemspresent && $normalisetotal != 1) || ($requiresnormalising)
+                    || $overridearray[$gradeitem->id]['weight'] < 0) {
                 // Just divide the overriden weight for this item against the total weight override of all
                 // items in this category.
-                if ($normalisetotal == 0) {
+                if ($normalisetotal == 0 || $overridearray[$gradeitem->id]['weight'] < 0) {
+                    // If the normalised total equals zero, or the weight value is less than zero,
+                    // set the weight for the grade item to zero.
                     $gradeitem->aggregationcoef2 = 0;
                 } else {
                     $gradeitem->aggregationcoef2 = $overridearray[$gradeitem->id]['weight'] / $normalisetotal;