562 lines
21 KiB
JavaScript
562 lines
21 KiB
JavaScript
var currentAppointment;
|
|
var selectedAppointmentOid, selectedAppointmentSubject, selectedAppointmentNotice, selectedAppointmentStartDate, selectedAppointmentEndDate, selectedAppointmentDate;
|
|
|
|
array2 = [];
|
|
appointments = [];
|
|
|
|
function saveOnlyKalender() {
|
|
if(navigator.onLine) {
|
|
clearLocalStorage(2);
|
|
|
|
localStorage.setItem("Kalenderdaten", currentAppointment);
|
|
|
|
location.reload();
|
|
}
|
|
}
|
|
|
|
function loadAppointments(newtoday) {
|
|
showSanduhr();
|
|
|
|
$.ajax({
|
|
type: "GET",
|
|
url: loadAppointmentsUrl,
|
|
data: { newtoday: newtoday },
|
|
success: function (json) {
|
|
hideSanduhr();
|
|
|
|
var kalenderRec = $.parseJSON(json);
|
|
var appointmentList = $("#AppointmentList");
|
|
var html = "<table>";
|
|
|
|
appointmentList.empty();
|
|
|
|
$.each(kalenderRec, function (index, termin) {
|
|
console.log(termin);
|
|
var description = termin.Description;
|
|
var startD = termin.StartDate;
|
|
var endD = termin.EndDate;
|
|
var date = new Date(startD);
|
|
var dateend = new Date(endD);
|
|
|
|
appointments[termin.SchedulerAppointmentOid] = termin;
|
|
|
|
var startTime = getHoursAndMinutesWithLeadingZeros(date);
|
|
var endTime = getHoursAndMinutesWithLeadingZeros(dateend);
|
|
|
|
var employeeColorStyle = "width: .2em; background-color: #E6E6E6;";
|
|
|
|
if(termin.EmployeeList.length > 0) {
|
|
var color = getSixDigitHexColorCode(termin.EmployeeList[0].Employee.EmployeeColor);
|
|
|
|
$.each(termin.EmployeeList, function(index, emp) {
|
|
if(emp.Employee.Color !== null && emp.Employee.EmployeeColor !== undefined) {
|
|
color = getSixDigitHexColorCode(emp.Employee.EmployeeColor);
|
|
return false;
|
|
}
|
|
});
|
|
|
|
if(color !== null && color !== undefined) {
|
|
employeeColorStyle = "width: .2em; background-color: " + color + ";";
|
|
} else {
|
|
color = getSixDigitHexColorCode(termin.Originator.EmployeeColor);
|
|
if(color !== null && color !== undefined) {
|
|
employeeColorStyle = "width: .2em; background-color: " + color + ";";
|
|
}
|
|
}
|
|
} else {
|
|
var originatorColor = getSixDigitHexColorCode(termin.Originator.EmployeeColor);
|
|
if(originatorColor !== null && originatorColor !== undefined) {
|
|
employeeColorStyle = "width: .2em; background-color: " + originatorColor + ";";
|
|
}
|
|
}
|
|
|
|
var customerResourceColorStyle = "width: .2em; background-color: #E6E6E6;";
|
|
var customerColor = "#3B7799";
|
|
var resourceColor = "#04B4D0";
|
|
|
|
if(termin.CustomerList.length > 0 && termin.ResourceList.length > 0) {
|
|
$.each(termin.ResourceList, function(index, resource) {
|
|
if(resource.Color !== null && resource.Color !== undefined) {
|
|
resourceColor = getSixDigitHexColorCode(resource.Color);
|
|
|
|
return false;
|
|
}
|
|
});
|
|
|
|
customerResourceColorStyle = "width: .2em; background: linear-gradient(" + customerColor + " 50%, " + resourceColor + " 50%);";
|
|
} else if(termin.CustomerList.length > 0 && termin.ResourceList.length === 0) {
|
|
customerResourceColorStyle = "width: .2em; background-color: " + customerColor + ";";
|
|
} else if(termin.CustomerList.length === 0 && termin.ResourceList.length > 0) {
|
|
$.each(termin.ResourceList, function(index, resource) {
|
|
if(resource.Color !== null && resource.Color !== undefined) {
|
|
resourceColor = getSixDigitHexColorCode(resource.Color);
|
|
|
|
return false;
|
|
}
|
|
});
|
|
|
|
customerResourceColorStyle = "width: .2em; background-color: " + resourceColor + ";";
|
|
}
|
|
|
|
|
|
|
|
html +=
|
|
'<tr class="appointment-outer-table-row">' +
|
|
'<td style="' + employeeColorStyle + '"></td>' +
|
|
'<td class="appointment-header-td" onclick="toggleAppointmentDetails(this)">' +
|
|
'<p class="appointment-header-p"><span class="appointment-time-span">' + startTime + ' - ' + endTime + '</span> ' + termin.Subject + '</p>' +
|
|
'</td>' +
|
|
'<td class="appointment-edit-btn-container">' +
|
|
'<input type="button" class="edit-button" onclick="appointmentOnClick(this, ' + termin.SchedulerAppointmentOid + ')" style="' + (termin.SchedulerAppointmentOid === null ? 'display: none;' : '') +'" />' +
|
|
'</td>' +
|
|
'<td class="appointment-edit-btn-container">' +
|
|
'<input type="button" class="appointment-toggle-btn" onclick="toggleAppointmentDetails(this)" />' +
|
|
'</td>' +
|
|
'<td style="' + customerResourceColorStyle + '">' +
|
|
'</td>' +
|
|
'</tr>' +
|
|
'<tr class="collapsible-container">' +
|
|
'<td colspan="5" style="display: none;">' +
|
|
'<div class="kollabierbar">';
|
|
|
|
if(termin.EmployeeList.length > 0) {
|
|
html += '<p><span class="employee_span">M: </span>';
|
|
|
|
$.each(termin.EmployeeList, function(index, employee) {
|
|
html += employee.Employee.LastName + ", " + employee.Employee.FirstName;
|
|
|
|
if(index !== termin.EmployeeList.length - 1) {
|
|
html += "; ";
|
|
}
|
|
});
|
|
|
|
html += "</p>";
|
|
}
|
|
|
|
if(termin.CustomerList.length > 0) {
|
|
html += '<p><span class="customer_span">K: </span>';
|
|
|
|
$.each(termin.CustomerList, function(index, customer) {
|
|
html += customer.LastName + ", " + customer.FirstName;
|
|
|
|
if(index !== termin.CustomerList.length - 1) {
|
|
html += "; ";
|
|
}
|
|
});
|
|
|
|
html += "</p>";
|
|
}
|
|
|
|
if(termin.ResourceList.length > 0) {
|
|
html += '<p><span class="resource_span">R: </span>';
|
|
|
|
$.each(termin.ResourceList, function(index, resource) {
|
|
html += resource.Name;
|
|
|
|
if(index !== termin.ResourceList.length - 1) {
|
|
html += ", ";
|
|
}
|
|
});
|
|
|
|
html += "</p>";
|
|
}
|
|
|
|
if((termin.EmployeeList.length > 0 || termin.CustomerList.length > 0 || termin.ResourceList.length > 0) && typeof description === "string") {
|
|
html += "<hr/>";
|
|
}
|
|
|
|
if (typeof description !== "string") {
|
|
description = "";
|
|
}
|
|
|
|
html += description + "</div></td></tr>";
|
|
});
|
|
|
|
html += "</table>";
|
|
appointmentList.append(html);
|
|
loadBeWoTask(newtoday);
|
|
}
|
|
});
|
|
}
|
|
|
|
function toggleAppointmentDetails(element) {
|
|
var element2toggle = null;
|
|
var toggleBtn = null;
|
|
|
|
if($(element).is("input")) {
|
|
element2toggle = $(element).parent().parent().next("tr").find("td");
|
|
toggleBtn = $(element);
|
|
} else {
|
|
element2toggle = $(element).parent().next("tr").find("td");
|
|
|
|
toggleBtn = $(element).parent().find(".appointment-toggle-btn");
|
|
}
|
|
|
|
var newIcon = "url('";
|
|
newIcon += element2toggle.css("display") === "none" ? toggleIconUContentUrl : toggleIconDContentUrl;
|
|
newIcon += "')";
|
|
|
|
element2toggle.toggle();
|
|
|
|
if(toggleBtn !== null) {
|
|
toggleBtn.css("background-image", newIcon);
|
|
}
|
|
|
|
}
|
|
|
|
function appointmentOnClick(element, appointmentOid) {
|
|
if (appointmentOid === null) {
|
|
return;
|
|
}
|
|
|
|
var selectedAppointment = appointments[appointmentOid];
|
|
|
|
if (selectedAppointment.RecurrenceInfo !== null) {
|
|
return;
|
|
}
|
|
|
|
var saveAppointmentButton = $("#TerminSpeichern");
|
|
|
|
var startDate = new Date(selectedAppointment.StartDate);
|
|
var endDate = new Date(selectedAppointment.EndDate);
|
|
|
|
var startTime = getHoursAndMinutesWithLeadingZeros(startDate);
|
|
var endTime = getHoursAndMinutesWithLeadingZeros(endDate);
|
|
|
|
window.selectedAppointmentOid = selectedAppointment.SchedulerAppointmentOid;
|
|
|
|
$("#AppointmentEditForm").css("display", "block");
|
|
$("#KalenderTable").css("display", "none");
|
|
$("#KalenderNavigation").css("display", "none");
|
|
$("#KalenderTableTask").css("display", "none");
|
|
$("#StartDate").val(getDateStringWithLeadingZeros(startDate));
|
|
$("#EndDate").val(getDateStringWithLeadingZeros(endDate));
|
|
|
|
$("#TerminStartZeit").val(startTime);
|
|
$("#TerminEndZeit").val(endTime);
|
|
$("#TerminBetreff").val(selectedAppointment.Subject);
|
|
$("#TerminNotiz").val(selectedAppointment.Description);
|
|
$("#AppointmentLocation").val(selectedAppointment.Location);
|
|
|
|
$("#TerminSpeichernAbbrechen").val("Schließen");
|
|
saveAppointmentButton.val("Speichern");
|
|
saveAppointmentButton.prop("disabled", true);
|
|
saveAppointmentButton.css("display", "inline");
|
|
|
|
$("#InsertAppointmentButton").css("display", "none");
|
|
|
|
$("html, body").animate({scrollTop: 0}, 0);
|
|
}
|
|
|
|
function updateSelectedAppointment() {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: updateAppointmentUrl,
|
|
data: {
|
|
oid: selectedAppointmentOid,
|
|
betreff: currentAppointment.subject,
|
|
notice: currentAppointment.notice,
|
|
startZeit: currentAppointment.startTime,
|
|
endZeit: currentAppointment.endTime,
|
|
day: currentAppointment.startDate,
|
|
endDate: currentAppointment.endDate,
|
|
pLocation: currentAppointment.location
|
|
}, success: function() {
|
|
var dp = $("#KalenderDatumFormat").val();
|
|
var dateParts = dp.split(".");
|
|
var nextdatum2 = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
|
|
|
|
$("#KalenderDatum").val(toDateStringYearMonthDay(nextdatum2));
|
|
$("#KalenderDatumFormat").val(dp);
|
|
|
|
$("#AppointmentEditForm").css("display", "none");
|
|
$("#KalenderTable").css("display", "block");
|
|
$("#KalenderNavigation").css("display", "block");
|
|
$("#KalenderTableTask").css("display", "block");
|
|
|
|
loadAppointments(dp);
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateAppointmentOnClick() {
|
|
if(checkAppointmentFields()) {
|
|
updateSelectedAppointment();
|
|
}
|
|
}
|
|
|
|
function checkAppointmentFields() {
|
|
var newAppointmentStartDate = $("#StartDate").val();
|
|
var newAppointmentEndDate = $("#EndDate").val();
|
|
var newAppointmentStartTime = $("#TerminStartZeit").val();
|
|
var newAppointmentEndTime = $("#TerminEndZeit").val();
|
|
var newAppointmentSubject = $("#TerminBetreff").val();
|
|
var newAppointmentLocation = $("#AppointmentLocation").val();
|
|
|
|
var errorList = [];
|
|
var shouldShowErrorMessage = false;
|
|
|
|
if (newAppointmentStartDate === "") {
|
|
errorList.push("Startdatum");
|
|
shouldShowErrorMessage = true;
|
|
}
|
|
|
|
if (newAppointmentEndDate === "") {
|
|
errorList.push("Enddatum");
|
|
shouldShowErrorMessage = true;
|
|
}
|
|
|
|
if (newAppointmentStartTime === "") {
|
|
errorList.push("Startzeit");
|
|
shouldShowErrorMessage = true;
|
|
}
|
|
|
|
if (newAppointmentEndTime === "") {
|
|
errorList.push("Endzeit");
|
|
shouldShowErrorMessage = true;
|
|
}
|
|
|
|
if (newAppointmentSubject === "") {
|
|
errorList.push("Betreff");
|
|
shouldShowErrorMessage = true;
|
|
}
|
|
|
|
if (shouldShowErrorMessage === true) {
|
|
var errorMessage = "Bitte füllen Sie folgende" + (errorList.length === 1 ? "s" : "") + " Feld" + (errorList.length > 1 ? "er" : "") + " aus:<br />";
|
|
|
|
errorList.forEach(function(item, index, array) {
|
|
errorMessage += item + "<br/>";
|
|
});
|
|
|
|
writeFatalErrorMessage(errorMessage);
|
|
return false;
|
|
}
|
|
|
|
if (!doValidation($("#StartDate")) || !doValidation($("#EndDate")) || !doTimeValidation($("#TerminStartZeit")) || !doTimeValidation($("#TerminEndZeit"))) {
|
|
toggleErrorPopup("Bitte geben Sie gültige Datums- und/oder Zeitangaben ein");
|
|
return false;
|
|
}
|
|
|
|
currentAppointment = new Appointment(newAppointmentStartDate, newAppointmentStartTime, newAppointmentEndTime, newAppointmentSubject, $("#TerminNotiz").val(), newAppointmentEndDate, newAppointmentLocation);
|
|
|
|
return true;
|
|
}
|
|
|
|
function insertAppointmentOnClick() {
|
|
if(checkAppointmentFields()) {
|
|
insertNewAppointment(currentAppointment.startDate, currentAppointment.startTime, currentAppointment.endTime, currentAppointment.subject, currentAppointment.notice, currentAppointment.endDate, currentAppointment.location);
|
|
}
|
|
}
|
|
|
|
function insertNewAppointmentAfterCrash(pDay, pStartTime, pEndTime, pSubject, pNotice, pEndDate, pLocation) {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: insertAppointmentUrl,
|
|
data: {
|
|
pStartDate: pDay,
|
|
pStartTime: pStartTime,
|
|
pEndTime: pEndTime,
|
|
pSubject: pSubject,
|
|
pNotice: pNotice,
|
|
pEndDate: pEndDate,
|
|
pLocation: pLocation
|
|
}, success: null, error: null
|
|
});
|
|
}
|
|
|
|
function insertNewAppointment(pStartDate, pStartTime, pEndTime, pSubject, pNotice, pEndDate, pLocation) {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: insertAppointmentUrl,
|
|
data: {
|
|
pStartDate: pStartDate,
|
|
pStartTime: pStartTime,
|
|
pEndTime: pEndTime,
|
|
pSubject: pSubject,
|
|
pNotice: pNotice,
|
|
pEndDate: pEndDate,
|
|
pLocation: pLocation
|
|
}, success: function () {
|
|
$("#AppointmentEditForm").css("display", "none");
|
|
$("#KalenderTable").css("display", "block");
|
|
$("#KalenderNavigation").css("display", "block");
|
|
$("#KalenderTableTask").css("display", "block");
|
|
|
|
loadAppointments(pStartDate);
|
|
}, error: function() {
|
|
/*saveOnlyKalender();*/
|
|
}
|
|
});
|
|
}
|
|
|
|
function selectDate() {
|
|
var dp = $("#KalenderDatumFormat").val();
|
|
var dateParts = dp.split(".");
|
|
var nextdatum2 = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
|
|
|
|
$("#KalenderDatum").val(toDateStringYearMonthDay(nextdatum2));
|
|
$("#KalenderDatumFormat").val(dp);
|
|
|
|
loadAppointments(dp);
|
|
}
|
|
|
|
function previousDayButtonClick() {
|
|
var nextdatum = new Date($("#KalenderDatum").val());
|
|
nextdatum.setDate((nextdatum.getDate() - 1));
|
|
|
|
$("#KalenderDatum").val(toDateStringYearMonthDay(nextdatum));
|
|
|
|
var newtoday = getDateStringWithLeadingZeros(nextdatum);
|
|
|
|
$("#KalenderDatumFormat").val(newtoday);
|
|
|
|
loadAppointments(newtoday);
|
|
}
|
|
|
|
function loadBeWoTask(newtoday) {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: loadBewoTasksUrl,
|
|
data: { newtoday: newtoday },
|
|
success: function(json) {
|
|
var kalenderRec = $.parseJSON(json);
|
|
var html = "";
|
|
|
|
$("#KalenderTableTask").empty();
|
|
|
|
var zahl = 0;
|
|
$.each(kalenderRec, function(index, termin) {
|
|
var description = termin.Title;
|
|
var date = new Date(termin.DueDate);
|
|
|
|
if(zahl === 0) {
|
|
html += "<thead><tr><th style='width: 150px; border-bottom: solid 1px #D8D8D8;'>Aufgaben</th><th style='width: 80%; border-bottom: solid 1px #D8D8D8;'></th></tr></thead>";
|
|
}
|
|
|
|
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes().toString() : date.getMinutes.toString();
|
|
var hours = date.getHours() < 10 ? '0' + date.getHours().toString() : date.getHours().toString();
|
|
|
|
var farbe = "2B508B";
|
|
|
|
html +=
|
|
'<tr>' +
|
|
'<td style="width: 150px; border-bottom: solid 1px #D8D8D8;">'+
|
|
hours.fontcolor(farbe)+':' + minutes.fontcolor(farbe) + ' ' +
|
|
'</td>' +
|
|
'<td style="width: 80%; border-bottom: solid 1px #D8D8D8;">' +
|
|
description +
|
|
'</td></tr>';
|
|
|
|
zahl++;
|
|
});
|
|
|
|
$("#KalenderTableTask").append(html);
|
|
}
|
|
});
|
|
}
|
|
|
|
function LoadOnly(i, x) {
|
|
var serviceRecord = localStorage.getItem("Zeitdaten");
|
|
var appointment = localStorage.getItem("Kalenderdaten");
|
|
|
|
if(serviceRecord !== null || appointment !== null) {
|
|
if(serviceRecord !== null && i === 1) {
|
|
if(serviceRecord.startTime !== "" && serviceRecord.endTime !== "" && serviceRecord.duration !== "" && serviceRecord.notice !== "" && serviceRecord.supportConceptIndex !== "" && serviceRecord.date !== "") {
|
|
writeFatalErrorMessage("Es ist ein nicht gespeicherter Eintrag vorhanden. Dieser wird nun an den Server gesendet.");
|
|
|
|
setTimeout(function() {
|
|
saveZeiterfassungAfterCrash(serviceRecord.date, serviceRecord.startTime, serviceRecord.endTime, serviceRecord.duration, serviceRecord.notice, serviceRecord.serviceCategory, serviceRecord.costBearer2SupportConceptOid, serviceRecord.notice2, serviceRecord.notice3, serviceRecord.notice4, serviceRecord.notice5, serviceRecord.endDate);
|
|
clearLocalStorage(1);
|
|
showServiceRecords();
|
|
}, timeOut);
|
|
}
|
|
}
|
|
|
|
if(kalenderdata !== null && x === 2) {
|
|
if (appointment !== null && appointment.isValid()) {
|
|
writeFatalErrorMessage("Es ist ein nicht gespeicherter Kalendereintrag vorhanden. Dieser wird nun an den Server gesendet.", 1);
|
|
|
|
setTimeout(function() {
|
|
insertNewAppointmentAfterCrash(appointment.startDate, appointment.startTime, appointment.endTime, appointment.subject, appointment.notice, appointment.endDate);
|
|
clearLocalStorage(2);
|
|
showServiceRecords();
|
|
}, timeOut);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function nextDayButtonClick() {
|
|
var nextdatum = new Date($("#KalenderDatum").val() + "T00:00:00Z");
|
|
|
|
nextdatum.setDate((nextdatum.getDate() + 1));
|
|
|
|
$("#KalenderDatum").val(toDateStringYearMonthDay(nextdatum));
|
|
|
|
var newtoday = getDateStringWithLeadingZeros(nextdatum);
|
|
|
|
$("#KalenderDatumFormat").val(newtoday);
|
|
|
|
loadAppointments(newtoday);
|
|
}
|
|
|
|
function initAppointmentEditForm() {
|
|
var currTime = new Date();
|
|
|
|
if (currTime.getMinutes() <= 30) {
|
|
var k = 30 - currTime.getMinutes();
|
|
currTime.setMinutes(currTime.getMinutes() + k);
|
|
}
|
|
|
|
if (currTime.getMinutes() > 30) {
|
|
var j = 60 - currTime.getMinutes();
|
|
currTime.setMinutes(currTime.getMinutes() + j);
|
|
}
|
|
|
|
$("#AppointmentEditForm").show();
|
|
$("#KalenderTable").hide();
|
|
$("#KalenderNavigation").hide();
|
|
$("#KalenderTableTask").hide();
|
|
$("#StartDate").val($("#KalenderDatumFormat").val());
|
|
$("#EndDate").val($("#KalenderDatumFormat").val());
|
|
$("#TerminStartZeit").val(getHoursAndMinutesWithLeadingZeros(currTime));
|
|
$("#TerminEndZeit").val("");
|
|
$("#TerminBetreff").val("");
|
|
$("#TerminNotiz").val("");
|
|
$("#TerminBetreffLabel").val("Betreff");
|
|
|
|
$("#StartDate").prop("readonly", false);
|
|
$("#EndDate").prop("readonly", false);
|
|
$("#TerminStartZeit").prop("readonly", false);
|
|
$("#TerminEndZeit").prop("readonly", false);
|
|
$("#TerminBetreff").prop('readonly', false);
|
|
$("#TerminNotiz").prop("readonly", false);
|
|
|
|
$("#TerminSpeichern").val("Speichern");
|
|
$("#TerminSpeichernAbbrechen").val("Abbrechen");
|
|
$("#TerminSpeichern").hide();
|
|
|
|
$("#InsertAppointmentButton").css("display", "inline");
|
|
}
|
|
|
|
function showUsAendern() {
|
|
$("#TerminSpeichern").prop('disabled', false);
|
|
$("#AenderePopupDivSchalter").val("true");
|
|
}
|
|
|
|
function showUsVerwerfen() {
|
|
if ($("#AenderePopupDivSchalter").val() === "true") {
|
|
toggleUpdateAppointmentPopup("Wollen Sie wirklich abbrechen und Ihre Änderungen verwerfen?");
|
|
$("#AenderePopupDivSchalter").val("false");
|
|
} else {
|
|
hideEditForm();
|
|
}
|
|
}
|
|
|
|
function hideEditForm() {
|
|
$("#AppointmentEditForm").hide();
|
|
$("#KalenderTable").show();
|
|
$("#KalenderNavigation").show();
|
|
$("#KalenderTableTask").show();
|
|
$("#StartDate").val("");
|
|
} |