[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/amd/src/ -> grading_form_change_checker.js (source)

   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   * @package    mod_assign
  21   * @copyright  2016 Damyon Wiese <damyon@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   * @since      3.1
  24   */
  25  define(['jquery'], function($) {
  26  
  27      return /** @alias module:mod_assign/grading_form_change_checker */ {
  28          /**
  29           * Save the values in the form to a data attribute so they can be compared later for changes.
  30           *
  31           * @method saveFormState
  32           * @param {String} selector The selector for the form element.
  33           */
  34          saveFormState: function(selector) {
  35              $(selector).trigger('save-form-state');
  36              var data = $(selector).serialize();
  37              $(selector).data('saved-form-state', data);
  38          },
  39  
  40          /**
  41           * Compare the current values in the form to the previously saved state.
  42           *
  43           * @method checkFormForChanges
  44           * @param {String} selector The selector for the form element.
  45           * @return {Boolean} True if there are changes to the form data.
  46           */
  47          checkFormForChanges: function(selector) {
  48  
  49              $(selector).trigger('save-form-state');
  50  
  51              var data = $(selector).serialize(),
  52                  previousdata = $(selector).data('saved-form-state');
  53  
  54              if (typeof previousdata === 'undefined') {
  55                  return false;
  56              }
  57              return (previousdata != data);
  58          }
  59      };
  60  });


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1