1 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 * Module to update the displayed retention period.
19 * @module tool_dataprivacy/effective_retention_period
20 * @package tool_dataprivacy
21 * @copyright 2018 David Monllao
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 PURPOSE_SELECT: '#id_purposeid',
29 RETENTION_FIELD: '.form-control-static',
33 * Constructor for the retention period display.
35 * @param {Array} purposeRetentionPeriods Associative array of purposeids with effective retention period at this context
37 var EffectiveRetentionPeriod = function(purposeRetentionPeriods) {
38 this.purposeRetentionPeriods = purposeRetentionPeriods;
39 this.registerEventListeners();
43 * Removes the current 'change' listeners.
45 * Useful when a new form is loaded.
47 var removeListeners = function() {
48 $(SELECTORS.PURPOSE_SELECT).off('change');
52 * @var {Array} purposeRetentionPeriods
55 EffectiveRetentionPeriod.prototype.purposeRetentionPeriods = [];
58 * Add purpose change listeners.
60 * @method registerEventListeners
62 EffectiveRetentionPeriod.prototype.registerEventListeners = function() {
64 $(SELECTORS.PURPOSE_SELECT).on('change', function(ev) {
65 var selected = $(ev.currentTarget).val();
66 var selectedPurpose = this.purposeRetentionPeriods[selected];
68 $(SELECTORS.RETENTION_FIELD).each(function() {
70 // Sucky way to select the text, but no id for static fields :(.
71 var retentionField = node.siblings('#id_error_retention_current');
72 if (retentionField.length > 0) {
73 node.text(selectedPurpose);
80 return /** @alias module:tool_dataprivacy/effective_retention_period */ {
81 init: function(purposeRetentionPeriods) {
82 // Remove previously attached listeners.
84 return new EffectiveRetentionPeriod(purposeRetentionPeriods);