2008-01-15 00:17:19 +01:00
|
|
|
var RecurrenceEditor = {
|
|
|
|
types: new Array("Daily", "Weekly", "Monthly", "Yearly"),
|
|
|
|
currentRepeatType: 0
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:10:25 +01:00
|
|
|
function onRepeatTypeChange(event) {
|
|
|
|
setRepeatType(parseInt(this.value));
|
|
|
|
}
|
2008-01-15 00:17:19 +01:00
|
|
|
|
|
|
|
function setRepeatType(type) {
|
|
|
|
var elements;
|
|
|
|
|
|
|
|
RecurrenceEditor.currentRepeatType = type;
|
|
|
|
|
2008-01-15 22:45:48 +01:00
|
|
|
for (var i = 0; i <= 3; i++) {
|
2008-01-15 00:17:19 +01:00
|
|
|
elements = $$("TABLE TR.recurrence" + RecurrenceEditor.types[i]);
|
|
|
|
if (i != type)
|
|
|
|
elements.each(function(row) {
|
|
|
|
row.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
elements = $$("TABLE TR.recurrence" + RecurrenceEditor.types[type]);
|
|
|
|
elements.each(function(row) {
|
|
|
|
row.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-03-27 15:12:03 +01:00
|
|
|
function getSelectedDays(periodType) {
|
|
|
|
var element = $(periodType);
|
2008-01-15 22:45:48 +01:00
|
|
|
var elementsArray = $A(element.getElementsByTagName('DIV'));
|
|
|
|
var days = new Array();
|
2008-03-27 15:12:03 +01:00
|
|
|
var dayPrefix = periodType + "Day";
|
2008-01-15 22:45:48 +01:00
|
|
|
elementsArray.each(function(item) {
|
2008-03-27 15:12:03 +01:00
|
|
|
if (isNodeSelected(item)) {
|
|
|
|
var label = "" + item.getAttribute("id");
|
|
|
|
days.push(label.substr(dayPrefix.length));
|
|
|
|
}
|
2008-01-15 22:45:48 +01:00
|
|
|
});
|
|
|
|
return days.join(",");
|
|
|
|
}
|
|
|
|
|
2008-01-15 00:17:19 +01:00
|
|
|
function onDayClick(event) {
|
|
|
|
var element = $(this);
|
2008-01-15 22:45:48 +01:00
|
|
|
if (isNodeSelected(element))
|
|
|
|
this.removeClassName("_selected");
|
2008-01-15 00:17:19 +01:00
|
|
|
else
|
2008-01-15 22:45:48 +01:00
|
|
|
this.addClassName("_selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRangeChange(event) {
|
|
|
|
$('endDate_date').disabled = (this.value != 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAdjustTime(event) {
|
|
|
|
// must be defined for date picker widget
|
2008-01-15 00:17:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function initializeSelectors() {
|
2008-01-15 22:45:48 +01:00
|
|
|
$$("DIV#week SPAN.week DIV").each(function(element) {
|
2008-01-15 00:17:19 +01:00
|
|
|
element.observe("click", onDayClick, false);
|
|
|
|
});
|
|
|
|
|
2008-01-15 22:45:48 +01:00
|
|
|
$$("DIV#month SPAN.week DIV").each(function(element) {
|
2008-01-15 00:17:19 +01:00
|
|
|
element.observe("click", onDayClick, false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-01-14 14:57:28 +01:00
|
|
|
function initializeWindowButtons() {
|
2008-02-08 18:10:25 +01:00
|
|
|
var okButton = $("okButton");
|
|
|
|
var cancelButton = $("cancelButton");
|
2008-01-14 14:57:28 +01:00
|
|
|
|
2008-02-08 18:10:25 +01:00
|
|
|
Event.observe(okButton, "click", onEditorOkClick, false);
|
|
|
|
Event.observe(cancelButton, "click", onEditorCancelClick, false);
|
2008-01-15 00:17:19 +01:00
|
|
|
|
2008-02-08 18:10:25 +01:00
|
|
|
var repeatType = $("repeatType");
|
|
|
|
setRepeatType(parseInt(repeatType.value));
|
|
|
|
repeatType.observe("change", onRepeatTypeChange, false);
|
2008-01-14 14:57:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function initializeFormValues() {
|
2008-01-15 00:17:19 +01:00
|
|
|
var repeatType = parent$("repeatType").value;
|
2008-01-14 14:57:28 +01:00
|
|
|
|
2008-01-15 22:45:48 +01:00
|
|
|
// Select repeat type
|
|
|
|
$("repeatType").value = repeatType;
|
|
|
|
|
|
|
|
// Default values
|
|
|
|
$('recurrence_form').setRadioValue('dailyRadioButtonName', 0);
|
|
|
|
$('recurrence_form').setRadioValue('monthlyRadioButtonName', 0);
|
|
|
|
$('recurrence_form').setRadioValue('yearlyRadioButtonName', 0);
|
|
|
|
$('endDate_date').disabled = true;
|
|
|
|
|
|
|
|
if (repeatType == 0) {
|
|
|
|
// Repeat daily
|
2008-01-14 14:57:28 +01:00
|
|
|
$('recurrence_form').setRadioValue('dailyRadioButtonName', parent$("repeat1").value);
|
|
|
|
$('dailyDaysField').value = parent$("repeat2").value;
|
|
|
|
}
|
2008-01-15 22:45:48 +01:00
|
|
|
else if (repeatType == 1) {
|
|
|
|
// Repeat weekly
|
2008-01-14 14:57:28 +01:00
|
|
|
$('weeklyWeeksField').value = parent$("repeat1").value;
|
2008-02-08 20:39:53 +01:00
|
|
|
// log ("div: " + weekDiv);
|
|
|
|
// log ("days: " + parent$("repeat2").value);
|
2008-02-08 20:38:05 +01:00
|
|
|
var days = "" + parent$("repeat2").value;
|
|
|
|
if (days.length > 0) {
|
|
|
|
var daysArray = days.split(",");
|
|
|
|
daysArray.each(function(index) {
|
2008-03-27 15:12:03 +01:00
|
|
|
$("weekDay"+index).addClassName("_selected");
|
2008-01-15 22:45:48 +01:00
|
|
|
});
|
2008-02-08 20:38:05 +01:00
|
|
|
}
|
2008-01-14 14:57:28 +01:00
|
|
|
}
|
2008-01-15 22:45:48 +01:00
|
|
|
else if (repeatType == 2) {
|
|
|
|
// Repeat monthly
|
2008-01-14 14:57:28 +01:00
|
|
|
$('monthlyMonthsField').value = parent$("repeat1").value;
|
|
|
|
$('recurrence_form').setRadioValue('monthlyRadioButtonName', parent$("repeat2").value);
|
|
|
|
$('monthlyRepeat').value = parent$("repeat3").value;
|
|
|
|
$('monthlyDay').value = parent$("repeat4").value;
|
2008-02-08 20:38:05 +01:00
|
|
|
var days = "" + parent$("repeat5").value;
|
|
|
|
if (days.length > 0) {
|
|
|
|
var daysArray = days.split(",");
|
|
|
|
daysArray.each(function(index) {
|
2008-03-27 15:12:03 +01:00
|
|
|
$("monthDay" + index).addClassName("_selected");
|
2008-02-08 20:38:05 +01:00
|
|
|
});
|
|
|
|
}
|
2008-01-14 14:57:28 +01:00
|
|
|
}
|
2008-01-15 00:17:19 +01:00
|
|
|
else if (repeatType == 3) {
|
2008-01-15 22:45:48 +01:00
|
|
|
// Repeat yearly
|
2008-01-14 14:57:28 +01:00
|
|
|
$('yearlyYearsField').value = parent$("repeat1").value;
|
|
|
|
$('recurrence_form').setRadioValue('yearlyRadioButtonName', parent$("repeat2").value);
|
|
|
|
$('yearlyDayField').value = parent$("repeat3").value;
|
|
|
|
$('yearlyMonth1').value = parent$("repeat4").value;
|
|
|
|
$('yearlyRepeat').value = parent$("repeat5").value;
|
|
|
|
$('yearlyDay').value = parent$("repeat6").value;
|
|
|
|
$('yearlyMonth2').value = parent$("repeat7").value;
|
|
|
|
}
|
2008-01-15 22:45:48 +01:00
|
|
|
else
|
|
|
|
repeatType = 0;
|
|
|
|
|
|
|
|
setRepeatType(repeatType);
|
2008-01-14 14:57:28 +01:00
|
|
|
|
2008-01-15 22:45:48 +01:00
|
|
|
var range = parent$("range1").value;
|
|
|
|
$('recurrence_form').setRadioValue('rangeRadioButtonName', range);
|
2008-01-14 14:57:28 +01:00
|
|
|
|
2008-01-15 22:45:48 +01:00
|
|
|
if (range == 1) {
|
2008-01-14 14:57:28 +01:00
|
|
|
$('rangeAppointmentsField').value = parent$("range2").value;
|
|
|
|
}
|
2008-01-15 22:45:48 +01:00
|
|
|
else if (range == 2) {
|
2008-01-16 18:07:46 +01:00
|
|
|
$('endDate_date').value = parent$("range2").value;
|
2008-01-15 22:45:48 +01:00
|
|
|
$('endDate_date').disabled = false;
|
2008-01-14 14:57:28 +01:00
|
|
|
}
|
2008-01-15 22:45:48 +01:00
|
|
|
|
|
|
|
// Observe change of range radio buttons to activate the date picker when required
|
|
|
|
Form.getInputs($('recurrence_form'), 'radio', 'rangeRadioButtonName').each(function(input) {
|
|
|
|
input.observe("change", onRangeChange);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Show page
|
|
|
|
$("recurrence_pattern").show();
|
|
|
|
$("range_of_recurrence").show();
|
2008-01-14 14:57:28 +01:00
|
|
|
}
|
|
|
|
|
2008-02-08 18:10:25 +01:00
|
|
|
function handleDailyRecurrence() {
|
|
|
|
var validate = false;
|
|
|
|
|
|
|
|
var radioValue = $('recurrence_form').getRadioValue('dailyRadioButtonName');
|
|
|
|
|
|
|
|
// We check if the dailyDaysField really contains an integer
|
|
|
|
if (radioValue == 0) {
|
|
|
|
var showError = true;
|
|
|
|
|
|
|
|
var v = "" + $('dailyDaysField').value;
|
|
|
|
if (v.length > 0) {
|
|
|
|
v = parseInt(v);
|
2008-02-08 20:39:53 +01:00
|
|
|
// log("v: " + v);
|
2008-02-08 18:10:25 +01:00
|
|
|
if (!isNaN(v) && v > 0) {
|
|
|
|
validate = true;
|
|
|
|
showError = false;
|
|
|
|
parent$("repeat1").value = radioValue;
|
|
|
|
parent$("repeat2").value = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showError)
|
|
|
|
window.alert("Please specify a numerical value in the Days field greater or equal to 1.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
validate = true;
|
|
|
|
parent$("repeat1").value = radioValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return validate;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleWeeklyRecurrence() {
|
|
|
|
var validate = false;
|
|
|
|
|
|
|
|
var showError = true;
|
|
|
|
var fieldValue = "" + $('weeklyWeeksField').value;
|
|
|
|
if (fieldValue.length > 0) {
|
|
|
|
// We check if the weeklyWeeksField really contains an integer
|
|
|
|
var v = parseInt(fieldValue);
|
|
|
|
if (!isNaN(v) && v > 0) {
|
|
|
|
validate = true;
|
|
|
|
showError = false;
|
|
|
|
parent$("repeat1").value = fieldValue;
|
2008-03-27 15:12:03 +01:00
|
|
|
parent$("repeat2").value = getSelectedDays("week");
|
2008-02-08 18:10:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showError)
|
|
|
|
window.alert("Please specify a numerical value in the Week(s) field greater or equal to 1.");
|
|
|
|
|
|
|
|
return validate;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleMonthlyRecurrence() {
|
|
|
|
var validate = false;
|
|
|
|
|
|
|
|
var radioValue = $('recurrence_form').getRadioValue('monthlyRadioButtonName');
|
|
|
|
|
|
|
|
// FIXME - right now we do not support rules
|
|
|
|
// such as The Second Tuesday...
|
|
|
|
if (radioValue == 0)
|
|
|
|
window.alert("This type of recurrence is currently unsupported.");
|
|
|
|
else {
|
|
|
|
// We check if the monthlyMonthsField really contains an integer
|
|
|
|
var showError = true;
|
|
|
|
|
|
|
|
var fieldValue = "" + $('monthlyMonthsField').value;
|
|
|
|
if (fieldValue.length > 0) {
|
|
|
|
var v = parseInt(fieldValue);
|
|
|
|
if (!isNaN(v) && v > 0) {
|
|
|
|
validate = true;
|
|
|
|
showError = false;
|
|
|
|
parent$("repeat1").value = fieldValue;
|
|
|
|
parent$("repeat2").value = radioValue;
|
|
|
|
parent$("repeat3").value = $('monthlyRepeat').value;
|
|
|
|
parent$("repeat4").value = $('monthlyDay').value;
|
2008-03-27 15:12:03 +01:00
|
|
|
parent$("repeat5").value = getSelectedDays("month");
|
2008-02-08 18:10:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showError)
|
|
|
|
window.alert("Please specify a numerical value in the Month(s) field greater or equal to 1.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return validate;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleYearlyRecurrence() {
|
|
|
|
var validate = false;
|
|
|
|
|
|
|
|
var radioValue = $('recurrence_form').getRadioValue('yearlyRadioButtonName');
|
|
|
|
|
|
|
|
// FIXME - right now we do not support rules
|
|
|
|
// such as Every Second Tuesday of February
|
|
|
|
if (radioValue == 1)
|
|
|
|
window.alert("This type of recurrence is currently unsupported.");
|
|
|
|
else {
|
|
|
|
var showError = true;
|
|
|
|
|
|
|
|
var fieldValue = "" + $('yearlyYearsField').value;
|
|
|
|
if (fieldValue.length > 0) {
|
|
|
|
// We check if the yearlyYearsField really contains an integer
|
|
|
|
var v = parseInt(fieldValue);
|
|
|
|
if (!isNaN(v) && v > 0) {
|
|
|
|
validate = true;
|
|
|
|
showError = false;
|
|
|
|
parent$("repeat1").value = fieldValue;
|
|
|
|
parent$("repeat2").value = radioValue;
|
|
|
|
parent$("repeat3").value = $('yearlyDayField').value;
|
|
|
|
parent$("repeat4").value = $('yearlyMonth1').value;
|
|
|
|
parent$("repeat5").value = $('yearlyRepeat').value;
|
|
|
|
parent$("repeat6").value = $('yearlyDay').value;
|
|
|
|
parent$("repeat7").value = $('yearlyMonth2').value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showError)
|
|
|
|
window.alert("Please specify a numerical value in the Year(s) field greater or equal to 1.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return validate;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleRange() {
|
|
|
|
var validate = false;
|
|
|
|
|
|
|
|
var radioValue = $('recurrence_form').getRadioValue('rangeRadioButtonName');
|
|
|
|
if (radioValue == 0)
|
|
|
|
validate = true;
|
|
|
|
else if (radioValue == 1) {
|
|
|
|
var showError = true;
|
|
|
|
|
|
|
|
var fieldValue = "" + $('rangeAppointmentsField').value;
|
|
|
|
if (fieldValue.length > 0) {
|
|
|
|
// We check if the rangeAppointmentsField really contains an integer
|
|
|
|
var v = parseInt(fieldValue);
|
|
|
|
if (!isNaN(v) && v > 0) {
|
|
|
|
validate = true;
|
|
|
|
showError = false;
|
|
|
|
parent$("range2").value = fieldValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showError)
|
|
|
|
window.alert("Please specify a numerical value in the Appointment(s) field greater or equal to 1.");
|
|
|
|
}
|
|
|
|
else if (radioValue == 2) {
|
|
|
|
validate = true;
|
|
|
|
parent$("range2").value = $('endDate_date').value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validate)
|
|
|
|
parent$("range1").value = radioValue;
|
|
|
|
|
|
|
|
return validate;
|
|
|
|
}
|
|
|
|
|
2008-01-14 14:57:28 +01:00
|
|
|
function onEditorOkClick(event) {
|
2008-02-08 18:10:25 +01:00
|
|
|
preventDefault(event);
|
|
|
|
var repeatType = $("repeatType").value;
|
|
|
|
parent$("repeatType").value = repeatType;
|
|
|
|
|
|
|
|
var validate;
|
|
|
|
if (repeatType == 0)
|
|
|
|
validate = handleDailyRecurrence();
|
|
|
|
else if (repeatType == 1)
|
|
|
|
validate = handleWeeklyRecurrence();
|
|
|
|
else if (repeatType == 2)
|
|
|
|
validate = handleMonthlyRecurrence();
|
|
|
|
else
|
|
|
|
validate = handleYearlyRecurrence();
|
|
|
|
|
|
|
|
if (validate && handleRange())
|
|
|
|
window.close();
|
2008-01-14 14:57:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onEditorCancelClick(event) {
|
2008-02-08 18:10:25 +01:00
|
|
|
preventDefault(event);
|
|
|
|
window.close();
|
2008-01-14 14:57:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onRecurrenceLoadHandler() {
|
2008-01-15 00:17:19 +01:00
|
|
|
initializeFormValues();
|
|
|
|
initializeSelectors();
|
|
|
|
initializeWindowButtons();
|
2008-01-15 22:45:48 +01:00
|
|
|
assignCalendar('endDate_date');
|
2008-01-14 14:57:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FastInit.addOnLoad(onRecurrenceLoadHandler);
|