Commit 9b9b9cab authored by Marina Glancy's avatar Marina Glancy
Browse files

MDL-43470 mod_feedback: remove mapping form autosave

parent ed724aac
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
// 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();
}
});
}
};
});
......@@ -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();
}
}
......@@ -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';
......
......@@ -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.
......
......@@ -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"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment