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
 * Module to update the displayed retention period.
18
 *
19
 * @module     tool_dataprivacy/effective_retention_period
20
 * @copyright  2018 David Monllao
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
define(['jquery'],
24
    function($) {
25
 
26
        var SELECTORS = {
27
            PURPOSE_SELECT: '#id_purposeid',
28
            RETENTION_FIELD: '#fitem_id_retention_current [data-fieldtype=static]',
29
        };
30
 
31
        /**
32
         * Constructor for the retention period display.
33
         *
34
         * @param {Array} purposeRetentionPeriods Associative array of purposeids with effective retention period at this context
35
         */
36
        var EffectiveRetentionPeriod = function(purposeRetentionPeriods) {
37
            this.purposeRetentionPeriods = purposeRetentionPeriods;
38
            this.registerEventListeners();
39
        };
40
 
41
        /**
42
         * Removes the current 'change' listeners.
43
         *
44
         * Useful when a new form is loaded.
45
         */
46
        var removeListeners = function() {
47
            $(SELECTORS.PURPOSE_SELECT).off('change');
48
        };
49
 
50
        /**
51
         * @var {Array} purposeRetentionPeriods
52
         * @private
53
         */
54
        EffectiveRetentionPeriod.prototype.purposeRetentionPeriods = [];
55
 
56
        /**
57
         * Add purpose change listeners.
58
         *
59
         * @method registerEventListeners
60
         */
61
        EffectiveRetentionPeriod.prototype.registerEventListeners = function() {
62
 
63
            $(SELECTORS.PURPOSE_SELECT).on('change', function(ev) {
64
                var selected = $(ev.currentTarget).val();
65
                var selectedPurpose = this.purposeRetentionPeriods[selected];
66
                $(SELECTORS.RETENTION_FIELD).text(selectedPurpose);
67
            }.bind(this));
68
        };
69
 
70
        return /** @alias module:tool_dataprivacy/effective_retention_period */ {
71
            init: function(purposeRetentionPeriods) {
72
                // Remove previously attached listeners.
73
                removeListeners();
74
                return new EffectiveRetentionPeriod(purposeRetentionPeriods);
75
            }
76
        };
77
    }
78
);
79