From 79b8b8bd3cca7d61a3a8485ac942363c05e39d45 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 21 Apr 2021 18:06:37 +0200 Subject: [PATCH] Can refresh the list of events --- assets/js/pages/groups/pages/presence.js | 43 ++++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/assets/js/pages/groups/pages/presence.js b/assets/js/pages/groups/pages/presence.js index 98835698..04d5166a 100644 --- a/assets/js/pages/groups/pages/presence.js +++ b/assets/js/pages/groups/pages/presence.js @@ -14,29 +14,12 @@ class GroupPresencePage { * @param {HTMLElement} target */ static async Show(group, target) { - const presence = await ForezPresenceHelper.GetList(group.id); - const users = await getUsers([...new Set(presence.map(e => e.userID))]); - // Load template const tpl = await Page.loadHTMLTemplate("pages/groups/pages/presence.html"); const el = document.createElement("div") el.innerHTML = tpl; target.appendChild(el); - - - const calEvents = presence.map((e) => { - return { - title: users.get(e.userID).fullName, - start: new Date(e.year, e.month - 1, e.day), - backgroundColor: "#0073b7", //Blue - borderColor: "#0073b7", //Blue - editable: e.userID == userID(), - allDay: true, - description: users.get(e.userID).fullName - } - }) - let lastClick = null; const calendarTarget = el.querySelector(".calendar"); @@ -47,7 +30,29 @@ class GroupPresencePage { right: 'dayGridMonth,listMonth' }, initialView: 'dayGridMonth', - events: calEvents, + + // Data source + events: async function(info, success, failure) { + try { + const presence = await ForezPresenceHelper.GetList(group.id); + const users = await getUsers([...new Set(presence.map(e => e.userID))]); + success(presence.map((e) => { + return { + title: users.get(e.userID).fullName, + start: new Date(e.year, e.month - 1, e.day), + backgroundColor: "#0073b7", //Blue + borderColor: "#0073b7", //Blue + editable: e.userID == userID(), + allDay: true, + description: users.get(e.userID).fullName + } + })); + + } catch(e) { + console.error(e); + failure(e); + } + }, // Update events eventResize: async function(info) { @@ -69,6 +74,8 @@ class GroupPresencePage { try { await ForezPresenceHelper.AddDay(group.id, info.date.getFullYear(), info.date.getMonth() + 1, info.date.getDate()) + + calendar.getEventSources()[0].refetch() } catch(e) { console.error(e); notify(tr("Failed to update presence!"), "danger")