improve calendar features
This commit is contained in:
52
js/main.js
52
js/main.js
@@ -172,6 +172,57 @@
|
||||
});
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Calendar Sync Button (syntax widget)
|
||||
// ============================================================
|
||||
function initCalendarSyncButtons() {
|
||||
document.addEventListener('click', function (e) {
|
||||
var btn = e.target;
|
||||
if (!btn || !btn.classList || !btn.classList.contains('luxtools-calendar-sync-btn')) return;
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var ajaxUrl = btn.getAttribute('data-luxtools-ajax-url') || '';
|
||||
var sectok = btn.getAttribute('data-luxtools-sectok') || '';
|
||||
if (!ajaxUrl) return;
|
||||
|
||||
var status = btn.parentNode ? btn.parentNode.querySelector('.luxtools-calendar-sync-status') : null;
|
||||
|
||||
btn.disabled = true;
|
||||
if (status) {
|
||||
status.textContent = 'Syncing...';
|
||||
status.style.color = '';
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', ajaxUrl, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
xhr.onload = function () {
|
||||
btn.disabled = false;
|
||||
try {
|
||||
var r = JSON.parse(xhr.responseText);
|
||||
if (status) {
|
||||
status.textContent = r.message || (r.ok ? 'Done' : 'Failed');
|
||||
status.style.color = r.ok ? 'green' : 'red';
|
||||
}
|
||||
} catch (ex) {
|
||||
if (status) {
|
||||
status.textContent = 'Error';
|
||||
status.style.color = 'red';
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
btn.disabled = false;
|
||||
if (status) {
|
||||
status.textContent = 'Network error';
|
||||
status.style.color = 'red';
|
||||
}
|
||||
};
|
||||
xhr.send('call=luxtools_calendar_sync§ok=' + encodeURIComponent(sectok));
|
||||
}, false);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Initialize
|
||||
// ============================================================
|
||||
@@ -181,6 +232,7 @@
|
||||
initChronologicalEventTimes();
|
||||
if (CalendarWidget && CalendarWidget.init) CalendarWidget.init();
|
||||
initPurgeCacheDialog();
|
||||
initCalendarSyncButtons();
|
||||
}, false);
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
if (Scratchpads && Scratchpads.init) Scratchpads.init();
|
||||
|
||||
Reference in New Issue
Block a user