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
 * A javascript module to store calendar drag and drop data.
18
 *
19
 * This module is unfortunately required because of the limitations
20
 * of the HTML5 drag and drop API and it's ability to provide data
21
 * between the different stages of the drag/drop lifecycle.
22
 *
23
 * @module     core_calendar/drag_drop_data_store
24
 * @copyright  2017 Ryan Wyllie <ryan@moodle.com>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
define([], function() {
28
    /* @var {int|null} eventId The id of the event being dragged */
29
    var eventId = null;
30
    /* @var {int|null} durationDays How many days the event spans */
31
    var durationDays = null;
32
    /* @var {int|null} minTimestart The earliest valid timestart */
33
    var minTimestart = null;
34
    /* @var {int|null} maxTimestart The latest valid tiemstart */
35
    var maxTimestart = null;
36
    /* @var {string|null} minError Error message for min timestamp violation */
37
    var minError = null;
38
    /* @var {string|null} maxError Error message for max timestamp violation */
39
    var maxError = null;
40
 
41
    /**
42
     * Store the id of the event being dragged.
43
     *
44
     * @param {int} id The event id
45
     */
46
    var setEventId = function(id) {
47
        eventId = id;
48
    };
49
 
50
    /**
51
     * Get the stored event id.
52
     *
53
     * @return {int|null}
54
     */
55
    var getEventId = function() {
56
        return eventId;
57
    };
58
 
59
    /**
60
     * Check if the store has an event id.
61
     *
62
     * @return {bool}
63
     */
64
    var hasEventId = function() {
65
        return eventId !== null;
66
    };
67
 
68
    /**
69
     * Store the duration (in days) of the event being dragged.
70
     *
71
     * @param {int} days Number of days the event spans
72
     */
73
    var setDurationDays = function(days) {
74
        durationDays = days;
75
    };
76
 
77
    /**
78
     * Get the stored number of days.
79
     *
80
     * @return {int|null}
81
     */
82
    var getDurationDays = function() {
83
        return durationDays;
84
    };
85
 
86
    /**
87
     * Store the minimum timestart valid for an event being dragged.
88
     *
89
     * @param {int} timestamp The unix timstamp
90
     */
91
    var setMinTimestart = function(timestamp) {
92
        minTimestart = timestamp;
93
    };
94
 
95
    /**
96
     * Get the minimum valid timestart.
97
     *
98
     * @return {int|null}
99
     */
100
    var getMinTimestart = function() {
101
        return minTimestart;
102
    };
103
 
104
    /**
105
     * Check if a minimum timestamp is set.
106
     *
107
     * @return {bool}
108
     */
109
    var hasMinTimestart = function() {
110
        return minTimestart !== null;
111
    };
112
 
113
    /**
114
     * Store the maximum timestart valid for an event being dragged.
115
     *
116
     * @param {int} timestamp The unix timstamp
117
     */
118
    var setMaxTimestart = function(timestamp) {
119
        maxTimestart = timestamp;
120
    };
121
 
122
    /**
123
     * Get the maximum valid timestart.
124
     *
125
     * @return {int|null}
126
     */
127
    var getMaxTimestart = function() {
128
        return maxTimestart;
129
    };
130
 
131
    /**
132
     * Check if a maximum timestamp is set.
133
     *
134
     * @return {bool}
135
     */
136
    var hasMaxTimestart = function() {
137
        return maxTimestart !== null;
138
    };
139
 
140
    /**
141
     * Store the error string to display if trying to drag an event
142
     * earlier than the minimum allowed date.
143
     *
144
     * @param {string} message The error message
145
     */
146
    var setMinError = function(message) {
147
        minError = message;
148
    };
149
 
150
    /**
151
     * Get the error message for a minimum time start violation.
152
     *
153
     * @return {string|null}
154
     */
155
    var getMinError = function() {
156
        return minError;
157
    };
158
 
159
    /**
160
     * Store the error string to display if trying to drag an event
161
     * later than the maximum allowed date.
162
     *
163
     * @param {string} message The error message
164
     */
165
    var setMaxError = function(message) {
166
        maxError = message;
167
    };
168
 
169
    /**
170
     * Get the error message for a maximum time start violation.
171
     *
172
     * @return {string|null}
173
     */
174
    var getMaxError = function() {
175
        return maxError;
176
    };
177
 
178
    /**
179
     * Reset all of the stored values.
180
     */
181
    var clearAll = function() {
182
        setEventId(null);
183
        setDurationDays(null);
184
        setMinTimestart(null);
185
        setMaxTimestart(null);
186
        setMinError(null);
187
        setMaxError(null);
188
    };
189
 
190
    return {
191
        setEventId: setEventId,
192
        getEventId: getEventId,
193
        hasEventId: hasEventId,
194
        setDurationDays: setDurationDays,
195
        getDurationDays: getDurationDays,
196
        setMinTimestart: setMinTimestart,
197
        getMinTimestart: getMinTimestart,
198
        hasMinTimestart: hasMinTimestart,
199
        setMaxTimestart: setMaxTimestart,
200
        getMaxTimestart: getMaxTimestart,
201
        hasMaxTimestart: hasMaxTimestart,
202
        setMinError: setMinError,
203
        getMinError: getMinError,
204
        setMaxError: setMaxError,
205
        getMaxError: getMaxError,
206
        clearAll: clearAll
207
    };
208
});