1
|
|
|
const openpsa_calendar_widget = { |
2
|
|
|
popstate: false, |
3
|
|
|
refresh: function() { |
4
|
|
|
if (window.opener.openpsa_calendar_instance) { |
5
|
|
|
window.opener.openpsa_calendar_instance.refetchEvents(); |
6
|
|
|
} |
7
|
|
|
}, |
8
|
|
|
prepare_toolbar_buttons: function(selector, prefix) { |
9
|
|
|
$('#openpsa_calendar_add_event').on('click', function() { |
10
|
|
|
var date = window.openpsa_calendar_instance.getDate(); |
11
|
|
|
this.href = prefix + 'event/new/?start=' + window.openpsa_calendar_instance.formatIso(date, true); |
12
|
|
|
}); |
13
|
|
|
$("#date-navigation").parent().on("click", function(event) { |
14
|
|
|
event.preventDefault(); |
15
|
|
|
if ( event.target.parentNode.id !== 'date-navigation' |
16
|
|
|
&& event.target.id !== 'date-navigation') { |
17
|
|
|
//don't fire on datepicker navigation clicks |
18
|
|
|
return; |
19
|
|
|
} |
20
|
|
|
if ($(this).hasClass("active")) { |
21
|
|
|
$(this).removeClass("active"); |
22
|
|
|
$("#date-navigation-widget").hide(); |
23
|
|
|
} else if ($(this).hasClass("initialized")) { |
24
|
|
|
$("#date-navigation-widget").show(); |
25
|
|
|
$(this).addClass("active"); |
26
|
|
|
} else { |
27
|
|
|
$("#date-navigation").append("<div id=\"date-navigation-widget\"></div>"); |
28
|
|
|
$("#date-navigation-widget").css("position", "absolute"); |
29
|
|
|
$("#date-navigation-widget").css("z-index", "1000"); |
30
|
|
|
var default_date = window.openpsa_calendar_instance.getDate(); |
31
|
|
|
$("#date-navigation-widget").datepicker({ |
32
|
|
|
dateFormat: "yy-mm-dd", |
33
|
|
|
initialDate: default_date, |
34
|
|
|
prevText: "", |
35
|
|
|
nextText: "", |
36
|
|
|
onSelect: function(dateText) { |
37
|
|
|
window.openpsa_calendar_instance.gotoDate(new Date(dateText)); |
38
|
|
|
|
39
|
|
|
$("#date-navigation").parent().removeClass("active"); |
40
|
|
|
$("#date-navigation-widget").hide(); |
41
|
|
|
} |
42
|
|
|
}); |
43
|
|
|
$(this).addClass("active"); |
44
|
|
|
$(this).addClass("initialized"); |
45
|
|
|
} |
46
|
|
|
}); |
47
|
|
|
}, |
48
|
|
|
parse_url: function(prefix) { |
49
|
|
|
var args = location.pathname.substr(prefix.length).split('/'), |
50
|
|
|
settings = {}; |
51
|
|
|
if (args[0] !== undefined) { |
52
|
|
|
switch (args[0]) { |
53
|
|
|
case 'dayGridMonth': |
54
|
|
|
case 'dayGridDay': |
55
|
|
|
case 'dayGridWeek': |
56
|
|
|
case 'timeGridDay': |
57
|
|
|
case 'timeGridWeek': |
58
|
|
|
settings.initialView = args[0]; |
59
|
|
|
break; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
if (args[1] !== undefined) { |
63
|
|
|
settings.initialDate = args[1]; |
64
|
|
|
} |
65
|
|
|
return settings; |
66
|
|
|
}, |
67
|
|
|
update_url: function(selector, prefix) { |
68
|
|
|
var last_state = history.state, |
69
|
|
|
view = window.openpsa_calendar_instance.view, |
70
|
|
|
state_data = { |
71
|
|
|
date: window.openpsa_calendar_instance.formatIso(window.openpsa_calendar_instance.getDate(), true), |
72
|
|
|
view: view.type |
73
|
|
|
}, |
74
|
|
|
new_url = prefix + view.type + '/' + state_data.date + '/'; |
75
|
|
|
// skip if the last state was same as current, or if we were triggered via a popstate event |
76
|
|
|
if (!openpsa_calendar_widget.popstate && (!last_state || prefix + last_state.name + '/' + last_state.view + '/' !== new_url)) { |
77
|
|
|
history.pushState(state_data, view.title + ' ' + $('body').data('title'), new_url); |
78
|
|
|
} |
79
|
|
|
}, |
80
|
|
|
initialize: function(selector, prefix, settings, embedded) { |
81
|
|
|
function save_event(info) { |
82
|
|
|
var params = { |
83
|
|
|
start: ((info.event.start.getTime() / 1000) - info.event.start.getTimezoneOffset() * 60) + 1 |
84
|
|
|
}; |
85
|
|
|
//workaround for https://github.com/fullcalendar/fullcalendar/issues/3037 |
86
|
|
|
if (info.event.end) { |
87
|
|
|
params.end = (info.event.end.getTime() / 1000) - info.event.end.getTimezoneOffset() * 60; |
88
|
|
|
} |
89
|
|
|
$.post(prefix + 'event/move/' + info.event.id + '/', params) |
90
|
|
|
.fail(function() { |
91
|
|
|
info.revert(); |
92
|
|
|
}); |
93
|
|
|
} |
94
|
|
|
$('body').data('title', document.title); |
95
|
|
|
|
96
|
|
|
var defaults = { |
97
|
|
|
initialView: "dayGridMonth", |
98
|
|
|
weekNumbers: true, |
99
|
|
|
nowIndicator: true, |
100
|
|
|
editable: true, |
101
|
|
|
navLinks: true, |
102
|
|
|
height: '100%', |
103
|
|
|
headerToolbar: { |
104
|
|
|
left: 'dayGridMonth,timeGridWeek,timeGridDay', |
105
|
|
|
center: 'title', |
106
|
|
|
right: 'today prev,next' |
107
|
|
|
}, |
108
|
|
|
events: function (fetch_info, success_callback, failure_callback) { |
109
|
|
|
$.ajax({ |
110
|
|
|
url: prefix + 'json/', |
111
|
|
|
dataType: 'json', |
112
|
|
|
data: { |
113
|
|
|
start: fetch_info.start.getTime() / 1000, |
114
|
|
|
end: fetch_info.end.getTime() / 1000 |
115
|
|
|
}, |
116
|
|
|
success: success_callback, |
117
|
|
|
error: failure_callback |
118
|
|
|
}); |
119
|
|
|
}, |
120
|
|
|
datesSet: function() { |
121
|
|
|
if (!embedded) { |
122
|
|
|
openpsa_calendar_widget.update_url(selector, prefix); |
123
|
|
|
} |
124
|
|
|
}, |
125
|
|
|
eventContent: function (info) { |
126
|
|
|
if (info.event.extendedProps.participants) { |
|
|
|
|
127
|
|
|
if (info.timeText && info.view.type === 'dayGridMonth') { |
128
|
|
|
return { |
129
|
|
|
html: '<div class="fc-daygrid-event-dot"></div><div class="fc-event-time">' + info.timeText + '</div><div class="fc-event-title">' + info.event.title + '</div><div class="participants">(' + info.event.extendedProps.participants.join(', ') + ')</div>' |
130
|
|
|
}; |
131
|
|
|
} |
132
|
|
|
return { |
133
|
|
|
html: '<div class="fc-event-main-frame"><div class="fc-event-time">' + info.timeText + '</div><div class="fc-event-title-container"><div class="fc-event-title fc-sticky">' + info.event.title + '</div><div class="participants">(' + info.event.extendedProps.participants.join(', ') + ')</div></div></div>' |
134
|
|
|
}; |
135
|
|
|
} |
136
|
|
|
}, |
137
|
|
|
eventClick: function (info) { |
138
|
|
|
info.jsEvent.preventDefault(); |
139
|
|
|
info.jsEvent.target.dataset.dialogCancelLabel = settings.l10n.cancel; |
140
|
|
|
create_dialog($(info.jsEvent.target), '', prefix + 'event/' + info.event.id + '/'); |
141
|
|
|
}, |
142
|
|
|
selectable: true, |
143
|
|
|
select: function(info) { |
144
|
|
|
var url = prefix + 'event/new/?start=', |
145
|
|
|
start = window.openpsa_calendar_instance.formatIso(info.start), |
146
|
|
|
end = window.openpsa_calendar_instance.formatIso(info.end); |
147
|
|
|
create_dialog($('#openpsa_calendar_add_event'), '', url + encodeURIComponent(start) + '&end=' + encodeURIComponent(end)); |
148
|
|
|
}, |
149
|
|
|
eventDrop: save_event, |
150
|
|
|
eventResize: save_event |
151
|
|
|
}; |
152
|
|
|
|
153
|
|
|
settings = $.extend({}, defaults, openpsa_calendar_widget.parse_url(prefix), settings || {}); |
154
|
|
|
|
155
|
|
|
window.openpsa_calendar_instance = new FullCalendar.Calendar($(selector)[0], settings); |
156
|
|
|
window.openpsa_calendar_instance.render(); |
157
|
|
|
|
158
|
|
|
openpsa_calendar_widget.prepare_toolbar_buttons(selector, prefix); |
159
|
|
|
|
160
|
|
|
if (!embedded) { |
161
|
|
|
if (window.hasOwnProperty('history')) { |
162
|
|
|
window.onpopstate = function(event) { |
163
|
|
|
if (event.state) { |
164
|
|
|
openpsa_calendar_widget.popstate = true; |
165
|
|
|
window.openpsa_calendar_instance.gotoDate(event.state.date); |
166
|
|
|
window.openpsa_calendar_instance.changeView(event.state.view); |
167
|
|
|
openpsa_calendar_widget.popstate = false; |
168
|
|
|
} |
169
|
|
|
}; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
}; |
174
|
|
|
|
This check looks for functions where a
return
statement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBig
will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined
.This behaviour may not be what you had intended. In any case, you can add a
return undefined
to the other execution path to make the return value explicit.