MDL-43470 mod_feedback: remove mapping form autosave
authorMarina Glancy <marina@moodle.com>
Wed, 6 Apr 2016 02:22:01 +0000 (10:22 +0800)
committerMarina Glancy <marina@moodle.com>
Wed, 6 Apr 2016 02:29:56 +0000 (10:29 +0800)
mod/feedback/amd/build/feedback.min.js [deleted file]
mod/feedback/amd/src/feedback.js [deleted file]
mod/feedback/classes/course_map_form.php
mod/feedback/lang/en/feedback.php
mod/feedback/mapcourse.php
mod/feedback/tests/behat/coursemapping.feature

diff --git a/mod/feedback/amd/build/feedback.min.js b/mod/feedback/amd/build/feedback.min.js
deleted file mode 100644 (file)
index e1e4528..0000000
Binary files a/mod/feedback/amd/build/feedback.min.js and /dev/null differ
diff --git a/mod/feedback/amd/src/feedback.js b/mod/feedback/amd/src/feedback.js
deleted file mode 100644 (file)
index 8560f9d..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * AJAX helper for the tag management page.
- *
- * @module     mod_feedback/feedback
- * @package    mod_feedback
- * @copyright  2016 Marina Glancy
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since      3.1
- */
-define(['jquery'], function($) {
-    return /** @alias module:mod_feedback/feedback */ {
-
-        /**
-         * Initialises course mapping page.
-         *
-         * @method initCourseMapping
-         */
-        initCourseMapping: function (elementid) {
-            // Auto submit form on every change to element with id elementid.
-            $('body').on('change', elementid, function (e) {
-                var form = $(e.target).closest('form');
-                $.ajax(form.attr('action'), {
-                    type: 'POST',
-                    data: form.serialize()
-                });
-                if (typeof M.core_formchangechecker != 'undefined') {
-                    M.core_formchangechecker.set_form_submitted();
-                }
-            });
-        }
-    };
-});
index 66cef87..fe92115 100644 (file)
@@ -35,7 +35,6 @@ class mod_feedback_course_map_form extends moodleform {
      * Definition of the form
      */
     public function definition() {
-        global $PAGE;
         $mform  = $this->_form;
 
         $mform->addElement('hidden', 'id');
@@ -44,7 +43,6 @@ class mod_feedback_course_map_form extends moodleform {
         $options = array('multiple' => true);
         $mform->addElement('course', 'mappedcourses', get_string('courses'), $options);
 
-        // Automatically submit form in AJAX request every time 'mappedcourses' is modified.
-        $PAGE->requires->js_call_amd('mod_feedback/feedback', 'initCourseMapping', array('#id_mappedcourses'));
+        $this->add_action_buttons();
     }
 }
index 429e5f9..e2492c5 100644 (file)
@@ -153,6 +153,7 @@ $string['mapcourse_help'] = 'By default, feedback forms created on your homepage
 and will appear in all courses using the feedback block. You can force the feedback form to appear by making it a sticky block or limit the courses in which a feedback form will appear by mapping it to specific courses.';
 $string['mapcourses'] = 'Map feedback to courses';
 $string['mappedcourses'] = 'Mapped courses';
+$string['mappingchanged'] = 'Course mapping has been changed';
 $string['max_args_exceeded'] = 'Max 6 arguments can be handled, too many arguments for';
 $string['minimal'] = 'minimum';
 $string['maximal'] = 'maximum';
index 3379036..6330d6e 100644 (file)
@@ -43,8 +43,12 @@ require_capability('mod/feedback:mapcourse', $context);
 $coursemap = array_keys(feedback_get_courses_from_sitecourse_map($feedback->id));
 $form = new mod_feedback_course_map_form();
 $form->set_data(array('id' => $cm->id, 'mappedcourses' => $coursemap));
-if ($data = $form->get_data()) {
+$mainurl = new moodle_url('/mod/feedback/view.php', ['id' => $id]);
+if ($form->is_cancelled()) {
+    redirect($mainurl);
+} else if ($data = $form->get_data()) {
     feedback_update_sitecourse_map($feedback, $data->mappedcourses);
+    redirect($mainurl, get_string('mappingchanged', 'feedback'), null, \core\output\notification::NOTIFY_SUCCESS);
 }
 
 // Print the page header.
index 3ce083f..ffe9386 100644 (file)
@@ -143,9 +143,8 @@ Feature: Mapping courses in a feedback
     And I follow "Course feedback"
     And I follow "Map feedback to courses"
     And I set the field "Courses" to "Course 2"
-    And I wait until the page is ready
     And I set the field "Courses" to "Course 3"
-    And I wait until the page is ready
+    And I press "Save changes"
     And I log out
 
     And I log in as "user1"