Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Simple method to check for changes to a form between two points in time.
18
 *
19
 * @module     mod_assign/grading_form_change_checker
20
 * @copyright  2016 Damyon Wiese <damyon@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @since      3.1
23
 */
24
define(['jquery'], function($) {
25
 
26
    return {
27
        /**
28
         * Save the values in the form to a data attribute so they can be compared later for changes.
29
         *
30
         * @method saveFormState
31
         * @param {String} selector The selector for the form element.
32
         */
33
        saveFormState: function(selector) {
34
            $(selector).trigger('save-form-state');
35
            var data = $(selector).serialize();
36
            $(selector).data('saved-form-state', data);
37
        },
38
 
39
        /**
40
         * Compare the current values in the form to the previously saved state.
41
         *
42
         * @method checkFormForChanges
43
         * @param {String} selector The selector for the form element.
44
         * @return {Boolean} True if there are changes to the form data.
45
         */
46
        checkFormForChanges: function(selector) {
47
 
48
            $(selector).trigger('save-form-state');
49
 
50
            var data = $(selector).serialize(),
51
                previousdata = $(selector).data('saved-form-state');
52
 
53
            if (typeof previousdata === 'undefined') {
54
                return false;
55
            }
56
            return (previousdata != data);
57
        }
58
    };
59
});