From 1adf0fb8723cc97f2d476459e55dd7972affdcd3 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 21 Apr 2021 17:55:04 +0200 Subject: [PATCH] Can delete day --- .../js/components/presence/PresenceHelper.js | 24 ++++++++++++++++++- assets/js/pages/groups/pages/presence.js | 18 +++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/assets/js/components/presence/PresenceHelper.js b/assets/js/components/presence/PresenceHelper.js index ccce0fe2..da7a13a4 100644 --- a/assets/js/components/presence/PresenceHelper.js +++ b/assets/js/components/presence/PresenceHelper.js @@ -56,11 +56,33 @@ class ForezPresenceHelper { * @param {number} day */ static async DelDay(groupID, year, month, day) { - await ws("forez_presence/add_day", { + await ws("forez_presence/del_day", { group: groupID, year: year, month: month, day: day }) } + + static async UpdateEvents(groupID, oldStart, oldEnd, newStart, newEnd) { + const newDays = new Set(getDaysOfRange(newStart, newEnd).map(el => el.getTime())); + const oldDays = new Set(getDaysOfRange(oldStart, oldEnd).map(el => el.getTime())); + + for (const el of newDays) { + if(oldDays.has(el)) { + newDays.delete(el) + oldDays.delete(el) + } + } + + for(const newEl of newDays) { + const date = new Date(newEl); + await this.AddDay(groupID, date.getFullYear(), date.getMonth() + 1, date.getDate()) + } + + for(const oldEl of oldDays) { + const date = new Date(oldEl); + await this.DelDay(groupID, date.getFullYear(), date.getMonth() + 1, date.getDate()) + } + } } \ No newline at end of file diff --git a/assets/js/pages/groups/pages/presence.js b/assets/js/pages/groups/pages/presence.js index 38b2ba3c..97be100b 100644 --- a/assets/js/pages/groups/pages/presence.js +++ b/assets/js/pages/groups/pages/presence.js @@ -48,19 +48,13 @@ class GroupPresencePage { events: calEvents, // Update events - eventResize: function(info) { - const newDays = new Set(getDaysOfRange(info.event.start, info.event.end).map(el => el.getTime())); - const oldDays = new Set(getDaysOfRange(info.oldEvent.start, info.oldEvent.end).map(el => el.getTime())); - - for (const el of newDays) { - if(oldDays.has(el)) { - newDays.delete(el) - oldDays.delete(el) - } + eventResize: async function(info) { + try { + await ForezPresenceHelper.UpdateEvents(group.id, info.oldEvent.start, info.oldEvent.end, info.event.start, info.event.end) + } catch(e) { + console.error(e); + notify(tr("Failed to update presence!"), "danger") } - - console.info("add", newDays) - console.info("del", oldDays) } });