diff --git a/public/index.html b/public/index.html index d0b3bfa..720649d 100644 --- a/public/index.html +++ b/public/index.html @@ -31,6 +31,14 @@ placeholder="Enter collection name" class="input-field"> + + +
+
+ + +
+
@@ -40,6 +48,10 @@
+
+ + +
diff --git a/public/script.js b/public/script.js index 58b1af9..b4bd429 100644 --- a/public/script.js +++ b/public/script.js @@ -129,6 +129,10 @@ function loadCalendarConfig(config, calendarName) { +
+ + +
`; calendars.appendChild(newCalendar); @@ -150,6 +154,10 @@ addCalendarButton.addEventListener('click', () => { +
+ + +
`; calendars.appendChild(newCalendar); @@ -159,6 +167,7 @@ addCalendarButton.addEventListener('click', () => { // Event listener for form submission form.addEventListener('submit', (event) => { event.preventDefault(); + const globalKeepProperties = document.getElementById('global-keep-properties').checked; const linkGroupName = document.getElementById('link-group-name').value; const calendarsData = []; let valid = true; // Flag to track URL validity @@ -166,8 +175,9 @@ form.addEventListener('submit', (event) => { for (let i = 0; i < calendarIndex; i++) { const prefix = document.getElementById(`prefix-${i}`); const override = document.getElementById(`override-${i}`); + const keepProperties = document.getElementById(`keep-properties-${i}`); const url = document.getElementById(`url-${i}`); - if (prefix && override && url && url.value) { + if (prefix && override && keepProperties && url && url.value) { // Validate the URL if (url.value.startsWith('http') && !isValidUrl(url.value)) { valid = false; // Set flag to false if any URL is invalid @@ -176,7 +186,8 @@ form.addEventListener('submit', (event) => { calendarsData.push({ prefix: prefix.value, override: override.checked, - url: url.value + url: url.value, + keepProperties: globalKeepProperties || keepProperties.checked }); } } diff --git a/src/calendarUtil.js b/src/calendarUtil.js index 53f6e85..e9d52e0 100644 --- a/src/calendarUtil.js +++ b/src/calendarUtil.js @@ -47,7 +47,7 @@ export function addEventsToCalendar(newCalendar, calendars) { calendars.forEach((calendarRaw) => { try { - const { data, prefix, override } = calendarRaw; // Extract prefix and override + const { data, prefix, override, keepProperties = false } = calendarRaw; // Extract prefix, override and keepProperties const calendar = new ICAL.Component(ICAL.parse(calendarRaw.data)); // Extract METHOD from the parsed data (if available) @@ -98,6 +98,44 @@ export function addEventsToCalendar(newCalendar, calendars) { newEvent.summary = prefix || 'Busy'; } else { newEvent.summary = prefix ? `${prefix} ${event.summary}` : event.summary; + } + + // Handle all properties based on keepProperties setting + if (keepProperties) { + // Preserve all available properties + if (event.location) newEvent.location = event.location; + if (event.description) newEvent.description = event.description; + + // Copy additional properties from the original component + const originalComponent = vevent; + + // Preserve URL (for call links) + const url = originalComponent.getFirstPropertyValue('url'); + if (url) newEvent.component.updatePropertyWithValue('url', url); + + // Preserve attendees + const attendees = originalComponent.getAllProperties('attendee'); + attendees.forEach(attendee => { + newEvent.component.addProperty(attendee); + }); + + // Preserve categories + const categories = originalComponent.getFirstPropertyValue('categories'); + if (categories) newEvent.component.updatePropertyWithValue('categories', categories); + + // Preserve organizer + const organizer = originalComponent.getFirstPropertyValue('organizer'); + if (organizer) newEvent.component.updatePropertyWithValue('organizer', organizer); + + // Preserve status + const status = originalComponent.getFirstPropertyValue('status'); + if (status) newEvent.component.updatePropertyWithValue('status', status); + + // Preserve class (privacy) + const eventClass = originalComponent.getFirstPropertyValue('class'); + if (eventClass) newEvent.component.updatePropertyWithValue('class', eventClass); + } else if (!override) { + // Backward compatibility: only preserve location when not overriding if (event.location) newEvent.location = event.location; }