feat(form): add global setting to keep event properties and update calendar handling
This commit is contained in:
parent
a841d51e30
commit
833398d921
3 changed files with 64 additions and 3 deletions
|
@ -31,6 +31,14 @@
|
||||||
placeholder="Enter collection name"
|
placeholder="Enter collection name"
|
||||||
class="input-field">
|
class="input-field">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Global Settings -->
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="checkbox-group">
|
||||||
|
<input type="checkbox" id="global-keep-properties" checked>
|
||||||
|
<label for="global-keep-properties">Keep all event properties (location, description, etc.) for all calendars</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="calendars">
|
<div id="calendars">
|
||||||
<div class="calendar-entry">
|
<div class="calendar-entry">
|
||||||
|
@ -40,6 +48,10 @@
|
||||||
<input type="checkbox" id="override-0">
|
<input type="checkbox" id="override-0">
|
||||||
<label for="override-0">Override</label>
|
<label for="override-0">Override</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="checkbox-group">
|
||||||
|
<input type="checkbox" id="keep-properties-0" checked>
|
||||||
|
<label for="keep-properties-0">Keep properties</label>
|
||||||
|
</div>
|
||||||
<button type="button" class="remove-btn" title="Remove calendar"></button>
|
<button type="button" class="remove-btn" title="Remove calendar"></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -129,6 +129,10 @@ function loadCalendarConfig(config, calendarName) {
|
||||||
<input type="checkbox" id="override-${calendarIndex}" ${calendar.override ? 'checked' : ''}>
|
<input type="checkbox" id="override-${calendarIndex}" ${calendar.override ? 'checked' : ''}>
|
||||||
<label for="override-${calendarIndex}">Override</label>
|
<label for="override-${calendarIndex}">Override</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="checkbox-group">
|
||||||
|
<input type="checkbox" id="keep-properties-${calendarIndex}" ${calendar.keepProperties ? 'checked' : ''}>
|
||||||
|
<label for="keep-properties-${calendarIndex}">Keep properties</label>
|
||||||
|
</div>
|
||||||
<button type="button" class="remove-btn" title="Remove calendar"></button>
|
<button type="button" class="remove-btn" title="Remove calendar"></button>
|
||||||
`;
|
`;
|
||||||
calendars.appendChild(newCalendar);
|
calendars.appendChild(newCalendar);
|
||||||
|
@ -150,6 +154,10 @@ addCalendarButton.addEventListener('click', () => {
|
||||||
<input type="checkbox" id="override-${calendarIndex}">
|
<input type="checkbox" id="override-${calendarIndex}">
|
||||||
<label for="override-${calendarIndex}">Override</label>
|
<label for="override-${calendarIndex}">Override</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="checkbox-group">
|
||||||
|
<input type="checkbox" id="keep-properties-${calendarIndex}" checked>
|
||||||
|
<label for="keep-properties-${calendarIndex}">Keep properties</label>
|
||||||
|
</div>
|
||||||
<button type="button" class="remove-btn" title="Remove calendar"></button>
|
<button type="button" class="remove-btn" title="Remove calendar"></button>
|
||||||
`;
|
`;
|
||||||
calendars.appendChild(newCalendar);
|
calendars.appendChild(newCalendar);
|
||||||
|
@ -159,6 +167,7 @@ addCalendarButton.addEventListener('click', () => {
|
||||||
// Event listener for form submission
|
// Event listener for form submission
|
||||||
form.addEventListener('submit', (event) => {
|
form.addEventListener('submit', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const globalKeepProperties = document.getElementById('global-keep-properties').checked;
|
||||||
const linkGroupName = document.getElementById('link-group-name').value;
|
const linkGroupName = document.getElementById('link-group-name').value;
|
||||||
const calendarsData = [];
|
const calendarsData = [];
|
||||||
let valid = true; // Flag to track URL validity
|
let valid = true; // Flag to track URL validity
|
||||||
|
@ -166,8 +175,9 @@ form.addEventListener('submit', (event) => {
|
||||||
for (let i = 0; i < calendarIndex; i++) {
|
for (let i = 0; i < calendarIndex; i++) {
|
||||||
const prefix = document.getElementById(`prefix-${i}`);
|
const prefix = document.getElementById(`prefix-${i}`);
|
||||||
const override = document.getElementById(`override-${i}`);
|
const override = document.getElementById(`override-${i}`);
|
||||||
|
const keepProperties = document.getElementById(`keep-properties-${i}`);
|
||||||
const url = document.getElementById(`url-${i}`);
|
const url = document.getElementById(`url-${i}`);
|
||||||
if (prefix && override && url && url.value) {
|
if (prefix && override && keepProperties && url && url.value) {
|
||||||
// Validate the URL
|
// Validate the URL
|
||||||
if (url.value.startsWith('http') && !isValidUrl(url.value)) {
|
if (url.value.startsWith('http') && !isValidUrl(url.value)) {
|
||||||
valid = false; // Set flag to false if any URL is invalid
|
valid = false; // Set flag to false if any URL is invalid
|
||||||
|
@ -176,7 +186,8 @@ form.addEventListener('submit', (event) => {
|
||||||
calendarsData.push({
|
calendarsData.push({
|
||||||
prefix: prefix.value,
|
prefix: prefix.value,
|
||||||
override: override.checked,
|
override: override.checked,
|
||||||
url: url.value
|
url: url.value,
|
||||||
|
keepProperties: globalKeepProperties || keepProperties.checked
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ export function addEventsToCalendar(newCalendar, calendars) {
|
||||||
|
|
||||||
calendars.forEach((calendarRaw) => {
|
calendars.forEach((calendarRaw) => {
|
||||||
try {
|
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));
|
const calendar = new ICAL.Component(ICAL.parse(calendarRaw.data));
|
||||||
|
|
||||||
// Extract METHOD from the parsed data (if available)
|
// Extract METHOD from the parsed data (if available)
|
||||||
|
@ -98,6 +98,44 @@ export function addEventsToCalendar(newCalendar, calendars) {
|
||||||
newEvent.summary = prefix || 'Busy';
|
newEvent.summary = prefix || 'Busy';
|
||||||
} else {
|
} else {
|
||||||
newEvent.summary = prefix ? `${prefix} ${event.summary}` : event.summary;
|
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;
|
if (event.location) newEvent.location = event.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue