Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions availability/static/availability.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let isDirty = false;

function styleEvent(ev) {
if (ev.extendedProps.type === 'slot') {
if (ev.extendedProps.available === true) {
Expand Down Expand Up @@ -31,6 +33,7 @@ function eventClick(info) {
} else if (!ev.extendedProps.available) {
ev.setExtendedProp('available', null);
}
isDirty = true;
}
if (ev.extendedProps.type === 'span') {
if (info.jsEvent.shiftKey) {
Expand All @@ -39,6 +42,7 @@ function eventClick(info) {
} else if (allowMaybe) {
ev.setExtendedProp('maybe', !ev.extendedProps.maybe);
}
isDirty = true;
}
styleEvent(ev);
}
Expand All @@ -51,6 +55,7 @@ function calSelect(info) {
extendedProps: { type: 'span', maybe: false },
});
styleEvent(ev);
isDirty = true;
}

function fullcalDateToISO(date, calendar) {
Expand All @@ -59,6 +64,7 @@ function fullcalDateToISO(date, calendar) {
}

function onSubmit() {
isDirty = false;
const slots = [];
const spans = [];

Expand Down Expand Up @@ -126,6 +132,8 @@ function initialize(initialDate, nDays, events, hasSpans, timezones) {
selectable: hasSpans,
select: calSelect,
aspectRatio,
eventDrop: () => { isDirty = true; },
eventResize: () => { isDirty = true; },
});
calendar.getEvents().forEach(styleEvent);
calendar.render();
Expand All @@ -139,6 +147,18 @@ function initialize(initialDate, nDays, events, hasSpans, timezones) {
calendar.next();
});

document.getElementById('response').addEventListener('input', () => {
isDirty = true;
});

window.addEventListener('beforeunload', (e) => {
if (isDirty) {
e.preventDefault();
// eslint-disable-next-line no-param-reassign
e.returnValue = '';
}
});

const tzSelect = document.getElementById('timezone');
for (let i = 0; i < timezones.length; i += 1) {
const opt = document.createElement('option');
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading