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 handle calendar ajax actions.
18
 *
19
 * @module     core_calendar/repository
20
 * @copyright  2017 Simey Lameze <lameze@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
import Ajax from 'core/ajax';
24
 
25
/**
26
 * Delete a calendar event.
27
 *
28
 * @method deleteEvent
29
 * @param {number} eventId The event id.
30
 * @param {boolean} deleteSeries Whether to delete all events in the series
31
 * @return {promise} Resolved with requested calendar event
32
 */
33
export const deleteEvent = (eventId, deleteSeries = false) => {
34
    const request = {
35
        methodname: 'core_calendar_delete_calendar_events',
36
        args: {
37
            events: [{
38
                eventid: eventId,
39
                repeat: deleteSeries,
40
            }]
41
        }
42
    };
43
 
44
    return Ajax.call([request])[0];
45
};
46
 
47
/**
48
 * Get a calendar event by id.
49
 *
50
 * @method getEventById
51
 * @param {number} eventId The event id.
52
 * @return {promise} Resolved with requested calendar event
53
 */
54
export const getEventById = (eventId) => {
55
 
56
    const request = {
57
        methodname: 'core_calendar_get_calendar_event_by_id',
58
        args: {
59
            eventid: eventId
60
        }
61
    };
62
 
63
    return Ajax.call([request])[0];
64
};
65
 
66
/**
67
 * Submit the form data for the event form.
68
 *
69
 * @method submitCreateUpdateForm
70
 * @param {string} formData The URL encoded values from the form
71
 * @return {promise} Resolved with the new or edited event
72
 */
73
export const submitCreateUpdateForm = (formData) => {
74
    const request = {
75
        methodname: 'core_calendar_submit_create_update_form',
76
        args: {
77
            formdata: formData
78
        }
79
    };
80
 
81
    return Ajax.call([request])[0];
82
};
83
 
84
/**
85
 * Get calendar data for the month view.
86
 *
87
 * @method getCalendarMonthData
88
 * @param {number} year Year
89
 * @param {number} month Month
90
 * @param {number} courseId The course id.
91
 * @param {number} categoryId The category id.
92
 * @param {boolean} includeNavigation Whether to include navigation.
93
 * @param {boolean} mini Whether the month is in mini view.
94
 * @param {number} day Day (optional)
95
 * @param {string} view The calendar view mode.
96
 * @return {promise} Resolved with the month view data.
97
 */
98
export const getCalendarMonthData = (year, month, courseId, categoryId, includeNavigation, mini, day = 1, view = 'month') => {
99
    const request = {
100
        methodname: 'core_calendar_get_calendar_monthly_view',
101
        args: {
102
            year,
103
            month,
104
            courseid: courseId,
105
            categoryid: categoryId,
106
            includenavigation: includeNavigation,
107
            mini,
108
            day,
109
            view,
110
        }
111
    };
112
 
113
    return Ajax.call([request])[0];
114
};
115
 
116
/**
117
 * Get calendar data for the day view.
118
 *
119
 * @method getCalendarDayData
120
 * @param {number} year Year
121
 * @param {number} month Month
122
 * @param {number} day Day
123
 * @param {number} courseId The course id.
124
 * @param {number} categoryId The id of the category whose events are shown
125
 * @return {promise} Resolved with the day view data.
126
 */
127
export const getCalendarDayData = (year, month, day, courseId, categoryId) => {
128
    const request = {
129
        methodname: 'core_calendar_get_calendar_day_view',
130
        args: {
131
            year,
132
            month,
133
            day,
134
            courseid: courseId,
135
            categoryid: categoryId,
136
        }
137
    };
138
 
139
    return Ajax.call([request])[0];
140
};
141
 
142
/**
143
 * Change the start day for the given event id. The day timestamp
144
 * only has to be any time during the target day because only the
145
 * date information is extracted, the time of the day is ignored.
146
 *
147
 * @param {int} eventId The id of the event to update
148
 * @param {int} dayTimestamp A timestamp for some time during the target day
149
 * @return {promise}
150
 */
151
export const updateEventStartDay = (eventId, dayTimestamp) => {
152
    const request = {
153
        methodname: 'core_calendar_update_event_start_day',
154
        args: {
155
            eventid: eventId,
156
            daytimestamp: dayTimestamp
157
        }
158
    };
159
 
160
    return Ajax.call([request])[0];
161
};
162
 
163
/**
164
 * Get calendar upcoming data.
165
 *
166
 * @method getCalendarUpcomingData
167
 * @param {number} courseId The course id.
168
 * @param {number} categoryId The category id.
169
 * @return {promise} Resolved with the month view data.
170
 */
171
export const getCalendarUpcomingData = (courseId, categoryId) => {
172
    const request = {
173
        methodname: 'core_calendar_get_calendar_upcoming_view',
174
        args: {
175
            courseid: courseId,
176
            categoryid: categoryId,
177
        }
178
    };
179
 
180
    return Ajax.call([request])[0];
181
};
182
 
183
/**
184
 * Get the groups by course id.
185
 *
186
 * @param {Number} courseId The course id to fetch the groups from.
187
 * @return {promise} Resolved with the course groups.
188
 */
189
export const getCourseGroupsData = (courseId) => {
190
    const request = {
191
        methodname: 'core_group_get_course_groups',
192
        args: {
193
            courseid: courseId
194
        }
195
    };
196
 
197
    return Ajax.call([request])[0];
198
};
199
 
200
/**
201
 * Delete calendar subscription by id.
202
 *
203
 * @param {Number} subscriptionId The subscription id
204
 * @return {promise}
205
 */
206
export const deleteSubscription = (subscriptionId) => {
207
    const request = {
208
        methodname: 'core_calendar_delete_subscription',
209
        args: {
210
            subscriptionid: subscriptionId
211
        }
212
    };
213
 
214
    return Ajax.call([request])[0];
215
};