2015-02-17 01:58:04 -06:00
|
|
|
function toggleVisibility(node, nodeType){
|
|
|
|
// Toggle visibility of all elements having p_nodeType within p_node
|
|
|
|
var elements = node.getElementsByTagName(nodeType);
|
|
|
|
for (var i=0; i<elements.length; i++){
|
|
|
|
var sNode = elements[i];
|
|
|
|
if (sNode.style.visibility == 'hidden') sNode.style.visibility = 'visible';
|
|
|
|
else sNode.style.visibility = 'hidden';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-19 08:59:31 -06:00
|
|
|
function askCalendar(hookId, objectUrl, render, fieldName, month) {
|
|
|
|
// Sends an Ajax request for getting the calendar, at p_month
|
|
|
|
var params = {'month': month, 'render': render};
|
|
|
|
askAjaxChunk(hookId, 'GET', objectUrl, fieldName+':pxView', params);
|
2012-10-03 07:44:34 -05:00
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2013-08-21 05:35:30 -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 = {};
|
2015-02-17 01:58:04 -06:00
|
|
|
// Put form elements into "params"
|
2012-10-03 07:44:34 -05:00
|
|
|
for (var i=0; i < elems.length; i++) {
|
|
|
|
params[elems[i].name] = elems[i].value;
|
|
|
|
}
|
|
|
|
closePopup(prefix + 'Popup');
|
2015-02-19 08:59:31 -06:00
|
|
|
askAjaxChunk(hookId, 'POST', objectUrl, fieldName+':pxView', params);
|
2012-10-03 07:44:34 -05:00
|
|
|
}
|