2009-07-19 18:41:42 +02:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2006-10-18 23:53:47 +02:00
|
|
|
var contactSelectorAction = 'calendars-contacts';
|
2006-10-11 20:13:11 +02:00
|
|
|
|
|
|
|
function uixEarlierDate(date1, date2) {
|
2014-04-12 03:37:55 +02:00
|
|
|
// can this be done in a sane way?
|
|
|
|
if (date1 && date2) {
|
|
|
|
if (date1.getYear() < date2.getYear()) return date1;
|
|
|
|
if (date1.getYear() > date2.getYear()) return date2;
|
|
|
|
// same year
|
|
|
|
if (date1.getMonth() < date2.getMonth()) return date1;
|
|
|
|
if (date1.getMonth() > date2.getMonth()) return date2;
|
|
|
|
// same month
|
|
|
|
if (date1.getDate() < date2.getDate()) return date1;
|
|
|
|
if (date1.getDate() > date2.getDate()) return date2;
|
|
|
|
}
|
|
|
|
// same day
|
|
|
|
return null;
|
2006-10-23 16:56:58 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 17:21:48 +02:00
|
|
|
function validateDate(which, label) {
|
2014-04-12 03:37:55 +02:00
|
|
|
var result, dateValue;
|
2006-10-23 16:56:58 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
dateValue = this._getDate(which);
|
|
|
|
if (dateValue == null) {
|
|
|
|
alert(label);
|
|
|
|
result = false;
|
|
|
|
} else
|
|
|
|
result = dateValue;
|
2006-10-23 16:56:58 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
return result;
|
2006-10-11 20:13:11 +02:00
|
|
|
}
|
|
|
|
|
2006-10-23 23:34:56 +02:00
|
|
|
function validateTaskEditor() {
|
2014-04-12 03:37:55 +02:00
|
|
|
var e, startdate, enddate, tmpdate;
|
2006-10-23 16:56:58 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
e = document.getElementById('summary');
|
|
|
|
if (e.value.length == 0
|
|
|
|
&& !confirm(labels.validate_notitle))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
e = document.getElementById('startTime_date');
|
|
|
|
if (!e.disabled) {
|
|
|
|
startdate = validateDate('start', labels.validate_invalid_startdate);
|
|
|
|
if (!startdate)
|
|
|
|
return false;
|
|
|
|
}
|
2006-10-23 16:56:58 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
e = document.getElementById('dueTime_date');
|
|
|
|
if (!e.disabled) {
|
|
|
|
enddate = validateDate('due', labels.validate_invalid_enddate);
|
|
|
|
if (!enddate)
|
|
|
|
return false;
|
2006-10-23 16:56:58 +02:00
|
|
|
}
|
2011-06-13 22:28:10 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
if (startdate && enddate) {
|
|
|
|
tmpdate = uixEarlierDate(startdate, enddate);
|
|
|
|
if (tmpdate == enddate) {
|
|
|
|
alert(labels.validate_endbeforestart);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (tmpdate == null /* means: same date */) {
|
|
|
|
// TODO: check time
|
|
|
|
|
|
|
|
var startHour, startMinute, endHour, endMinute;
|
|
|
|
var matches;
|
2011-06-13 22:28:10 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
matches = document.forms[0]['startTime_time'].value.match(/([0-9]+):([0-9]+)/);
|
2011-06-13 22:28:10 +02:00
|
|
|
if (matches) {
|
2014-04-12 03:37:55 +02:00
|
|
|
startHour = parseInt(matches[1]);
|
|
|
|
startMinute = parseInt(matches[2]);
|
|
|
|
matches = document.forms[0]['dueTime_time'].value.match(/([0-9]+):([0-9]+)/);
|
|
|
|
if (matches) {
|
|
|
|
endHour = parseInt(matches[1]);
|
|
|
|
endMinute = parseInt(matches[2]);
|
|
|
|
|
|
|
|
if (startHour > endHour) {
|
2011-06-13 22:28:10 +02:00
|
|
|
alert(labels.validate_endbeforestart);
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-12 03:37:55 +02:00
|
|
|
else if (startHour == endHour) {
|
|
|
|
if (startMinute > endMinute) {
|
|
|
|
alert(labels.validate_endbeforestart);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert(labels.validate_invalid_enddate);
|
|
|
|
return false;
|
2011-06-13 22:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-04-12 03:37:55 +02:00
|
|
|
alert(labels.validate_invalid_startdate);
|
2011-06-13 22:28:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-10-23 16:56:58 +02:00
|
|
|
}
|
2006-10-11 20:13:11 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
return true;
|
2006-10-19 16:40:24 +02:00
|
|
|
}
|
2006-10-11 20:13:11 +02:00
|
|
|
|
2006-10-19 16:40:24 +02:00
|
|
|
function onTimeControlCheck(checkBox) {
|
2009-08-07 18:01:14 +02:00
|
|
|
if (checkBox) {
|
|
|
|
var inputs = checkBox.parentNode.getElementsByTagName("input");
|
|
|
|
var selects = checkBox.parentNode.getElementsByTagName("select");
|
|
|
|
for (var i = 0; i < inputs.length; i++)
|
|
|
|
if (inputs[i] != checkBox)
|
|
|
|
inputs[i].disabled = !checkBox.checked;
|
|
|
|
for (var i = 0; i < selects.length; i++)
|
|
|
|
if (selects[i] != checkBox)
|
|
|
|
selects[i].disabled = !checkBox.checked;
|
2011-12-22 19:02:59 +01:00
|
|
|
if (checkBox.id == "startDateCB")
|
2009-08-07 18:01:14 +02:00
|
|
|
$("reminderList").disabled = !checkBox.checked;
|
|
|
|
}
|
2006-10-11 20:13:11 +02:00
|
|
|
}
|
2006-10-23 23:34:56 +02:00
|
|
|
|
|
|
|
function saveEvent(sender) {
|
2014-04-12 03:37:55 +02:00
|
|
|
if (validateTaskEditor())
|
|
|
|
document.forms['editform'].submit();
|
2006-10-23 23:34:56 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
return false;
|
2006-10-23 23:34:56 +02:00
|
|
|
}
|
2006-10-27 00:00:54 +02:00
|
|
|
|
|
|
|
function startDayAsShortString() {
|
2014-04-12 03:37:55 +02:00
|
|
|
return dayAsShortDateString($('startTime_date'));
|
2006-10-27 00:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function dueDayAsShortString() {
|
2014-04-12 03:37:55 +02:00
|
|
|
return dayAsShortDateString($('dueTime_date'));
|
2006-10-27 00:00:54 +02:00
|
|
|
}
|
2006-11-07 17:13:03 +01:00
|
|
|
|
|
|
|
this._getDate = function(which) {
|
2014-04-12 03:37:55 +02:00
|
|
|
var date = window.timeWidgets[which]['date'].inputAsDate();
|
|
|
|
var time = window.timeWidgets[which]['time'].value.split(":");
|
|
|
|
date.setHours(time[0]);
|
|
|
|
date.setMinutes(time[1]);
|
2011-06-13 22:28:10 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
if (isNaN(date.getTime()))
|
|
|
|
return null;
|
2012-09-24 17:21:48 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
return date;
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this._getShadowDate = function(which) {
|
2014-04-12 03:37:55 +02:00
|
|
|
var date = window.timeWidgets[which]['date'].getAttribute("shadow-value").asDate();
|
|
|
|
var time = window.timeWidgets[which]['time'].getAttribute("shadow-value").split(":");
|
|
|
|
date.setHours(time[0]);
|
|
|
|
date.setMinutes(time[1]);
|
2008-03-27 22:05:47 +01:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
return date;
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.getStartDate = function() {
|
2014-04-12 03:37:55 +02:00
|
|
|
return this._getDate('start');
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.getDueDate = function() {
|
2014-04-12 03:37:55 +02:00
|
|
|
return this._getDate('due');
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.getShadowStartDate = function() {
|
2014-04-12 03:37:55 +02:00
|
|
|
return this._getShadowDate('start');
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.getShadowDueDate = function() {
|
2014-04-12 03:37:55 +02:00
|
|
|
return this._getShadowDate('due');
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this._setDate = function(which, newDate) {
|
2014-04-12 03:37:55 +02:00
|
|
|
window.timeWidgets[which]['date'].setInputAsDate(newDate);
|
|
|
|
window.timeWidgets[which]['time'].value = newDate.getDisplayHoursString();
|
2012-09-24 17:21:48 +02:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
// Update date picker
|
|
|
|
var dateComponent = jQuery(window.timeWidgets[which]['date']).closest('.date');
|
|
|
|
dateComponent.data('date', window.timeWidgets[which]['date'].value);
|
|
|
|
dateComponent.datepicker('update');
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.setStartDate = function(newStartDate) {
|
2014-04-12 03:37:55 +02:00
|
|
|
this._setDate('start', newStartDate);
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.setDueDate = function(newDueDate) {
|
2014-04-12 03:37:55 +02:00
|
|
|
this._setDate('due', newDueDate);
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.onAdjustTime = function(event) {
|
2014-04-12 03:37:55 +02:00
|
|
|
onAdjustDueTime(event);
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.onAdjustDueTime = function(event) {
|
2014-04-12 03:37:55 +02:00
|
|
|
if (!window.timeWidgets['due']['date'].disabled) {
|
|
|
|
var dateDelta = (window.getStartDate().valueOf()
|
|
|
|
- window.getShadowStartDate().valueOf());
|
|
|
|
var newDueDate = new Date(window.getDueDate().valueOf() + dateDelta);
|
|
|
|
window.setDueDate(newDueDate);
|
|
|
|
}
|
|
|
|
window.timeWidgets['start']['date'].updateShadowValue();
|
|
|
|
window.timeWidgets['start']['time'].updateShadowValue();
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.initTimeWidgets = function (widgets) {
|
2014-04-12 03:37:55 +02:00
|
|
|
this.timeWidgets = widgets;
|
|
|
|
|
|
|
|
jQuery(widgets['start']['date']).closest('.date').datepicker({autoclose: true, weekStart: firstDayOfWeek})
|
|
|
|
.on('changeDate', onAdjustTime);
|
|
|
|
widgets['start']['time'].on("time:change", onAdjustDueTime);
|
|
|
|
widgets['start']['time'].addInterface(SOGoTimePickerInterface);
|
|
|
|
|
|
|
|
jQuery(widgets['due']['date']).closest('.date').datepicker({autoclose: true, weekStart: firstDayOfWeek});
|
|
|
|
widgets['due']['time'].addInterface(SOGoTimePickerInterface);
|
|
|
|
|
|
|
|
jQuery('#statusTime_date').closest('.date').datepicker({autoclose: true, weekStart: firstDayOfWeek});
|
2008-03-27 22:05:47 +01:00
|
|
|
};
|
2014-04-12 03:37:55 +02:00
|
|
|
|
2008-03-27 22:05:47 +01:00
|
|
|
function onStatusListChange(event) {
|
2014-04-12 03:37:55 +02:00
|
|
|
var value = $("statusList").value;
|
|
|
|
var statusTimeDate = $("statusTime_date");
|
|
|
|
var statusPercent = $("statusPercent");
|
2008-03-27 22:05:47 +01:00
|
|
|
|
2014-04-12 03:37:55 +02:00
|
|
|
if (value == "WONoSelectionString") {
|
|
|
|
statusTimeDate.disabled = true;
|
|
|
|
statusPercent.disabled = true;
|
|
|
|
statusPercent.value = "";
|
|
|
|
}
|
|
|
|
else if (value == "0") {
|
|
|
|
statusTimeDate.disabled = true;
|
|
|
|
statusPercent.disabled = false;
|
|
|
|
}
|
|
|
|
else if (value == "1") {
|
|
|
|
statusTimeDate.disabled = true;
|
|
|
|
statusPercent.disabled = false;
|
|
|
|
}
|
|
|
|
else if (value == "2") {
|
|
|
|
statusTimeDate.disabled = false;
|
|
|
|
statusPercent.disabled = false;
|
|
|
|
statusPercent.value = "100";
|
|
|
|
}
|
|
|
|
else if (value == "3") {
|
|
|
|
statusTimeDate.disabled = true;
|
|
|
|
statusPercent.disabled = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
statusTimeDate.disabled = true;
|
|
|
|
}
|
2008-03-27 22:05:47 +01:00
|
|
|
}
|
2007-03-18 16:00:34 +01:00
|
|
|
|
|
|
|
function initializeStatusLine() {
|
2014-04-12 03:37:55 +02:00
|
|
|
var statusList = $("statusList");
|
|
|
|
if (statusList) {
|
|
|
|
statusList.observe("change", onStatusListChange);
|
|
|
|
}
|
2007-03-18 16:00:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTaskEditorLoad() {
|
2009-08-07 18:01:14 +02:00
|
|
|
if (readOnly == false) {
|
|
|
|
var widgets = {'start': {'date': $("startTime_date"),
|
2011-06-13 22:28:10 +02:00
|
|
|
'time': $("startTime_time")},
|
2009-08-07 18:01:14 +02:00
|
|
|
'due': {'date': $("dueTime_date"),
|
2011-06-13 22:28:10 +02:00
|
|
|
'time': $("dueTime_time")}};
|
2009-08-07 18:01:14 +02:00
|
|
|
initTimeWidgets(widgets);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable or disable the reminder list
|
2011-12-22 19:02:59 +01:00
|
|
|
onTimeControlCheck($("startDateCB"));
|
2009-04-21 16:34:22 +02:00
|
|
|
|
2009-08-07 18:01:14 +02:00
|
|
|
initializeStatusLine();
|
2007-03-18 16:00:34 +01:00
|
|
|
}
|
2007-07-10 16:13:44 +02:00
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", onTaskEditorLoad);
|