2012-10-03 07:44:34 -05:00
|
|
|
function askMonthView(hookId, objectUrl, fieldName, month) {
|
|
|
|
// Sends an Ajax request for getting the view month of a calendar field
|
|
|
|
var params = {'fieldName': fieldName, 'month': month};
|
|
|
|
askAjaxChunk(hookId,'GET',objectUrl,'widgets/calendar','viewMonth', params);
|
|
|
|
}
|
|
|
|
|
2012-10-29 23:53:45 -05:00
|
|
|
function openEventPopup(action, fieldName, day, spansDays,
|
|
|
|
applicableEventTypes, message) {
|
2012-10-03 07:44:34 -05:00
|
|
|
/* Opens the popup for creating (or deleting, depending on p_action) a
|
|
|
|
calendar event at some p_day. When action is "del", we need to know
|
|
|
|
(from p_spansDays) if the event spans more days, in order to propose a
|
2012-10-29 23:53:45 -05:00
|
|
|
checkbox allowing to delete events for those successive days. When action
|
|
|
|
is "new", a possibly restricted list of applicable event types for this
|
|
|
|
day is given in p_applicableEventTypes; p_message contains an optional
|
|
|
|
message explaining why not applicable types are not applicable. */
|
2012-10-03 07:44:34 -05:00
|
|
|
var prefix = fieldName + '_' + action + 'Event';
|
|
|
|
var f = document.getElementById(prefix + 'Form');
|
|
|
|
f.day.value = day;
|
|
|
|
if (action == 'del') {
|
2012-10-29 23:53:45 -05:00
|
|
|
// Show or hide the checkbox for deleting the event for successive days.
|
2012-10-03 07:44:34 -05:00
|
|
|
var elem = document.getElementById(prefix + 'DelNextEvent');
|
|
|
|
var cb = elem.getElementsByTagName('input');
|
|
|
|
cb[0].checked = false;
|
|
|
|
cb[1].value = 'False';
|
|
|
|
if (spansDays == 'True') { elem.style.display = 'block' }
|
|
|
|
else { elem.style.display = 'none' }
|
|
|
|
}
|
2012-10-29 23:53:45 -05:00
|
|
|
else if (action == 'new') {
|
|
|
|
// First: reinitialise input fields
|
|
|
|
f.eventType.style.background = '';
|
|
|
|
var allOptions = f.eventType.options;
|
|
|
|
for (var i=0; i < allOptions.length; i++) {
|
|
|
|
allOptions[i].selected = false;
|
|
|
|
}
|
|
|
|
f.eventSpan.style.background = '';
|
|
|
|
// Among all event types, show applicable ones and hide the others.
|
|
|
|
var applicable = applicableEventTypes.split(',');
|
|
|
|
var applicableDict = {};
|
|
|
|
for (var i=0; i < applicable.length; i++) {
|
|
|
|
applicableDict[applicable[i]] = true;
|
|
|
|
}
|
|
|
|
for (var i=0; i < allOptions.length; i++) {
|
|
|
|
if (!allOptions[i].value) continue;
|
|
|
|
if (allOptions[i].value in applicableDict) {
|
|
|
|
allOptions[i].disabled = false;
|
|
|
|
allOptions[i].title = '';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
allOptions[i].disabled = true;
|
|
|
|
allOptions[i].title = message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-03 07:44:34 -05:00
|
|
|
openPopup(prefix + 'Popup');
|
|
|
|
}
|
|
|
|
|
2012-10-05 22:20:35 -05:00
|
|
|
function triggerCalendarEvent(action, hookId, fieldName, objectUrl, maxEventLength) {
|
2012-10-03 07:44:34 -05:00
|
|
|
/* Sends an Ajax request for triggering a calendar event (create or delete an
|
|
|
|
event) and refreshing the view month. */
|
|
|
|
var prefix = fieldName + '_' + action + 'Event';
|
|
|
|
var f = document.getElementById(prefix + 'Form');
|
|
|
|
if (action == 'new') {
|
2012-10-29 23:53:45 -05:00
|
|
|
// Check that an event span has been specified
|
|
|
|
if (f.eventType.selectedIndex == 0) {
|
|
|
|
f.eventType.style.background = wrongTextInput;
|
|
|
|
return;
|
|
|
|
}
|
2012-10-03 07:44:34 -05:00
|
|
|
// Check that eventSpan is empty or contains a valid number
|
|
|
|
var spanNumber = f.eventSpan.value.replace(' ', '');
|
|
|
|
if (spanNumber) {
|
2012-10-05 22:20:35 -05:00
|
|
|
spanNumber = parseInt(spanNumber);
|
|
|
|
if (isNaN(spanNumber) || (spanNumber > maxEventLength)) {
|
2012-10-03 07:44:34 -05:00
|
|
|
f.eventSpan.style.background = wrongTextInput;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var elems = f.elements;
|
|
|
|
var params = {};
|
|
|
|
// Put form elements into "params".
|
|
|
|
for (var i=0; i < elems.length; i++) {
|
|
|
|
params[elems[i].name] = elems[i].value;
|
|
|
|
}
|
|
|
|
closePopup(prefix + 'Popup');
|
|
|
|
askAjaxChunk(hookId,'POST',objectUrl,'widgets/calendar','viewMonth',params);
|
|
|
|
}
|