Files
thetool/public/js/pages/Calendar/View.js
2026-02-02 19:38:49 +01:00

3008 lines
138 KiB
JavaScript

var hidesearch = [2, 3, 4, 8];
var columnfilter = [7];
var columnoptions = '<option value=""></option><option value="Offen">Offen</option><option value="Genehmigt">Genehmigt</option><option value="Abgelehnt">Abgelehnt</option>';
var localsorageEvent = null;
const fileTypeClasses = {
'image/png': 'fa-file-png',
'image/jpeg': 'fa-file-jpg',
'application/pdf': 'fa-file-pdf',
'application/zip': 'fa-file-zip',
'application/x-zip-compressed': 'fa-file-zip',
'application/octet-stream': 'fa-file-csv',
'text/csv': 'fa-file-csv',
'text/xml': 'fa-file-xml',
'application/xml': 'fa-file-xml',
'audio/mpeg': 'fa-file-mp3',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'fa-file-doc',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'fa-file-xls',
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'fa-file-ppt',
'application/x-rar-compressed': 'fa-file-archive',
'application/msword': 'fa-file-doc',
'application/vnd.ms-excel': 'fa-file-xls',
'application/vnd.ms-powerpoint': 'fa-file-ppt',
'application/vnd.ms-outlook': 'fa-file-outlook',
'application/vnd.ms-access': 'fa-file-access',
'application/vnd.ms-project': 'fa-file-project',
'application/vnd.ms-visio': 'fa-file-visio',
'application/vnd.ms-publisher': 'fa-file-publisher',
};
let calendar;
let calendarEl = document.getElementById('calendar');
calendarRights = JSON.parse(calendarRights);
/*function reinitializeAttendeesSelect() {
var selectedCalendarId = $('#calendar-users').val();
var selectedOption = $('#calendar-users option:selected');
var hasMicrosoftId = selectedOption.data('has-microsoft-id');
if ($('#calendar-attendees').hasClass('select2-hidden-accessible')) {
$('#calendar-attendees').select2('destroy');
}
if (hasMicrosoftId == '1') {
$('#calendar-attendees').select2({
tags: true,
tokenSeparators: [',', ' '],
dropdownParent: jQuery('#relContainer'),
placeholder: "Teilnehmer auswählen oder eingeben",
templateResult: function(data) {
if (!data.id) return data.text;
var $option = $(data.element);
var hasMs = $option.data('has-microsoft-id');
if (hasMs == '0') {
return $('<span style="color: #dc3545; font-weight: bold;">' + data.text + '</span>');
}
return data.text;
},
templateSelection: function(data) {
if (!data.id) return data.text;
var $option = $(data.element);
var hasMs = $option.data('has-microsoft-id');
if (hasMs == '0') {
return $('<span style="color: #dc3545; font-weight: bold;">' + data.text + '</span>');
}
return data.text;
}
});
} else {
$('#calendar-attendees').select2({
dropdownParent: jQuery('#relContainer'),
placeholder: "Teilnehmer auswählen (Freitext nicht verfügbar)",
closeOnSelect: false,
templateResult: function(data) {
if (!data.id) return data.text;
var $option = $(data.element);
var hasMs = $option.data('has-microsoft-id');
if (hasMs == '0') {
return $('<span style="color: #dc3545; font-weight: bold;">' + data.text + '</span>');
}
return data.text;
},
templateSelection: function(data) {
if (!data.id) return data.text;
var $option = $(data.element);
var hasMs = $option.data('has-microsoft-id');
if (hasMs == '0') {
return $('<span style="color: #dc3545; font-weight: bold;">' + data.text + '</span>');
}
return data.text;
}
});
}
}*/
function reinitializeAttendeesSelect() {
var selectedCalendarId = $('#calendar-users').val();
var selectedOption = $('#calendar-users option:selected');
var hasMicrosoftId = selectedOption.data('has-microsoft-id');
// ÄNDERUNG: Verstecke/Deaktiviere Teilnehmer-Zeile wenn keine Microsoft-ID
if (hasMicrosoftId == '0' || hasMicrosoftId === 0 || !hasMicrosoftId) {
// Verstecke die gesamte Teilnehmer-Zeile
// $('#calendar-attendees').closest('.row').hide();
// // Optional: Leere auch die Auswahl
// $('#calendar-attendees').val(null).trigger('change');
return; // Beende Funktion früh
} else {
// Zeige die Teilnehmer-Zeile wieder an
$('#calendar-attendees').closest('.row').show();
}
// Zerstöre bestehende Select2 Instanz
if ($('#calendar-attendees').hasClass('select2-hidden-accessible')) {
$('#calendar-attendees').select2('destroy');
}
// ÄNDERUNG: Initialisiere mit tags (Freitext erlaubt)
$('#calendar-attendees').select2({
tags: true,
tokenSeparators: [',', ' '],
dropdownParent: jQuery('#relContainer'),
placeholder: "Teilnehmer auswählen oder eingeben",
templateResult: function(data) {
if (!data.id) return data.text;
var $option = $(data.element);
var hasMs = $option.data('has-microsoft-id');
if (hasMs == '0') {
return $('<span style="">' + data.text + '</span>');
}
return data.text;
},
templateSelection: function(data) {
if (!data.id) return data.text;
var $option = $(data.element);
var hasMs = $option.data('has-microsoft-id');
if (hasMs == '0') {
return $('<span style="">' + data.text + '</span>');
}
return data.text;
}
});
}
function formatFileSize(bytes) {
if (bytes >= 1024 * 1024) {
const megabytes = bytes / (1024 * 1024);
return megabytes.toFixed(2) + ' MB';
}
else if (bytes >= 1024) {
const kilobytes = bytes / 1024;
return kilobytes.toFixed(2) + ' KB';
}
else {
return Math.round(bytes) + ' Bytes';
}
}
function getOffset(unixTimestamp) {
const date = new Date(unixTimestamp); // Convert to milliseconds
const isDST = date.getTimezoneOffset() < Math.max(
new Date(date.getFullYear(), 0, 1).getTimezoneOffset(),
new Date(date.getFullYear(), 6, 1).getTimezoneOffset()
);
return isDST ? 7200 : 3600;
}
document.addEventListener('DOMContentLoaded', function () {
let checkbox = $(".form-check-input");
let visibleCalendars = [];
let mycalendar_id = $('#calendar-id').data('calendarid');
visibleCalendars.push(0);
checkbox.each(function () {
if ($(this).prop('checked')) {
visibleCalendars.push($(this).data('calendar_id'));
}
});
$.post(requestUrl, {visibleCalendars: visibleCalendars, visibleCancellation: 0}, function (data) {
}, 'json').done(function (json) {
if (json.success == true) {
let userevents = [];
let otherevents = [];
let resources = [];
let category = "";
let rights = false;
let movable = false;
let resourceCounter = 0;
let rrule = null;
let duration = null;
let rruleflag = false;
let allDAy;
let cursorclass = "";
$.each($('.calendar-check'), function (index, value) {
if ($(this).prop('checked')) {
rights = true;
resources.push({
id: $(this).data('calendar_id'),
title: $.trim($(this).closest('div').find('label').text()),
order: resourceCounter
});
resourceCounter++;
}
});
$.each(json.data, function (index, value) {
if (!value.timerecording.timerecording) {
allDAy = false;
rrule = null;
duration = null;
rruleflag = false;
category = value.ccategory.ccategory;
cursorclass = "";
if (value.calendar_id.calendar_id in calendarRights) {
if (calendarRights[value.calendar_id.calendar_id] == 'all') {
rights = true;
} else {
rights = false;
}
if (value.privateflag.privateflag == '1' && mycalendar_id != value.calendar_id.calendar_id) {
rights = false;
}
if (value.isorganizer.isorganizer == '1' && rights) {
movable = true;
} else if (rights) {
movable = false;
cursorclass = "cursor-alias";
} else {
movable = false;
}
if (value.allDay.allDay == "1") {
allDAy = true;
}
if (value.rrule.rrule) {
$.each(value.rrule_events.rrule_events, function (index, rrule_event) {
rruleflag = true;
let busy;
if (rrule_event.showAs == 'busy') {
busy = "1";
} else if (rrule_event.showAs == 'tentative') {
busy = '2';
} else if (rrule_event.showAs == 'free') {
busy = '0';
}
let event = {
id: value.id.id,
start: rrule_event.start,
end: rrule_event.end,
title: rrule_event.subject,
description: value.description.description,
location: value.location.location,
allDay: allDAy,
attachment: value.attachment.attachment,
attachments: value.attachments.attachments,
calendar_id: value.calendar_id,
event_type: value.event_type.event_type,
classNames: ['cal-class-group-' + value.calendar_id.calendar_id, 'cal-class-id-' + value.id.id, cursorclass],
textColor: value.txtColor.txtColor,
backgroundColor: value.bgColor.bgColor,
privateflag: value.privateflag.privateflag,
editable: rights,
rruleflag: rruleflag,
dates: rrule,
duration: duration,
droppable: movable,
startEditable: movable,
durationEditable: movable,
resizableFromStart: movable,
resourceId: value.calendar_id.calendar_id,
calendar_name: value.calendar_name.calendar_name,
clickable: rights,
mtime: value.mtime.mtime,
mname: value.mname.mname,
ctime: value.ctime.ctime,
cname: value.cname.cname,
busy: busy
};
userevents.push(event);
});
} else {
let event = {
id: value.id.id,
start: value.cstart.cstart,
end: value.cend.cend,
title: category,
description: value.description.description,
location: value.location.location,
allDay: allDAy,
attachment: value.attachment.attachment,
attachments: value.attachments.attachments,
calendar_id: value.calendar_id,
event_type: value.event_type.event_type,
classNames: ['cal-class-group-' + value.calendar_id.calendar_id, 'cal-class-id-' + value.id.id, cursorclass],
textColor: value.txtColor.txtColor,
backgroundColor: value.bgColor.bgColor,
privateflag: value.privateflag.privateflag,
editable: rights,
rruleflag: rruleflag,
dates: rrule,
duration: duration,
droppable: movable,
startEditable: movable,
durationEditable: movable,
resizableFromStart: movable,
resourceId: value.calendar_id.calendar_id,
calendar_name: value.calendar_name.calendar_name,
clickable: rights,
mtime: value.mtime.mtime,
mname: value.mname.mname,
ctime: value.ctime.ctime,
cname: value.cname.cname,
busy: value.busy.busy
};
userevents.push(event);
}
if (value.rrule.rrule) {
}
} else {
otherevents.push({
id: value.id.id,
start: value.cstart.cstart,
end: value.cend.cend,
title: category,
description: category,
color: 'red',
editable: false,
rruleflag: rruleflag,
rrule: rrule,
calendar_id: value.calendar_id,
event_type: value.event_type.event_type,
classNames: ['cal-class-group-' + value.calendar_id.calendar_id, 'cal-class-id-' + value.id.id],
attachment: value.attachment.attachment,
attachments: value.attachments.attachments,
resourceId: value.calendar_id.calendar_id,
calendar_name: value.calendar_name.calendar_name,
clickable: rights,
mtime: value.mtime.mtime,
mname: value.mname.mname,
ctime: value.ctime.ctime,
cname: value.cname.cname,
busy: value.busy.busy
});
}
} else {
let event = {
id: value.id.id,
start: value.cstart.cstart,
end: value.cend.cend,
title: value.category.category,
description: value.description.description,
calendar_id: value.calendar_id,
textColor: value.txtColor.txtColor,
backgroundColor: value.bgColor.bgColor,
resourceId: value.calendar_id.calendar_id,
calendar_name: value.calendar_name.calendar_name,
mtime: value.mtime.mtime,
mname: value.mname.mname,
ctime: value.ctime.ctime,
cname: value.cname.cname,
editable: false,
};
userevents.push(event);
}
});
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const eventSources = [];
eventSources.push(userevents);
eventSources.push(otherevents);
if (visibleCalendars.includes(997)) {
eventSources.push(holiDays);
}
if (visibleCalendars.includes(998)) {
eventSources.push(birthdays);
}
calendar = new FullCalendar.Calendar(calendarEl, {
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
timeZone: 'UTC',
locale: 'de',
height: 'auto',
resourceAreaWidth: '220px',
themeSystem: 'bootstrap4',
snapDuration: '00:15:00',
selectable: true,
weekNumbers: true,
headerToolbar: {
left: "prev,today,next",
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,resourceTimelineDay,listMonth'
},
views: {
timeGridDay: {
titleFormat: {
weekday: 'long',
year: 'numeric',
month: 'short',
day: 'numeric'
}
},
resourceTimelineDay: {
titleFormat: {
weekday: 'long',
year: 'numeric',
month: 'short',
day: 'numeric'
}
}
},
buttonText: {
resourceTimelineDay: 'Planung'
},
select: function (info) {
let resourceId = "";
if (info.resource) {
resourceId = info.resource.id;
}
let allDay = info.allDay;
let cestDate = new Date(info.startStr);
let cestOffset = 0; // 2 Stunden in Minuten
let utcTime = cestDate.getTime() - cestOffset * 60 * 1000;
let utcDate = new Date(utcTime);
let year = utcDate.getUTCFullYear();
let month = String(utcDate.getUTCMonth() + 1).padStart(2, '0');
let day = String(utcDate.getUTCDate()).padStart(2, '0');
let hours = String(utcDate.getUTCHours()).padStart(2, '0');
let minutes = String(utcDate.getUTCMinutes()).padStart(2, '0');
let seconds = String(utcDate.getUTCSeconds()).padStart(2, '0');
let StartformattedDate = year + "-" + month + "-" + day;
let StarteformattedTime = hours + ":" + minutes;
let EndformattedDate;
let EndformattedTime;
if (!allDay) {
cestDate = new Date(info.endStr);
cestOffset = 0; // 2 Stunden in Minuten
utcTime = cestDate.getTime() - cestOffset * 60 * 1000;
utcDate = new Date(utcTime);
year = utcDate.getUTCFullYear();
month = String(utcDate.getUTCMonth() + 1).padStart(2, '0');
day = String(utcDate.getUTCDate()).padStart(2, '0');
hours = String(utcDate.getUTCHours()).padStart(2, '0');
minutes = String(utcDate.getUTCMinutes()).padStart(2, '0');
seconds = String(utcDate.getUTCSeconds()).padStart(2, '0');
EndformattedDate = year + "-" + month + "-" + day;
EndformattedTime = hours + ":" + minutes;
} else {
cestDate = new Date(info.endStr);
cestOffset = 120; // 2 Stunden in Minuten
utcTime = cestDate.getTime() - cestOffset * 60 * 1000;
utcDate = new Date(utcTime);
year = utcDate.getUTCFullYear();
month = String(utcDate.getUTCMonth() + 1).padStart(2, '0');
day = String(utcDate.getUTCDate()).padStart(2, '0');
hours = String(utcDate.getUTCHours()).padStart(2, '0');
minutes = String(utcDate.getUTCMinutes()).padStart(2, '0');
seconds = String(utcDate.getUTCSeconds()).padStart(2, '0');
EndformattedDate = year + "-" + month + "-" + day;
EndformattedTime = '23' + ":" + '59';
}
$('#EventModal').modal('show');
if (resourceId) {
$('#calendar-users').val(resourceId).trigger('change');
$('.calendar-users-all').show();
}
$('#start-date').val(StartformattedDate);
$('#start-time').val(StarteformattedTime);
$('#end-date').val(EndformattedDate);
$('#end-time').val(EndformattedTime);
if (allDay) {
$('#allday').prop('checked', true);
$('#allday').change();
$('#end-time').val('');
$('#end-date').val(EndformattedDate);
$('#start-time').val('');
}
}, eventClick: function (info, element) {
let isOrganizer;
$.getJSON(requestEventUrl, {
id: info.event.id
}, function (data) {
}).done(function (data) {
if (data.data.description.description) {
tinymce.activeEditor.setContent(data.data.description.description);
}
if (data.data.attachment.attachment) {
let docs = "";
$.each(data.data.attachments.attachments, function (index, value) {
docs += `<div data-docid="` + value.id + `" class="doc-main-div"><div class="d-inline-block doc-icon-div"><i class="fa-duotone fa-solid ` + value.icon + `"></i></div><div class="d-inline-block doc-content-div"><a href="` + requestEventAttachmentUrl + `&id=` + value.id + `" target="_blank" >` + value.name + `</a></div><span class="float-right"><i title="` + value.name + ` entfernen" class="fas fa-trash fa-del-attachment ml-2"></i></span><span class="float-right">` + formatFileSize(value.size) + `</span></div>`;
});
$('.attachment-div').append(docs);
}
if (data.data.reminder.reminder) {
$('#reminder').val(data.data.reminder.reminder);
} else {
$('#reminder').val('NULL');
}
if (data.data.privateflag.privateflag == 1) {
$('.privacy-click').removeClass('fa-unlock');
$('.privacy-click').removeClass('fa-lock');
$('.privacy-click').addClass('fa-lock');
}
$('#type').val(data.data.type.type);
$('#busy').val(data.data.busy.busy);
isOrganizer = data.data.isorganizer.isorganizer;
if (data.data.type.type == "1") {
$('.customer-div').hide();
$('.ticket-div').hide();
} else if (data.data.type.type == "2" || data.data.type.type == "3" || data.data.type.type == "4" || data.data.type.type == "6") {
$('.ticket-div').hide();
$('.customer-div').show();
if (data.data.customer.customer) {
$('#customer').html('<option>' + data.data.customer.customer + '</option>');
} else {
$('#customer').html('<option></option>');
}
if (data.data.customer_info_reminder.customer_info_reminder) {
if (data.data.customer_info_reminder.customer_info_reminder == 1) {
$('#customer-info-reminder-check').prop('checked', true);
} else {
$('#customer-info-reminder-check').prop('checked', false);
}
}
$('#customer').select2({
placeholder: "Kunden Suche",
minimumInputLength: 3,
dropdownParent: jQuery('#relContainer2'),
// dropdownParent: $('#EventModal'),
language: "de",
ajax: {
url: requestAddressUrl,
dataType: 'json',
delay: 250,
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
});
if (data.data.customer_info.customer_info) {
const obj = JSON.parse(data.data.customer_info.customer_info);
$('#customer-info-text').val(obj.customer_info_text);
$('#customer-info-type').val(obj.customer_info_type);
$('#customer-info-type-text').val(obj.customer_info_type_text);
}
if (data.data.customer_info_send.customer_info_send) {
const obj = JSON.parse(data.data.customer_info_send.customer_info_send);
$('#customer-info-check-info').html('<i class="fa-sharp-duotone fa-solid fa-circle-info customer-info-point"></i>');
const unixTime = obj.sendtime;
const date = new Date(unixTime * 1000);
const germanDateTime = date.toLocaleString('de-DE', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
let typeText;
if (obj.customer_info_type == 1) {
typeText = 'E-Mail';
} else if (obj.customer_info_type == 2) {
typeText = 'SMS';
}
let customer_info_text = "";
if (obj.customer_info_text) {
customer_info_text = obj.customer_info_text.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
}
let title = `<div class="text-center font-weight-500">Letzte gesendete Info (` + typeText + `):</div>
<div class="text-left">` + customer_info_text + `</div>
<div class="text-left"><span class="font-weight-500">gesendet an:</span> ` + obj.customer_info_type_text + `</div>
<div class="text-left"><span class="font-weight-500">gesendet von:</span> ` + obj.sendby + `</div>
<div class="text-left"><span class="font-weight-500">gesendet am:</span> ` + germanDateTime + `</div>
`;
let tooltip = new Tooltip($('.customer-info-point'), {
title: title,
placement: 'right',
trigger: 'hover',
container: 'body',
html: true
});
}
} else if (data.data.type.type == "7") {
$('.ticket-div').hide();
$('.customer-div').show();
if (data.data.customer.customer) {
$('#customer').html('<option>' + data.data.customer.customer + '</option>');
} else {
$('#customer').html('<option></option>');
}
if (data.data.customer_info_reminder.customer_info_reminder) {
if (data.data.customer_info_reminder.customer_info_reminder == 1) {
$('#customer-info-reminder-check').prop('checked', true);
} else {
$('#customer-info-reminder-check').prop('checked', false);
}
}
$('#customer').select2({
placeholder: "Kunden Suche",
minimumInputLength: 3,
dropdownParent: jQuery('#relContainer2'),
// dropdownParent: $('#EventModal'),
language: "de",
ajax: {
url: requestAddressSbidiUrl,
dataType: 'json',
delay: 250,
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
});
if (data.data.customer_info.customer_info) {
const obj = JSON.parse(data.data.customer_info.customer_info);
$('#customer-info-text').val(obj.customer_info_text);
$('#customer-info-type').val(obj.customer_info_type);
$('#customer-info-type-text').val(obj.customer_info_type_text);
}
if (data.data.customer_info_send.customer_info_send) {
const obj = JSON.parse(data.data.customer_info_send.customer_info_send);
$('#customer-info-check-info').html('<i class="fa-sharp-duotone fa-solid fa-circle-info customer-info-point"></i>');
const unixTime = obj.sendtime;
const date = new Date(unixTime * 1000);
const germanDateTime = date.toLocaleString('de-DE', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
let typeText;
if (obj.customer_info_type == 1) {
typeText = 'E-Mail';
} else if (obj.customer_info_type == 2) {
typeText = 'SMS';
}
let customer_info_text = "";
if (obj.customer_info_text) {
customer_info_text = obj.customer_info_text.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
}
let title = `<div class="text-center font-weight-500">Letzte gesendete Info (` + typeText + `):</div>
<div class="text-left">` + customer_info_text + `</div>
<div class="text-left"><span class="font-weight-500">gesendet an:</span> ` + obj.customer_info_type_text + `</div>
<div class="text-left"><span class="font-weight-500">gesendet von:</span> ` + obj.sendby + `</div>
<div class="text-left"><span class="font-weight-500">gesendet am:</span> ` + germanDateTime + `</div>
`;
let tooltip = new Tooltip($('.customer-info-point'), {
title: title,
placement: 'right',
trigger: 'hover',
container: 'body',
html: true
});
}
} else if (data.data.type.type == "5") {
$('.ticket-div').show();
$('.customer-div').hide();
if (data.data.customer.customer) {
$('#customer').html('<option>' + data.data.customer.customer + '</option>');
} else {
$('#customer').html('<option></option>');
}
$('#ticket').select2({
placeholder: "Ticket",
minimumInputLength: 3,
dropdownParent: jQuery('#relContainer3'),
// dropdownParent: $('#EventModal'),
language: "de",
ajax: {
url: requestTicketUrl,
dataType: 'json',
delay: 250,
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
})
}
if (isOrganizer == "1") {
$('.event-organizer-div').hide();
$('.show-update').show();
$('.show-attendee').hide();
if (data.data.type.type == 2 || data.data.type.type == 3 || data.data.type.type == 4 || data.data.type.type == 7) {
$('#cancel-event').show();
} else {
$('#cancel-event').hide();
}
} else {
const organizer = JSON.parse(data.data.organizer.organizer);
$('.event-organizer-div').show();
$('.event-organizer').text(organizer.name);
$('.accepted-status').removeClass('fa-circle-check');
$('.accepted-status').removeClass('fa-circle-info');
let accepted = data.data.accepted.accepted;
if (accepted) {
const accept = JSON.parse(accepted);
if (accept.time) {
const datetime = new Date(accept.time * 1000);
const germanDateTime = datetime.toLocaleString('de-DE');
$('.accepted-status').prop('title', accept.user + ' (' + germanDateTime + ')');
} else {
$('.accepted-status').prop('title', '');
}
$('.accepted-status').addClass('fa-circle-check');
$('.event-accepted').text('Akzeptiert');
} else {
$('.accepted-status').addClass('fa-circle-info');
$('.accepted-status').prop('title', 'Termin wurde noch nicht bestätigt');
$('.event-accepted').text('Offen');
}
$('.show-update').hide();
$('.show-attendee').show();
$('#cancel-event').hide();
$('.show-attendee').data('id', info.event.id);
}
if (data.data.attendees.attendees) {
let attendees = JSON.parse(data.data.attendees.attendees);
$.each(attendees, function (index, value) {
if (!Number.isInteger(value)) {
let valueExists = $("#calendar-attendees option").filter(function () {
return $(this).val() === value;
}).length > 0;
if (!valueExists) {
$("#calendar-attendees").append(new Option(value, value, true, true))
}
}
});
$('#calendar-attendees').val(attendees).trigger('change');
}
if (info.event.extendedProps.rruleflag == true) {
$('#delete-event').hide();
$('#cancel-event').hide();
$('#update-event').hide();
$('.show-attendee').hide();
$('#recurringCheck').prop('checked', true);
$('#recurringCheck').change();
if (data.data.recurrence) {
$('#rrule-frequency').val(data.data.recurrence.recurrence.rrule_frequency);
$('#rrule-frequency').trigger('change');
$('#rrule-interval').val(data.data.recurrence.recurrence.rrule_interval);
$('#rrule-byweekday').val(data.data.recurrence.recurrence.rrule_byweekday);
$('#rrule-until').val(data.data.recurrence.recurrence.rrule_until);
$('#monthly-type').val(data.data.recurrence.recurrence.monthly_type);
$('#monthly-type').trigger('change');
$('#rrule-bymonthday').val(data.data.recurrence.recurrence.rrule_bymonthday);
}
}
if (data.data.canceld.canceld == 1) {
$('#delete-event').hide();
$('#cancel-event').hide();
$('#update-event').hide();
$('.show-attendee').hide();
}
});
if (info.event.extendedProps.clickable) {
let cestDate = new Date(info.event.startStr);
let cestOffset = 0; // 2 Stunden in Minuten
let utcTime = cestDate.getTime() - cestOffset * 60 * 1000;
let utcDate = new Date(utcTime);
let year = utcDate.getUTCFullYear();
let month = String(utcDate.getUTCMonth() + 1).padStart(2, '0');
let day = String(utcDate.getUTCDate()).padStart(2, '0');
let hours = String(utcDate.getUTCHours()).padStart(2, '0');
let minutes = String(utcDate.getUTCMinutes()).padStart(2, '0');
let seconds = String(utcDate.getUTCSeconds()).padStart(2, '0');
let StartformattedDate = year + "-" + month + "-" + day;
let StarteformattedTime = hours + ":" + minutes;
let EndformattedDate;
let EndformattedTime;
if (info.event.endStr) {
cestDate = new Date(info.event.endStr);
cestOffset = 0;
// 2 Stunden in Minuten
utcTime = cestDate.getTime() - cestOffset * 60 * 1000;
if (info.event.allDay) {
utcTime = utcTime - 60;
}
utcDate = new Date(utcTime);
year = utcDate.getUTCFullYear();
month = String(utcDate.getUTCMonth() + 1).padStart(2, '0');
day = String(utcDate.getUTCDate()).padStart(2, '0');
hours = String(utcDate.getUTCHours()).padStart(2, '0');
minutes = String(utcDate.getUTCMinutes()).padStart(2, '0');
seconds = String(utcDate.getUTCSeconds()).padStart(2, '0');
EndformattedDate = year + "-" + month + "-" + day;
EndformattedTime = hours + ":" + minutes;
} else {
EndformattedDate = StartformattedDate;
EndformattedTime = StarteformattedTime;
}
$('#EventModal').modal('show');
$('#start-date').val(StartformattedDate);
$('#start-time').val(StarteformattedTime);
$('#end-date').val(EndformattedDate);
$('#end-time').val(EndformattedTime);
$('#EventModal').modal('show');
if (info.event.allDay) {
$('#allday').prop('checked', true)
$('#allday').change();
$('#end-time').val('');
$('#end-date').val(EndformattedDate);
$('#start-time').val('');
} else {
$('#end-date').val(EndformattedDate);
$('#allday').prop('checked', false);
$('#end-time').val(EndformattedTime);
$('#start-time').val(StarteformattedTime);
}
$('#name').val(info.event.title);
$('#location').val(info.event.extendedProps.location);
// $('#description').val(info.event.extendedProps.description);
$('#delete-event').data('id', info.event.id);
$('#copy-event').data('id', info.event.id);
$('#update-event').data('id', info.event.id);
$('#cancel-event').data('id', info.event.id);
$('#cancelled-event').data('id', info.event.id);
$('#cancelled-abort').data('id', info.event.id);
$('#EventModalLabel').data('id', info.event.id);
$('#EventModalLabel span').text('Termin bearbeiten');
$('#EventModalLabel .fa-calendar-symbol').removeClass('fa-calendar-circle-plus');
$('#EventModalLabel .fa-calendar-symbol').removeClass('fa-calendar-circle-exclamation');
$('#EventModalLabel .fa-calendar-symbol').addClass('fa-calendar-lines-pen');
$('#add-event').hide();
// $('#calendar-users').select2('destroy');
// $('#calendar-users').select2();
$('#calendar-users').val(info.event.extendedProps.calendar_id.calendar_id).trigger('change');
$('#calendar-users').select2("enable", false)
}
},
eventDidMount: function (info) {
let eventstart = new Date(info.event.startStr);
let eventend = new Date(info.event.endStr);
let title;
if (!info.event.allDay) {
eventstart = String(eventstart.getUTCHours()).padStart(2, '0') + ':' + String(eventstart.getUTCMinutes()).padStart(2, '0');
eventend = String(eventend.getUTCHours()).padStart(2, '0') + ':' + String(eventend.getUTCMinutes()).padStart(2, '0');
title = '<div class="tooltip-description text-center">von ' + eventstart + ' bis ' + eventend + '</div>';
} else {
eventstart = String(eventstart.getUTCDate()).padStart(2, '0') + '.' + String(eventstart.getUTCMonth() + 1).padStart(2, '0') + '.' + eventstart.getUTCFullYear();
eventend = String(eventend.getUTCDate()).padStart(2, '0') + '.' + String(eventend.getUTCMonth() + 1).padStart(2, '0') + '.' + eventend.getUTCFullYear();
if (eventend == "NaN.NaN.NaN") {
eventend = eventstart;
}
title = '<div class="tooltip-description text-center">Ganztägig von ' + eventstart + ' bis ' + eventend + ' </div>';
}
title += info.event.title;
if (info.event.extendedProps['description']) {
title += '<div class="tooltip-description text-left">' + info.event.extendedProps['description'] + '</div>';
}
if (info.event.extendedProps['location']) {
title += '<div class="text-left tooltip-location">@ ' + info.event.extendedProps['location'] + '</div>';
}
if (info.event.extendedProps['attachment'] == 1) {
const obj = JSON.parse(info.event.extendedProps['attachments']);
let docs = "";
$.each(obj, function (index, value) {
let filename;
if (fileTypeClasses[value.contentType]) {
filename = fileTypeClasses[value.contentType];
} else {
filename = 'fa-file';
}
docs += `<div class="doc-main-div font-13"><div class="d-inline-block doc-icon-div"><i class="fa-duotone fa-solid ` + filename + ` font-15"></i></div><div class="d-inline-block doc-content-tooltip-div"><a href="` + requestEventAttachmentUrl + `&id=` + value.id + `" target="_blank" >` + value.name + `</a></div><span class="float-right d-inline-block ml-1 font-12">` + formatFileSize(value.size) + `</span></div>`;
});
title += '<div class="text-left tooltip-attachments font-13">' + docs + '</div>';
}
if (info.event.extendedProps['ctime']) {
title += '<div class="text-left font-13"><span class="font-weight-500">Kalender: </span>' + info.event.extendedProps['calendar_name'] + '</div>';
title += '<div class="text-left font-13"><span class="font-weight-500">erstellt am </span>' + info.event.extendedProps['ctime'] + '</div>';
title += '<div class="text-left font-13"><span class="font-weight-500">erstellt von </span>' + info.event.extendedProps['cname'] + '</div>';
title += '<div class="text-left font-13"><span class="font-weight-500">geändert am </span> ' + info.event.extendedProps['mtime'] + '</div>';
title += '<div class="text-left font-13"><span class="font-weight-500">geändert von </span> ' + info.event.extendedProps['mname'] + '</div>';
}
if ($('.fc-button-active').hasClass('fc-timeGridWeek-button') || $('.fc-button-active').hasClass('fc-timeGridDay-button')) {
if (info.event.extendedProps['event_type'] == '2') {
// info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><i class=\"fa-light fa-user-helmet-safety\"></i></div>");
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><img style='height: 13px;vertical-align: top;' src='/img/xinon-logo.png'></div>");
}
if (info.event.extendedProps['event_type'] == '3') {
// info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><i class=\"fa-light fa-user-helmet-safety\"></i></div>");
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><img style='height: 13px;vertical-align: top;' src='/img/estmk_logo.png'></div>");
}
if (info.event.extendedProps['event_type'] == '7') {
// info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><i class=\"fa-light fa-user-helmet-safety\"></i></div>");
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><img style='height: 15px;vertical-align: top;margin-top:-1px' src='/img/sbidi-logo.png'></div>");
}
if (info.event.extendedProps['event_type'] == '4') {
// info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><i class=\"fa-light fa-user-helmet-safety\"></i></div>");
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><img style='height: 13px;vertical-align: top;' src='/img/snop-logo.png'></div>");
}
if (info.event.extendedProps['event_type'] == '6') {
// info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><i class=\"fa-light fa-user-helmet-safety\"></i></div>");
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><i class=\"fa-duotone fa-solid fa-phone-volume fa-calendar-call\"></i></div>");
}
if (info.event.extendedProps['event_type'] == '5') {
// info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><i class=\"fa-light fa-user-helmet-safety\"></i></div>");
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-type\"><i class=\"fa-duotone fa-solid fa-triangle-exclamation fa-calendar-alert\"></i></div>");
}
if (info.event.extendedProps['privateflag'] == 1) {
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-private\"><i class=\"fa-regular fa-event-lock fa-lock\"></i></div>");
}
if (info.event.extendedProps['attachment'] && info.event.extendedProps['privateflag'] == 1) {
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-attachment-mr\"><i class=\"fa-light fa-paperclip-vertical\"></i></div>");
} else if (info.event.extendedProps['attachment']) {
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-attachment\"><i class=\"fa-light fa-paperclip-vertical\"></i></div>");
}
if (info.event.extendedProps['rruleflag']) {
info.el.querySelector(".fc-event-title").insertAdjacentHTML("afterend", "<div class=\"fc-event-recurrence\"><i class=\"fa-regular fa-arrows-rotate\"></i></div>");
}
}
let tooltip = new Tooltip(info.el, {
title: title,
placement: 'right',
delay: {hide: 50},
trigger: 'hover',
container: 'body',
html: true,
});
let tooltips = info.event.extendedProps['tooltips'] || [];
tooltips.push(tooltip);
info.event.setExtendedProp('tooltips', tooltips);
},
eventWillUnmount: function (info) {
for (let tooltip of info.event.extendedProps['tooltips']) {
tooltip.dispose();
}
},
eventResize: function (info) {
info.event.remove();
let start = info.event.start.getTime();
// const offsetstart = getOffset(start);
const offsetstart = 0;
start = (start / 1000 + offsetstart) * 1000;
let end = info.event.end.getTime();
// const offsetend = getOffset(end);
const offsetend = 0;
end = (end / 1000 + offsetend) * 1000;
let id = info.event.id;
$.post(requestUpdateUrl, {
start: start,
end: end,
id: id
}, function (data) {
}).done(function (data) {
let tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'right',
trigger: 'hover',
container: 'body'
});
let tooltips = info.event.extendedProps['tooltips'] || [];
tooltips.push(tooltip);
info.event.setExtendedProp('tooltips', tooltips);
});
},
eventDrop: function (info) {
info.event.remove();
let start = info.event.start.getTime();
// const offsetstart = getOffset(start);
const offsetstart = 0;
start = (start / 1000 + offsetstart) * 1000;
let end = info.event.end.getTime();
// const offsetend = getOffset(end);
const offsetend = 0;
end = (end / 1000 + offsetend) * 1000;
let id = info.event.id;
$.post(requestUpdateUrl, {
start: start,
end: end,
id: id
}, function (data) {
}).done(function (data) {
});
// });
},
eventClassNames: function (info) {
let result = '';
if (typeof info.event.extendedProps.calendar_id === 'undefined') {
return '';
}
let checkbox = $(".form-check-input");
checkbox.each(function () {
if ($(this).prop('checked')) {
if (Number(info.event.extendedProps.calendar_id.calendar_id) === $(this).data('calendar_id')) {
}
} else {
if (Number(info.event.extendedProps.calendar_id.calendar_id) === $(this).data('calendar_id')) {
result = "";
}
}
});
if (info.event.extendedProps.busy == '0') {
result += ' event-free';
} else if (info.event.extendedProps.busy == '1') {
result += ' event-busy';
} else if (info.event.extendedProps.busy == '2') {
result += ' event-tentative';
}
return result;
},
datesSet: function (dateInfo) {
$('.event-search-result').removeClass('event-search-result');
$('#jumpevent').val(null).trigger('change');
},
editable: true,
droppable: true,
fixedWeekCount: true,
// height: 300,
initialView: 'timeGridWeek',
timeZone: 'UTC',
hiddenDays: [],
navLinks: 'true',
events: [],
height: 800,
eventSources: eventSources,
resourceOrder: 'order',
resources: resources,
});
calendar.render();
} else {
$('#calendar').closest('.row').html('<div class="col-12"><h3 class="alert alert-danger text-center">' + json.errormessage + '</h3></div>');
}
}
)
;
});
if (typeof (EventSource) !== 'undefined') {
console.info('Starting connection...');
let source = new EventSourcePolyfill(requestUpdateEventsUrl, {
// Specifying custom request headers
headers: {
'X-API-KEY': 'wcdqEHXcXl5f1sZTEHKPTutqpFBbRf55'
},
heartbeatTimeout: 6000000
});
source.addEventListener('open', function (e) {
console.info('Connection was opened.');
}, false);
let jsondata;
source.addEventListener('error', function (e) {
let txt;
switch (e.target.readyState) {
// if reconnecting
case EventSource.CONNECTING:
txt = 'Reconnecting...';
break;
// if error was fatal
case EventSource.CLOSED:
txt = 'Connection failed. Will not retry.';
break;
}
console.error('Connection error: ' + txt);
}, false);
source.addEventListener('message', function (e) {
// document.getElementById('result').innerHTML += e.data + '<br>';
let checkbox = $(".form-check-input");
let calendarFilter = $('.btn-light-search');
let visibleCalendars = [];
let visibleCalendarTypes = [];
let visibleCancellation = 0;
let mycalendar_id = $('#calendar-id').data('calendarid');
visibleCalendars.push(0);
checkbox.each(function () {
if ($(this).prop('checked')) {
visibleCalendars.push(parseInt($(this).data('calendar_id')));
}
});
calendarFilter.each(function () {
if (!$(this).hasClass('top-search-filter')) {
if ($(this).data('ctype')) {
visibleCalendarTypes.push(parseInt($(this).data('ctype')));
}
if ($(this).data('eventcancelled')) {
visibleCancellation = $(this).data('eventcancelled');
}
}
});
jsondata = JSON.parse(e.data);
jsondata.forEach(function (event) {
if (!visibleCalendars.includes(parseInt(event.calendar_id))) {
return;
}
if (visibleCalendarTypes.length > 0 && !visibleCalendarTypes.includes(parseInt(event.event_type)) && event.change_type != '3') {
return;
}
if (visibleCancellation == 0 && event.change_type != '3' && event.canceld == 1) {
let cevent = calendar.getEventById(event.cal_events_id);
if (cevent) {
cevent.remove();
}
return;
}
let cevent = calendar.getEventById(event.cal_events_id);
let rights = false;
let movable = false;
let rrule = null;
let duration = null;
let rruleflag = false;
let cursorclass = '';
if (event.rrule) {
$('.calendar-check').eq(0).trigger('change');
rrule = event.rrule;
duration = event.duration;
rruleflag = true;
return;
}
if (event.calendar_id in calendarRights) {
if (calendarRights[event.calendar_id] == 'all') {
rights = true;
} else {
rights = false;
}
if (event.isorganizer == '1' && rights) {
movable = true;
} else if (rights) {
cursorclass = "cursor-alias"
movable = false;
} else {
movable = false;
}
if (event.privateflag == '1' && mycalendar_id != event.calendar_id_check.calendar_id) {
rights = false;
movable = false;
}
}
if (event.change_type == '2' && cevent) {
if (cevent) {
if (event.calendar_id == event.calendar_id) {
// console.log(jsondata);
cevent.remove();
calendar.addEvent({
id: event.cal_events_id,
title: event.name,
start: event.start_time,
end: event.end_time,
description: event.description,
calendar_id: event.calendar_id_check,
textColor: event.txtColor,
backgroundColor: event.bgColor,
location: event.location,
event_type: event.event_type,
classNames: ['cal-class-group-' + event.calendar_id, 'cal-class-id-' + event.cal_events_id, cursorclass],
attachment: event.attachment,
attachments: event.attachments,
editable: movable,
privateflag: event.privateflag,
rruleflag: rruleflag,
rrule: rrule,
duration: duration,
resourceId: event.calendar_id,
calendar_name: event.calendar_name,
clickable: rights,
mtime: event.mtime,
mname: event.mname,
ctime: event.ctime,
cname: event.cname,
busy: event.busy
});
} else {
cevent.remove();
calendar.addEvent({
id: event.cal_events_id,
title: event.name,
start: event.start_time,
end: event.end_time,
description: event.description,
calendar_id: event.calendar_id_check,
color: '#ab0000',
editable: false,
location: event.location,
event_type: event.event_type,
classNames: ['cal-class-group-' + event.calendar_id, 'cal-class-id-' + event.cal_events_id, cursorclass],
attachment: event.attachment,
attachments: event.attachments,
calendar_id: event.calendar_id_check,
resourceId: event.calendar_id,
privateflag: event.privateflag,
calendar_name: event.calendar_name,
clickable: rights,
mtime: event.mtime,
mname: event.mname,
ctime: event.ctime,
cname: event.cname,
busy: event.busy
});
}
calendar.render();
}
} else if ((event.change_type == '1' || !cevent) && event.change_type != '3') {
if (event.calendar_id == event.calendar_id && event.name) {
let info = calendar.addEvent({
id: event.cal_events_id,
title: event.name,
start: event.start_time,
end: event.end_time,
description: event.description,
calendar_id: event.calendar_id_check,
textColor: event.txtColor,
backgroundColor: event.bgColor,
location: event.location,
privateflag: event.privateflag,
event_type: event.event_type,
classNames: ['cal-class-group-' + event.calendar_id, 'cal-class-id-' + event.cal_events_id, cursorclass],
attachment: event.attachment,
attachments: event.attachments,
editable: movable,
resourceId: event.calendar_id,
calendar_name: event.calendar_name,
clickable: rights,
mtime: event.mtime,
mname: event.mname,
ctime: event.ctime,
cname: event.cname,
busy: event.busy
});
} else if (event.name) {
let info = calendar.addEvent({
id: event.cal_events_id,
title: event.name,
start: event.start_time,
end: event.end_time,
description: event.description,
calendar_id: event.calendar_id_check,
color: '#ab0000',
editable: false,
location: event.location,
privateflag: event.privateflag,
event_type: event.event_type,
classNames: ['cal-class-group-' + event.calendar_id, 'cal-class-id-' + event.cal_events_id, cursorclass],
attachment: event.attachment,
attachments: event.attachments,
calendar_id: event.calendar_id_check,
resourceId: event.calendar_id,
calendar_name: event.calendar_name,
clickable: rights,
mtime: event.mtime,
mname: event.mname,
ctime: event.ctime,
cname: event.cname,
busy: event.busy
});
}
calendar.render();
} else if (event.change_type == '3') {
let cevent = calendar.getEventById(event.cal_events_id);
if (cevent) {
cevent.remove();
}
}
});
}, false);
} else {
alert('Your browser does not support Server-sent events! Please upgrade it!');
console.error('Connection aborted');
}
$(document).ready(function () {
let eventdialog = $('#EventModal').html();
$('body').on('click', '.fa-window-maximize', function () {
$('.card').addClass('card-fullscreen');
$('#card-size').removeClass('fa-window-maximize').addClass('fa-window-restore');
calendar.render();
});
$(document).on('show.bs.dropdown', '.dropdown', function () {
let previewMenue = '';
$.getJSON(requestgetpreviewtUrl, {
event_type: $('#type').val()
}, function (data) {
}).done(function (data) {
;
let counter = 1;
$.each(data.data, function (index, item) {
previewMenue += '<li><a class="dropdown-item text-template" data-text="' + item.data.text + '">' + item.data.name + '</a></li>';
counter++;
});
$('.dropdown-menu').html(previewMenue);
});
});
$('body').on('click', '.fa-window-restore', function () {
$('.card').removeClass('card-fullscreen');
$('#card-size').removeClass('fa-window-restore').addClass('fa-window-maximize');
calendar.render();
});
$(document).keyup(function (e) {
if (e.key === "Escape") { // escape key maps to keycode `27`
if ($('.card').hasClass('card-fullscreen')) {
$('.card').removeClass('card-fullscreen');
$('#card-size').removeClass('fa-window-restore').addClass('fa-window-maximize');
}
$('.cal-group-name-input').each(function (index, value) {
$(this).closest('div').find('.dropdown-group-div').show();
$(this).closest('div').find('.move-group-div').show();
$(this).closest('div').find('.group-checkbox-div').show();
$(this).closest('.cal-group-name').text($(this).data('oldname'));
});
}
});
$('#myModal').on('shown.bs.modal', function () {
$(document).off('focusin.modal');
});
// Sobald der Link-Dialog geschlossen wird, fügen wir die "modal-open"-Klasse wieder hinzu, falls noch ein Modal offen ist.
$('#EventModal').on('hidden.bs.modal', function (event) {
tinymce.activeEditor.setContent('');
localStorage.removeItem('Calendar_create');
});
$('#EventModal').on('show.bs.modal', function (event) {
$(document).off('focusin.modal');
$('.hide-cancelled').show();
$('.show-cancelled').hide();
$('#delete-old-entry').val('');
$('#delete-old-entry').prop('checked', false);
$('.delete-old-div').hide();
$('#name-col').removeClass('col-9').addClass('col-6');
$('.attachment-div').empty();
$('#reminder').val('NULL');
$('#type').val('1');
$('.privacy-click').removeClass('fa-lock');
$('.privacy-click').removeClass('fa-unlock');
$('.privacy-click').addClass('fa-unlock');
$('#customer-info-check-info').empty();
$('#customer-info-type').val('1');
$('#customer').val('');
$('#ticket').val('');
$('.event-organizer-div').hide();
$('#calendar-attendees').val('').trigger('change');
$('.customer-div').hide();
$('.ticket-div').hide();
$('.calendar-users-all').hide();
$('#EventModalLabel span').text('Termin erstellen');
$('#EventModalLabel .fa-calendar-symbol').addClass('fa-calendar-circle-plus');
$('#EventModalLabel .fa-calendar-symbol').removeClass('fa-calendar-lines-pen');
$('#EventModalLabel .fa-calendar-symbol').removeClass('fa-calendar-circle-exclamation');
$('#EventModalLabel').data('id', '');
$('.show-attendee').data('id', '');
$('.eventmodal-input').val('');
$('.eventmodal-input').prop('disabled', false);
$('.eventmodal-checkbox').prop('checked', false);
$('#EventModal .is-require').each(function (index, value) {
$(this).removeClass('required');
});
$('#recurring-settings').hide();
$('#weekly-options').hide();
$('#monthly-type').val('BYMONTHDAY');
$('#rrule-frequency').val('');
$('#rrule-count').val('');
$('#rrule-until').val('');
$('#rrule-byweekday').val('');
$('#rrule-bymonthday').val('1');
$('#monthly-options').hide();
// $('.select2-multiple').select2();
$('#calendar-users').prop("disabled", false);
$("#calendar-users option").each(function () {
if ($(this).data('mainuser') == "1") {
$(this).prop('selected', true).trigger('change');
}
});
$('#type').val('1');
$('#busy').val('1');
$('#files-input').val('');
$('#start-time').addClass('is-require');
$('#end-time').addClass('is-require');
$('.show-update').hide();
$('.show-attendee').hide();
$('#add-event').show();
$('#attachments').data('newkey', Math.floor(Math.random() * 10000));
if (localsorageEvent) {
$('#type').val(localsorageEvent.type).trigger('change');
$('#location').val(localsorageEvent.location);
$('#name').val(localsorageEvent.subject);
const datetime = localsorageEvent.cstart.split(' ');
$('#start-date').val(datetime[0]);
$('#start-time').val(datetime[1]);
const datetimeend = localsorageEvent.cend.split(' ');
$('#end-date').val(datetimeend[0]);
$('#end-time').val(datetimeend[1]);
if (localsorageEvent.customer_phone)
{
$('#customer-info-type').val('2').trigger('change');
$('#customer-info-type-text').val(localsorageEvent.customer_phone);
} else if (localsorageEvent.customer_email)
{
$('#customer-info-type').val('1').trigger('change');
}
}
});
tinymce.init({
//font_formats: "Arial=arial,sans-serif;",
selector: '#description',
dialog_container: '#EventModal',
language: 'de',
branding: false,
height: 250,
menubar: false,
forced_root_block_attrs: {
style: 'margin:0;'
},
skin: "tinymce-5",
plugins: ' code link autolink lists table',
paste_block_drop: true,
paste_as_text: true,
paste_data_images: false,
promotion: false,
toolbar1: 'undo redo | styles | bold italic underline strikethrough | fontfamily fontsize forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent | table | link unlink',
content_css: "/assets/css/tinymce.css",
content_style: "body { font-family: 'Calibri', sans-serif; }",
font_family_formats: "Calibri=Calibri, sans-serif;Arial=arial,sans-serif; Courier New=courier new,courier,monospace; Georgia=georgia,palatino,serif; Helvetica=helvetica,sans-serif; Lucida Sans=lucida sans unicode,sans-serif; Tahoma=tahoma,arial,helvetica,sans-serif; Times New Roman=times new roman,times,serif",
setup: function (editor) {
editor.on('init', function () {
if (localsorageEvent) {
this.setContent(localsorageEvent.description || '');
}
});
}
});
$('body').on('click', '#add-event', function () {
let valid = true;
$('#EventModal .is-require').each(function (index, value) {
if ($(this).val() == "") {
valid = false;
$(this).addClass('required');
} else {
$(this).removeClass('required');
}
});
let attachments = [];
$('.doc-main-div').each(function (index, value) {
if ($(this).data('docid')) {
attachments.push($(this).data('docid'));
}
});
let start = $('#start-date').val() + ' ' + $('#start-time').val();
let end = $('#end-date').val() + ' ' + $('#end-time').val();
let title = $('#name').val();
let location = $('#location').val();
let description = tinymce.activeEditor.getContent();
let newkey = $('#attachments').data('newkey');
let allday = 0;
let reminder = $('#reminder').val();
let type = $('#type').val();
let busy = $('#busy').val();
let customer;
let customer_info_check = 0;
let customer_info_text;
let customer_info_type;
let customer_info_type_text;
let customer_info_reminder_check = 0;
let private = $('.privacy-click');
let privateflag = 0;
if (private.hasClass('fa-lock')) {
privateflag = 1;
}
let users = [];
if ($('#allday').is(':checked')) {
allday = 1;
}
if (allday != 1) {
const isostart = start.replace(' ', 'T');
const isoend = end.replace(' ', 'T');
const startdate = new Date(isostart);
const enddate = new Date(isoend);
if (startdate >= enddate) {
$('#end-time').addClass('required');
valid = false;
}
}
if (!valid) {
return;
}
let delete_old_entry = '';
if ($('#delete-old-entry').is(':checked')) {
delete_old_entry = $('#delete-old-entry').val()
}
if ($('#customer-info-check').is(':checked')) {
customer_info_check = 1;
}
if (type == '2' || type == '3' || type == '4' || type == '7') {
customer_info_text = $('#customer-info-text').val();
customer_info_type = $('#customer-info-type').val();
customer_info_type_text = $('#customer-info-type-text').val();
customer = $('#customer option:selected').text();
if ($('#customer-info-reminder-check').is(':checked')) {
customer_info_reminder_check = 1;
}
}
$('#calendar-users > option:selected').each(function () {
users.push($(this).val());
});
if ($('#recurringCheck').is(':checked') && $('#rrule-frequency').val() !== '') {
var rruleData = {};
rruleData.rrule_frequency = $('#rrule-frequency').val();
if (rruleData.rrule_frequency === 'WEEKLY') {
// Mehrere Wochentage als Array
rruleData['rrule-byweekday'] = $('#rrule-byweekday').val();
} else if (rruleData.rrule_frequency === 'MONTHLY') {
rruleData.monthly_type = $('#monthly-type').val();
if (rruleData.monthly_type === 'BYMONTHDAY') {
rruleData.rrule_bymonthday = $('#rrule-bymonthday').val();
} else if (rruleData.monthly_type === 'BYSETPOS') {
rruleData.rrule_setpos = $('#rrule-setpos').val();
rruleData.rrule_bynweekday = $('#rrule-bynweekday').val();
}
}
// Optionale Felder
rruleData.rrule_count = $('#rrule-count').val();
rruleData.rrule_until = $('#rrule-until').val();
}
$.post(requestInsertUrl, {
start: start,
end: end,
allday: allday,
title: title,
location: location,
reminder: reminder,
type: type,
busy: busy,
description: description,
attachments: attachments,
users: users,
privateflag: privateflag,
rruleData: rruleData,
attendees: $('#calendar-attendees').val(),
customer: customer,
customer_info_check: customer_info_check,
customer_info_text: customer_info_text,
customer_info_type: customer_info_type,
customer_info_type_text: customer_info_type_text,
customer_info_reminder_check: customer_info_reminder_check,
delete_old_entry: delete_old_entry,
newkey: newkey
}, function (data) {
}).done(function (data) {
localStorage.removeItem('Calendar_create');
});
$('#EventModal').modal('hide');
});
$('body').on('click', '#cancelled-event', function () {
let id = $(this).data('id');
let title = $('#name').val();
let users = [];
let customer_info_text;
let customer_info_type;
let customer_info_type_text;
let customer_info_check = 0;
$('#calendar-users > option:selected').each(function () {
users.push($(this).val());
});
customer_info_text = $('#customer-info-text').val();
customer_info_type = $('#customer-info-type').val();
customer_info_type_text = $('#customer-info-type-text').val();
if ($('#customer-info-check-cancelled').is(':checked')) {
customer_info_check = 1;
}
if (confirm('Termin wirklich absagen?')) {
$.post(requestCancelUrl, {
id: id,
users: users,
customer_info_text: customer_info_text,
customer_info_type: customer_info_type,
customer_info_type_text: customer_info_type_text,
customer_info_check: customer_info_check,
title: title
}, function (data) {
}).done(function (data) {
});
$('#EventModal').modal('hide');
}
});
$('body').on('click', '#cancel-event', function () {
let id = $(this).data('id');
let users = [];
$('.hide-cancelled').hide();
$('.show-cancelled').show();
$('#name').val("Absage: " + $('#name').val());
$('#name-col').removeClass('col-6').addClass('col-9');
//<i class="fa-duotone fa-solid fa-calendar-xmark"></i>
//<i class="fa-duotone fa-solid fa-calendar-circle-exclamation"></i>
$('#EventModalLabel .fa-calendar-symbol').removeClass('fa-calendar-circle-plus');
$('#EventModalLabel .fa-calendar-symbol').removeClass('fa-calendar-lines-pen');
$('#EventModalLabel .fa-calendar-symbol').addClass('fa-calendar-circle-exclamation');
$('#EventModalLabel span').text('Termin absagen');
// $('#calendar-users > option:selected').each(function () {
// users.push($(this).val());
// });
//
//
// if (confirm('Termin wirklich absagen?')) {
// $.post(requestCancelUrl, {
// id: id,
// users: users
// }, function (data) {
//
// }).done(function (data) {
// });
// $('#EventModal').modal('hide');
// }
});
$('body').on('click', '#cancelled-abort', function () {
const id = $(this).data('id');
const eventEl = document.querySelector('.cal-class-id-' + id);
if (!eventEl) return console.warn('Event-Element nicht gefunden:', id);
$('#EventModal').one('hidden.bs.modal', function () {
eventEl.dispatchEvent(new MouseEvent('click', {
bubbles: true,
cancelable: true
}));
});
$('#EventModal').modal('hide');
});
$('body').on('click', '#update-event', function () {
let valid = true;
$('#EventModal .is-require').each(function (index, value) {
if ($(this).val() == "") {
valid = false;
$(this).addClass('required');
} else {
$(this).removeClass('required');
}
});
let attachments = [];
$('.doc-main-div').each(function (index, value) {
if ($(this).data('docid')) {
attachments.push($(this).data('docid'));
}
});
let start = $('#start-date').val() + ' ' + $('#start-time').val();
let end = $('#end-date').val() + ' ' + $('#end-time').val();
let title = $('#name').val();
let location = $('#location').val();
let description = tinymce.activeEditor.getContent();
if (description == "") {
description = '&nbsp;';
}
let newkey = $('#attachments').data('newkey');
let allday = 0;
let reminder = $('#reminder').val();
let type = $('#type').val();
let busy = $('#busy').val();
let customer;
let customer_info_check = 0;
let customer_info_text;
let customer_info_type;
let customer_info_type_text;
let customer_info_reminder_check = 0;
let private = $('.privacy-click');
let privateflag = 0;
if (private.hasClass('fa-lock')) {
privateflag = 1;
}
let users = [];
if ($('#allday').is(':checked')) {
allday = 1;
}
if (allday != 1) {
const isostart = start.replace(' ', 'T');
const isoend = end.replace(' ', 'T');
const startdate = new Date(isostart);
const enddate = new Date(isoend);
if (startdate >= enddate) {
$('#end-time').addClass('required');
valid = false;
}
}
if (!valid) {
return;
}
if ($('#customer-info-check').is(':checked')) {
customer_info_check = 1;
}
if (type == '2' || type == '3' || type == '4' || type == '7') {
customer_info_text = $('#customer-info-text').val();
customer_info_type = $('#customer-info-type').val();
customer_info_type_text = $('#customer-info-type-text').val();
customer = $('#customer option:selected').text();
if ($('#customer-info-reminder-check').is(':checked')) {
customer_info_reminder_check = 1;
}
}
let id = $(this).data('id');
const cevent = calendar.getEventById(id);
cevent.remove();
$('#calendar-users > option:selected').each(function () {
users.push($(this).val());
});
$.post(requestUpdateUrl, {
id: id,
start: start,
end: end,
allday: allday,
title: title,
location: location,
reminder: reminder,
type: type,
busy: busy,
description: description,
attachments: attachments,
users: users,
privateflag: privateflag,
attendees: $('#calendar-attendees').val(),
customer: customer,
customer_info_check: customer_info_check,
customer_info_text: customer_info_text,
customer_info_type: customer_info_type,
customer_info_type_text: customer_info_type_text,
customer_info_reminder_check: customer_info_reminder_check,
newkey: newkey
}, function (data) {
}).done(function (data) {
});
$('#EventModal').modal('hide');
});
$("body").on("click", ".show-attendee", function (e) {
let eventAction = $(this).data("event-action");
let eventactionGerman;
let id = $(this).data('id');
let users = [];
$('#calendar-users > option:selected').each(function () {
users.push($(this).val());
});
if (eventAction === "accept") {
eventactionGerman = "zusagen";
} else if (eventAction === "decline") {
eventactionGerman = "absagen";
}
if (confirm('Termin ' + eventactionGerman + '?')) {
$.post(requestUpdateStateUrl, {
id: id,
eventAction: eventAction,
users: users
}, function (data) {
}).done(function (data) {
});
$('#EventModal').modal('hide');
}
});
$('body').on('click', '#delete-event', function () {
let id = $(this).data('id');
let users = [];
$('#calendar-users > option:selected').each(function () {
users.push($(this).val());
});
if (confirm('Eintrag wirklich löschen?')) {
$.post(requestDeleteUrl, {
id: id,
users: users
}, function (data) {
}).done(function (data) {
});
$('#EventModal').modal('hide');
}
});
$('body').on('click', '#copy-event', function () {
let id = $(this).data('id');
$('#EventModalLabel .fa-calendar-symbol').addClass('fa-calendar-circle-plus');
$('#EventModalLabel .fa-calendar-symbol').removeClass('fa-calendar-lines-pen');
$('#EventModalLabel .fa-calendar-symbol').removeClass('fa-calendar-circle-exclamation');
$('#EventModalLabel span').text('Termin erstellen');
$('#calendar-users').prop("disabled", false);
if ($('#update-event').is(':visible')) {
$('#delete-old-entry').val(id);
$('.delete-old-div').show();
} else {
var $input = $('#name');
var text = $input.val();
var pos = text.indexOf(':');
if (pos !== -1) {
var neuerText = text.substring(pos + 1).trim();
$input.val(neuerText);
}
$('#busy').val('1');
}
$('.hide-cancelled').show();
$('.show-cancelled').hide();
$('.show-update').hide();
$('.show-attendee').hide();
$('.event-organizer-div').hide();
if ($('#type').val() != 5) {
$('.ticket-div').hide();
}
});
$('body').on('change', '#allday', function () {
if ($(this).is(':checked')) {
$('#start-time').prop('disabled', true);
$('#end-time').prop('disabled', true);
$('#start-time').removeClass('is-require');
$('#end-time').removeClass('is-require');
} else {
$('#start-time').prop('disabled', false);
$('#end-time').prop('disabled', false);
if ($('#start-time').val() == "") {
$('#start-time').val('08:00');
}
if ($('#end-time').val() == "") {
$('#end-time').val('10:00');
}
}
});
$('body').on('change', '.color-input,.color-text-input', function (event, init = 0) {
let bgcolors = [];
let txtcolors = [];
let calendar_id = [];
let thisis = $(this);
$.each($('.color-input'), function (index, value) {
if ($(this).data('calendar_id')) {
bgcolors.push($(this).closest('div').find('.color-input').val());
txtcolors.push($(this).closest('div').find('.color-text-input').val());
calendar_id.push($(this).data('calendar_id'));
} else {
}
});
let id = $('#calendar-id').data('id');
let groups = getGroups();
$.post(requestUpdateColorUrl, {
id: id,
bgcolors: bgcolors,
txtcolors: txtcolors,
calendar_id: calendar_id,
groups: groups
}, function (data) {
}).done(function (data) {
if (init === 0) {
refreshCalendarEvents();
}
})
});
$('body').on('click', '.btn-light-search', function (event, init = 0) {
if ($(this).hasClass('top-search-filter')) {
$(this).removeClass('top-search-filter');
} else {
$(this).addClass('top-search-filter');
}
refreshCalendarEvents();
});
$('body').on('change', '.calendar-check', function (event, init = 0) {
if ($(this).prop('checked')) {
refreshCalendarEvents()
} else {
refreshCalendarEvents()
}
let resources = calendar.getResources();
$.each(resources, function (index, value) {
value.remove();
});
let resourceCounter = 0;
$.each($('.calendar-check'), function (index, value) {
if ($(this).prop('checked')) {
rights = true;
calendar.addResource({
id: $(this).data('calendar_id'),
title: $.trim($(this).closest('div').find('label').text()),
order: resourceCounter
});
resourceCounter++;
}
});
$(".color-input").eq(0).trigger("change", 1);
checkGroupCheckboxes();
}
)
;
function uploadajax(ttl, cl) {
let fileList = $('#files-input').prop("files");
let form_data = "";
form_data = new FormData();
form_data.append("upload_file", fileList[cl]);
form_data.append("event_id", $('#EventModalLabel').data('id'));
form_data.append("newkey", $('#attachments').data('newkey'));
let request = $.ajax({
url: requestEventAttachmentUploadUrl,
cache: false,
contentType: false,
processData: false,
async: true,
data: form_data,
type: 'POST',
xhr: function () {
let xhr = $.ajaxSettings.xhr();
if (xhr.upload) {
xhr.upload.addEventListener('progress', function (event) {
let percent = 0;
if (event.lengthComputable) {
percent = Math.ceil(event.loaded / event.total * 100);
}
$('.pb-' + fileList[cl].size).css('width', percent + '%').attr('aria-valuenow', percent);
}, false);
}
return xhr;
},
success: function (res, status) {
if (status == 'success') {
percent = 0;
$('.pb-' + fileList[cl].size).closest('.progress').remove();
if (cl < ttl) {
uploadajax(ttl, cl + 1);
} else {
}
}
},
fail: function (res) {
alert('Failed');
}
})
}
$('body').on('change', '#files-input', function () {
let fileList = $('#files-input').prop("files");
$('#uploadsts').html('');
let i;
for (i = 0; i < fileList.length; i++) {
let newkey = $('#attachments').data('newkey');
const filetype = fileList[i].type;
const classContentType = fileTypeClasses[filetype] || 'fa-file';
// $('#uploadsts').append('<p class="upload-page">' + fileList[i].name + '<span class="loading-prep" id="prog' + i + '"></span></p>');
$('.attachment-div').append(`<div class="doc-main-div" data-name="` + fileList[i].name + `" data-newkey="` + newkey + `"><div class="d-inline-block doc-icon-div"><i class="fa-duotone fa-solid ` + classContentType + `"></i></div>
<div class="d-inline-block doc-content-div" style="margin-left: -3px;"><a href="` + requestEventAttachmentTmpUrl + `&id=` + newkey + `&name=` + fileList[i].name + `" target="_blank">` + fileList[i].name + `</a></div>
<span class="float-right"><i title="` + fileList[i].name + `" class="fas fa-trash fa-del-attachment ml-2"></i></span><span class="float-right">` + formatFileSize(fileList[i].size) + `</span></div>
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated pb-` + fileList[i].size + `" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
`);
if (i == fileList.length - 1) {
uploadajax(fileList.length - 1, 0);
}
}
});
$('body').on('click', '.fa-del-attachment', function () {
if ($(this).closest('.doc-main-div').data('newkey') && $(this).closest('.doc-main-div').data('name')) {
let newkey = $(this).closest('.doc-main-div').data('newkey');
let name = $(this).closest('.doc-main-div').data('name');
$.post(requestEventAttachmentTmpDeleteUrl, {
newkey: newkey,
name: name
}, function (data) {
}).done(function (data) {
});
}
$(this).closest('.doc-main-div').remove();
});
$('body').on('click', '#customer', function () {
})
$('body').on('change', '#type', function () {
$('#customer').val('');
if ($(this).val() == "1") {
$('.customer-div').hide();
$('.ticket-div').hide();
} else if ($(this).val() == "2") {
$('.customer-div').show();
$('.ticket-div').hide();
$('#customer').select2({
placeholder: "Kunden Suche",
minimumInputLength: 3,
// dropdownParent: $('#EventModal'),
dropdownParent: jQuery('#relContainer2'),
language: "de",
ajax: {
url: requestAddressUrl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
term: params.term,
xinon: 1,
};
},
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
});
} else if ($(this).val() == "3") {
$('.customer-div').show();
$('.ticket-div').hide();
$('#customer').select2({
placeholder: "Kunden Suche",
minimumInputLength: 3,
// dropdownParent: $('#EventModal'),
dropdownParent: jQuery('#relContainer2'),
language: "de",
ajax: {
url: requestAddressUrl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
term: params.term,
xinon: 0,
};
},
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
});
} else if ($(this).val() == "4") {
$('.customer-div').show();
$('.ticket-div').hide();
$('#customer').select2({
placeholder: "Kunden Suche",
minimumInputLength: 3,
// dropdownParent: $('#EventModal'),
dropdownParent: jQuery('#relContainer2'),
language: "de",
ajax: {
url: requestAddressUrl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
term: params.term,
xinon: 0,
};
},
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
});
} else if ($(this).val() == "7") {
$('.customer-div').show();
$('.ticket-div').hide();
$('#customer').select2({
placeholder: "Kunden Suche",
minimumInputLength: 3,
// dropdownParent: $('#EventModal'),
dropdownParent: jQuery('#relContainer2'),
language: "de",
ajax: {
url: requestAddressSbidiUrl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
term: params.term,
xinon: 0,
};
},
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
});
} else if ($(this).val() == "6") {
$('.customer-div').show();
$('.ticket-div').hide();
$('#customer').select2({
placeholder: "Kunden Suche",
minimumInputLength: 3,
// dropdownParent: $('#EventModal'),
dropdownParent: jQuery('#relContainer2'),
language: "de",
ajax: {
url: requestAddressUrl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
term: params.term,
xinon: 1,
};
},
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
});
} else if ($(this).val() == "5") {
$('.customer-div').hide();
$('.ticket-div').show();
$('#ticket').select2({
placeholder: "Ticket",
minimumInputLength: 3,
dropdownParent: jQuery('#relContainer3'),
// dropdownParent: $('#EventModal'),
language: "de",
ajax: {
url: requestTicketUrl,
dataType: 'json',
delay: 250,
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
})
}
});
$('body').on('change', '#jumpevent', function () {
$('.event-search-result').removeClass('event-search-result');
if ($(this).val() == "" || $(this).val() == null) {
return;
}
const valueArray = $(this).val().split(";");
let id = valueArray[0];
let date = valueArray[1];
calendar.gotoDate(date)
$('.cal-class-id-' + id).addClass('event-search-result');
})
$('#jumpevent').select2({
placeholder: "Termin Suche",
minimumInputLength: 3,
language: "de",
ajax: {
url: requestEventSearchURL,
data: function (params) {
let checkbox = $(".calendar-check");
let calendarFilter = $('.btn-light-search');
let visibleCalendars = [];
let visibleCalendarTypes = [];
let visibleCancellation = 0;
visibleCalendars.push(0);
checkbox.each(function () {
if ($(this).prop('checked')) {
visibleCalendars.push($(this).data('calendar_id'));
}
});
calendarFilter.each(function () {
if (!$(this).hasClass('top-search-filter')) {
visibleCalendarTypes.push($(this).data('ctype'));
if ($(this).data('eventcancelled')) {
visibleCancellation = 1;
}
}
});
return {
q: params.term, // Der Suchbegriff
term: params.term, // Der Suchbegriff
calendars: visibleCalendars, // Die dynamische letiable, die du hinzufügen möchtest
visibleCalendarTypes: visibleCalendarTypes,
visibleCancellation: visibleCancellation,
cal_id: $('#calendar-id').data('calendarid')
};
},
dataType: 'json',
delay: 250,
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.items
};
}
}
});
$('body').on('click', '.text-template', function () {
const date = new Date($('#start-date').val());
const formattedDate = date.toLocaleDateString('de-DE', {
day: '2-digit',
month: '2-digit',
year: 'numeric'
});
let starttime = $('#start-time').val();
let [stunden, minuten] = starttime.split(":").map(Number);
let endtime = $('#end-time').val();
let daytimetext;
if (stunden < 12) {
daytimetext = "vormittags";
} else {
daytimetext = "nachmittags";
}
let text = $(this).data('text');
text = text.replace(/\[&&vmnm&&\]/g, daytimetext);
text = text.replace(/\[&&date&&\]/g, formattedDate);
text = text.replace(/\[&&start&&\]/g, starttime);
text = text.replace(/\[&&end&&\]/g, endtime);
$('#customer-info-text').val(text);
});
$('body').on('change', '#customer,#customer-info-type', function () {
if ($('#name').val() == "") {
$('#name').val('IBN: ' + $("#customer").select2('data')[0].name);
}
if ($('#location').val() == "") {
$('#location').val($("#customer").select2('data')[0].location);
}
if ($('#customer-info-type').val() == 1) {
let data = $("#customer").select2('data')[0];
if (data) {
$('#customer-info-type-text').val(data.mail);
}
} else if ($('#customer-info-type').val() == 2) {
let data = $("#customer").select2('data')[0];
if (data) {
$('#customer-info-type-text').val(data.mobilenumber);
}
}
if ($(this).attr('id') == 'customer') {
if ($("#customer").select2('data')[0].spin) {// ID deines Editors
var currentContent = tinymce.activeEditor.getContent();
tinymce.activeEditor.setContent(currentContent + '<p style="margin-bottom: 0"><b>Service Pin: </b>' + $("#customer").select2('data')[0].spin + '</p>');
//
// $('#description').val('Service Pin: ' + $("#customer").select2('data')[0].spin + '\n');
}
}
});
$('body').on('change', '#ticket', function () {
if ($('#name').val() == "") {
$('#name').val('Störung: ' + $("#ticket").select2('data')[0].name);
}
if ($('#location').val() == "") {
$('#location').val($("#ticket").select2('data')[0].location);
}
var currentContent = tinymce.activeEditor.getContent();
tinymce.activeEditor.setContent(currentContent + '<p style="margin-bottom: 0"><b>Ticket Nr.: </b><a href="https://project.xinon.at/projects/storungen-and-support/work_packages/' + $("#ticket").select2('data')[0].id + '/activity" target="_blank">' + $("#ticket").select2('data')[0].id + '</a></p>\n' + $("#ticket").select2('data')[0].subject);
// $('#description').val('<a href="https://project.xinon.at/projects/storungen-and-support/work_packages/' + $("#ticket").select2('data')[0].id + '/activity" target="_blank">Ticket Nr.: ' + $("#ticket").select2('data')[0].id + '</a>\n' + $("#ticket").select2('data')[0].subject);
});
$("body").on("click", "#customer-info-check", function () {
if ($(this).prop('checked')) {
$('#customer-info-reminder-check').prop('checked', true);
}
});
$("body").on("click", ".add-cal-group-div", function () {
$('.add-cal-group-div-sub').prepend(` <div class="calendar-side-borders-sub mb-2">
<h5 ><span class="cal-group-name">Gruppe </span>
<div class="move-group-div">
<i class="fa-regular fa-arrows-up-down-left-right handle"></i>
</div>
<div class="group-checkbox-div"><input class="form-check-input group-checkbox" name="form-check-input" type="checkbox"></div>
<div class="dropdown-group-div"><i class="fa-duotone fa-solid dropdown-group fa-square-arrow-up"></i></div>
</h5> <div class="calendar-side-borders-sub-inner"></div>`);
$('.calendar-side-borders-sub-inner').sortable({
group: 'shared',
filter: 'h5',
});
});
$("body").on("dblclick", ".cal-group-name", function () {
if ($(this).find('.cal-group-name-input').length) {
return;
}
$(this).closest('div').find('.dropdown-group-div').hide();
$(this).closest('div').find('.move-group-div').hide();
$(this).closest('div').find('.group-checkbox-div').hide();
let groupname = $.trim($(this).text());
$(this).html('<input type="text" data-oldname="' + groupname + '" class="form-control cal-group-name-input" value="' + groupname + '">');
let strLength = $(this).find('.cal-group-name-input').val().length * 2;
$(this).find('.cal-group-name-input')[0].setSelectionRange(strLength, strLength);
$(this).find('.cal-group-name-input').focus();
});
$("body").on("click", ".group-checkbox", function () {
if ($(this).prop('checked')) {
$(this).closest('.calendar-side-borders-sub').find('.form-check-input').prop('checked', true);
refreshCalendarEvents()
} else {
$(this).closest('.calendar-side-borders-sub').find('.form-check-input').prop('checked', false);
refreshCalendarEvents()
}
let resources = calendar.getResources();
$.each(resources, function (index, value) {
value.remove();
});
let resourceCounter = 0;
$.each($('.calendar-check'), function (index, value) {
if ($(this).prop('checked')) {
rights = true;
calendar.addResource({
id: $(this).data('calendar_id'),
title: $.trim($(this).closest('div').find('label').text()),
order: resourceCounter
});
resourceCounter++;
}
});
$(".color-input").eq(0).trigger("change", 1);
checkGroupCheckboxes();
});
$("body").on("click", ".calendar-users-all", function () {
const resources = calendar.getResources();
let users = [];
$.each(resources, function (index, value) {
if (value.id < 900 && $('#calendar-users').val() != value.id) {
users.push(value.id);
}
});
$('#calendar-attendees').val(users).trigger('change');
});
$("body").on("click", ".dropdown-group", function () {
if ($(this).hasClass('fa-square-arrow-up')) {
$(this).removeClass('fa-square-arrow-up');
$(this).addClass('fa-square-arrow-down');
$(this).closest('.calendar-side-borders-sub').find('.calendar-side-borders-sub-inner').hide();
$(".color-input").eq(0).trigger("change", 1);
} else {
$(this).removeClass('fa-square-arrow-down');
$(this).addClass('fa-square-arrow-up');
$(this).closest('.calendar-side-borders-sub').find('.calendar-side-borders-sub-inner').show();
$(".color-input").eq(0).trigger("change", 1);
}
});
$("body").on("click", ".privacy-click", function (e) {
if ($(this).hasClass('fa-unlock')) {
$(this).removeClass('fa-unlock');
$(this).addClass('fa-lock');
$(this).prop('title', 'Privat');
} else {
$(this).removeClass('fa-lock');
$(this).addClass('fa-unlock');
$(this).prop('title', 'Normal');
}
});
$("body").on("keyup", ".cal-group-name-input", function (e) {
if (e.keyCode === 13) {
let groupname = $.trim($(this).val());
if (groupname.length > 3) {
$(this).closest('div').find('.dropdown-group-div').show();
$(this).closest('div').find('.move-group-div').show();
$(this).closest('div').find('.group-checkbox-div').show();
$(this).closest('.cal-group-name').text(groupname);
$(".color-input").eq(0).trigger("change", 1);
} else if (groupname.length == 0) {
if (confirm('Gruppe wirklich löschen?')) {
$(this).closest('.calendar-side-borders-sub').find('.form-check').each(function (index, value) {
let calendar = $(this).html();
$('.data-origin-' + $(this).data('origin')).append(`<div class="form-check text-left ml-2" data-origin="` + $(this).data('origin') + `">` + calendar + `</div>`);
});
$(this).closest('.calendar-side-borders-sub').remove();
$(".color-input").eq(0).trigger("change", 1);
}
$(this).closest('div').find('.dropdown-group-div').show();
$(this).closest('div').find('.move-group-div').show();
$(this).closest('div').find('.group-checkbox-div').show();
$(this).closest('.cal-group-name').text($(this).data('oldname'));
}
}
});
$("body").on("click", ".fa-xls-calendar", function (e) {
let checkbox = $(".calendar-check");
let calendarFilter = $('.btn-light-search');
let visibleCalendars = [];
let visibleCalendarTypes = [];
let mycalendar_id = $('#calendar-id').data('calendarid');
visibleCalendars.push(0);
checkbox.each(function () {
if ($(this).prop('checked')) {
visibleCalendars.push($(this).data('calendar_id'));
}
});
calendarFilter.each(function () {
if (!$(this).hasClass('top-search-filter')) {
visibleCalendarTypes.push($(this).data('ctype'));
}
});
$.ajax({
url: requestgenerateEventsxlsx,
method: 'POST',
data: {
visibleCalendars: visibleCalendars,
visibleCalendarTypes: visibleCalendarTypes
},
xhrFields: {
responseType: 'blob' // Erwartet binäre Daten als Blob
},
success: function (data, status, xhr) {
// Header auslesen, um den Dateinamen zu erhalten
var disposition = xhr.getResponseHeader('Content-Disposition');
var filename = "download.xlsx";
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
var matches = filenameRegex.exec(disposition);
if (matches != null && matches[1]) {
filename = matches[1].replace(/['"]/g, '');
}
}
// Blob in eine URL umwandeln und Download auslösen
var url = window.URL.createObjectURL(data);
var a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
},
error: function (jqXHR, status, error) {
console.error("Download error:", error);
}
});
});
$("body").on("blur", ".cal-group-name-input", function (e) {
let groupname = $.trim($(this).val());
if (groupname.length > 3) {
$(this).closest('div').find('.dropdown-group-div').show();
$(this).closest('div').find('.move-group-div').show();
$(this).closest('div').find('.group-checkbox-div').show();
$(this).closest('.cal-group-name').text(groupname);
$(".color-input").eq(0).trigger("change", 1);
} else {
$(this).closest('div').find('.dropdown-group-div').show();
$(this).closest('div').find('.move-group-div').show();
$(this).closest('div').find('.group-checkbox-div').show();
$(this).closest('.cal-group-name').text($(this).data('oldname'));
}
});
function getGroups() {
const groups = [];
$('.calendar-side-borders-sub').each(function (index, value) {
let show;
if ($(this).find('.fa-square-arrow-up').length) {
show = 1;
} else {
show = 0;
}
const group = {
name: $.trim($(this).find('h5').text()),
show: show,
origin: $(this).data('origin'),
calendars: []
};
$(this).find(('.form-check')).each(function (index, value) {
let checkbox = $(this).find('.calendar-check');
let checked;
if (checkbox.prop('checked')) {
checked = 1;
} else {
checked = 0;
}
group.calendars[index] = {
'calendar_id': $.trim(checkbox.data('calendar_id')),
'checked': checked,
origin: $(this).data('origin')
};
});
groups.push(group);
});
let groupsJson = JSON.stringify(groups);
return groupsJson;
}
function checkGroupCheckboxes() {
$('.group-checkbox').each(function (index, value) {
let checked = 0;
let unchecked = 0;
let thisis = $(this);
let ok = 0;
$(this).closest('.calendar-side-borders-sub').find('.calendar-check').each(function (index, value) {
if ($(this).prop('checked')) {
checked++;
} else {
unchecked++;
}
if (checked > 0 && unchecked > 0) {
$(this).closest('.calendar-side-borders-sub').find('.group-checkbox').prop('checked', false);
thisis.prop("indeterminate", true);
ok = 1;
return;
}
});
if (ok == 0) {
if (checked == 0) {
thisis.prop("indeterminate", false);
thisis.prop('checked', false);
} else {
thisis.prop("indeterminate", false);
thisis.prop('checked', true);
}
}
});
}
$('.calendar-side-borders-sub-inner').sortable({
group: 'shared',
filter: '.no-movable',
delay: 0,
animation: 0,
onEnd: function (evt) {
$('.calendar-check').eq(0).trigger('change');
},
});
$('.add-cal-group-div-sub').sortable({
filter: '.no-movable',
handle: '.handle',
delay: 0,
onEnd: function (evt) {
$('.calendar-check').eq(0).trigger('change');
},
});
if (firstcall) {
$('.color-input').trigger('change', 1);
}
$('.select2-multiple').select2(
{
dropdownParent: jQuery('#relContainer')
}
);
// $(document).on("select2:opening", (e) => {
// $('.modal-body').css('overflow', 'visible');
// });
// $(document).on("select2:open", (e) => {
// $('.modal-body').css('overflow', 'auto');
// });
// $.fn.select2.defaults.set("dropdownParent", $('#EventModal'));
checkGroupCheckboxes();
function refreshCalendarEvents() {
calendar.removeAllEvents();
let checkbox = $(".calendar-check");
let calendarFilter = $('.btn-light-search');
let visibleCalendars = [];
let visibleCancellation = 0;
let visibleCalendarTypes = [];
let mycalendar_id = $('#calendar-id').data('calendarid');
visibleCalendars.push(0);
checkbox.each(function () {
if ($(this).prop('checked')) {
visibleCalendars.push($(this).data('calendar_id'));
}
});
calendarFilter.each(function () {
if (!$(this).hasClass('top-search-filter')) {
visibleCalendarTypes.push($(this).data('ctype'));
if ($(this).data('eventcancelled')) {
visibleCancellation = 1;
}
}
});
$.post(requestUrl, {
visibleCalendars: visibleCalendars,
visibleCalendarTypes: visibleCalendarTypes,
visibleCancellation: visibleCancellation
}, function (data) {
}, 'json').done(function (json) {
if (json.success == true) {
let userevents = [];
let otherevents = [];
let resources = [];
let category = "";
let rights = false;
let movable = false;
let resourceCounter = 0;
let rrule = null;
let duration = null;
let rruleflag = false;
let allDAy = false;
let cursorclass = "";
$.each($('.calendar-check'), function (index, value) {
if ($(this).prop('checked')) {
rights = true;
resources.push({
id: $(this).data('calendar_id'),
title: $.trim($(this).closest('div').find('label').text()),
order: resourceCounter
});
resourceCounter++;
}
});
$.each(json.data, function (index, value) {
if (!value.timerecording.timerecording) {
rrule = null;
duration = null;
rruleflag = false;
allDAy = false;
cursorclass = "";
category = value.ccategory.ccategory;
if (value.rrule.rrule) {
rrule = value.rrule.rrule;
duration = value.duration.duration;
rruleflag = true;
}
if (value.calendar_id.calendar_id in calendarRights) {
if (calendarRights[value.calendar_id.calendar_id] == 'all') {
rights = true;
} else {
rights = false;
}
if (value.isorganizer.isorganizer == '1' && rights) {
movable = true;
} else if (rights) {
movable = false;
cursorclass = "cursor-alias";
} else {
movable = false;
}
if (value.privateflag.privateflag == '1' && mycalendar_id != value.calendar_id.calendar_id) {
rights = false;
movable = false;
}
if (value.allDay.allDay == "1") {
allDAy = true;
}
if (value.rrule.rrule) {
$.each(value.rrule_events.rrule_events, function (index, rrule_event) {
rruleflag = true;
let busy;
if (rrule_event.showAs == 'busy') {
busy = "1";
} else if (rrule_event.showAs == 'tentative') {
busy = '2';
} else if (rrule_event.showAs == 'free') {
busy = '0';
}
let event = {
id: value.id.id,
start: rrule_event.start,
end: rrule_event.end,
title: rrule_event.subject,
description: value.description.description,
location: value.location.location,
allDay: allDAy,
attachment: value.attachment.attachment,
attachments: value.attachments.attachments,
calendar_id: value.calendar_id,
event_type: value.event_type.event_type,
classNames: ['cal-class-group-' + value.calendar_id.calendar_id, 'cal-class-id-' + value.id.id, cursorclass],
textColor: value.txtColor.txtColor,
backgroundColor: value.bgColor.bgColor,
editable: rights,
privateflag: value.privateflag.privateflag,
rruleflag: rruleflag,
dates: rrule,
duration: duration,
droppable: movable,
startEditable: movable,
durationEditable: movable,
resizableFromStart: movable,
resourceId: value.calendar_id.calendar_id,
calendar_name: value.calendar_name.calendar_name,
clickable: rights,
mtime: value.mtime.mtime,
mname: value.mname.mname,
ctime: value.ctime.ctime,
cname: value.cname.cname,
busy: busy
};
userevents.push(event);
});
} else {
let event = {
id: value.id.id,
start: value.cstart.cstart,
end: value.cend.cend,
title: category,
description: value.description.description,
location: value.location.location,
allDay: allDAy,
attachment: value.attachment.attachment,
attachments: value.attachments.attachments,
calendar_id: value.calendar_id,
event_type: value.event_type.event_type,
classNames: ['cal-class-group-' + value.calendar_id.calendar_id, 'cal-class-id-' + value.id.id, cursorclass],
textColor: value.txtColor.txtColor,
backgroundColor: value.bgColor.bgColor,
editable: rights,
privateflag: value.privateflag.privateflag,
rruleflag: rruleflag,
dates: rrule,
duration: duration,
droppable: movable,
startEditable: movable,
durationEditable: movable,
resizableFromStart: movable,
resourceId: value.calendar_id.calendar_id,
calendar_name: value.calendar_name.calendar_name,
clickable: rights,
mtime: value.mtime.mtime,
mname: value.mname.mname,
ctime: value.ctime.ctime,
cname: value.cname.cname,
busy: value.busy.busy
};
userevents.push(event);
}
} else {
otherevents.push({
id: value.id.id,
start: value.cstart.cstart,
end: value.cend.cend,
title: category,
description: category,
color: 'red',
editable: false,
rruleflag: rruleflag,
rrule: rrule,
duration: duration,
calendar_id: value.calendar_id,
event_type: value.event_type.event_type,
classNames: ['cal-class-group-' + value.calendar_id.calendar_id, 'cal-class-id-' + value.id.id],
attachment: value.attachment.attachment,
attachments: value.attachments.attachments,
resourceId: value.calendar_id.calendar_id,
calendar_name: value.calendar_name.calendar_name,
clickable: false,
mtime: value.mtime.mtime,
mname: value.mname.mname,
ctime: value.ctime.ctime,
cname: value.cname.cname,
busy: value.busy.busy
});
}
} else {
let event = {
id: value.id.id,
start: value.cstart.cstart,
end: value.cend.cend,
title: value.category.category,
description: value.description.description,
calendar_id: value.calendar_id,
textColor: value.txtColor.txtColor,
backgroundColor: value.bgColor.bgColor,
resourceId: value.calendar_id.calendar_id,
calendar_name: value.calendar_name.calendar_name,
mtime: value.mtime.mtime,
mname: value.mname.mname,
ctime: value.ctime.ctime,
cname: value.cname.cname,
editable: false,
};
userevents.push(event);
}
});
calendar.addEventSource(userevents);
if (visibleCalendars.includes(998)) {
calendar.addEventSource(birthdays);
}
if (visibleCalendars.includes(997)) {
calendar.addEventSource(holiDays);
}
}
;
});
}
$(document).on('focusin', function (e) {
if ($(e.target).closest(".tox-tinymce, .tox-tinymce-aux, .moxman-window, .tam-assetmanager-root").length) {
e.stopImmediatePropagation();
}
});
$(document).ready(function () {
$('#recurringCheck').on('change', function () {
if ($(this).is(':checked')) {
$('#recurring-settings').show();
$('#rrule-until').attr('min', $('#start-date').val());
} else {
$('#recurring-settings').hide();
$('#weekly-options').hide();
$('#monthly-options').hide();
}
});
$('#rrule-frequency').on('change', function () {
var freq = $(this).val();
$('#weekly-options').hide();
$('#monthly-options').hide();
if (freq === 'WEEKLY') {
$('#weekly-options').show();
} else if (freq === 'MONTHLY') {
$('#monthly-options').show();
}
});
$('#monthly-type').on('change', function () {
var monthlyType = $(this).val();
if (monthlyType === 'BYMONTHDAY') {
$('#monthly-day-select').show();
$('#monthly-setpos-select').hide();
} else {
$('#monthly-day-select').hide();
$('#monthly-setpos-select').show();
}
});
});
let create_event = localStorage.getItem('Calendar_create');
if (create_event) {
localsorageEvent = JSON.parse(create_event);
$('#EventModal').modal('show');
}
$('body').on('change', '#calendar-users', function() {
reinitializeAttendeesSelect();
});
reinitializeAttendeesSelect();
});