From 87829331387985689a39ce04f3414100d4d79eb9 Mon Sep 17 00:00:00 2001 From: Rafael te Boekhorst Date: Tue, 24 Jan 2023 09:23:34 +0100 Subject: [PATCH 1/5] small fix for loading holidays correctly --- js/kronolith.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/js/kronolith.js b/js/kronolith.js index 7863ef77..55a42ee3 100644 --- a/js/kronolith.js +++ b/js/kronolith.js @@ -3853,8 +3853,17 @@ KronolithCore = { data.owner_input = null; } if (data.type == 'holiday') { - this.insertCalendarInList('holiday', data.driver, Kronolith.conf.calendars.holiday[data.driver]); - this.toggleCalendar('holiday', data.driver); + // checking if a holiday is already in the list + let check = this.getCalendarList(data.type).textContent.replace(/[^\w\s]/gi, ''); + if (check === data.driver){ + // if so: only toggle the calendar + this.toggleCalendar('holiday', data.driver); + } + else { + // if not so: add the calendar to the list + this.insertCalendarInList('holiday', data.driver, Kronolith.conf.calendars.holiday[data.driver]); + this.toggleCalendar('holiday', data.driver); + } form.down('.kronolithCalendarSave').enable(); this.closeRedBox(); this.go(this.lastLocation); From 9d35a24c172af2ff4b7665458773c6fded1143c7 Mon Sep 17 00:00:00 2001 From: Rafael te Boekhorst Date: Tue, 24 Jan 2023 09:47:26 +0100 Subject: [PATCH 2/5] adapting regex to deal with multiple calendars --- js/kronolith.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/kronolith.js b/js/kronolith.js index 55a42ee3..1dabc573 100644 --- a/js/kronolith.js +++ b/js/kronolith.js @@ -3854,8 +3854,8 @@ KronolithCore = { } if (data.type == 'holiday') { // checking if a holiday is already in the list - let check = this.getCalendarList(data.type).textContent.replace(/[^\w\s]/gi, ''); - if (check === data.driver){ + let check = this.getCalendarList(data.type).textContent; + if (check.includes(data.driver)){ // if so: only toggle the calendar this.toggleCalendar('holiday', data.driver); } From ed5a8cf1f5e4cb437d9fbef1e6d4cc21da4de279 Mon Sep 17 00:00:00 2001 From: Rafael te Boekhorst Date: Thu, 26 Jan 2023 15:26:30 +0100 Subject: [PATCH 3/5] iterating over list of unselected holidays retoggle them --- js/kronolith.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/js/kronolith.js b/js/kronolith.js index 1dabc573..879a5c25 100644 --- a/js/kronolith.js +++ b/js/kronolith.js @@ -3853,17 +3853,21 @@ KronolithCore = { data.owner_input = null; } if (data.type == 'holiday') { - // checking if a holiday is already in the list - let check = this.getCalendarList(data.type).textContent; - if (check.includes(data.driver)){ - // if so: only toggle the calendar + + // getting the holidays that are listed but unselected + let check = this.getCalendarList(data.type); + let checklist = check.select('span.horde-resource-off').map( + item => item = item.textContent + ); + + // checking if the new calendar is in the unselected list + if (checklist.indexOf(data.driver) > -1){ this.toggleCalendar('holiday', data.driver); - } - else { - // if not so: add the calendar to the list + }else{ this.insertCalendarInList('holiday', data.driver, Kronolith.conf.calendars.holiday[data.driver]); this.toggleCalendar('holiday', data.driver); } + form.down('.kronolithCalendarSave').enable(); this.closeRedBox(); this.go(this.lastLocation); From 2690314b7a3b3e14e08064713e112e2fe53de1df Mon Sep 17 00:00:00 2001 From: Rafael te Boekhorst Date: Fri, 27 Jan 2023 13:40:36 +0100 Subject: [PATCH 4/5] on refresh remove untoggled Holiday calendarsonly --- js/kronolith.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/js/kronolith.js b/js/kronolith.js index 879a5c25..d4e3953f 100644 --- a/js/kronolith.js +++ b/js/kronolith.js @@ -5096,6 +5096,21 @@ KronolithCore = { } else { // We want to always delete the cache, even if we are not // in a calendar view. + + if (type == 'holiday') { + // if it is not toggled: a refresh click should remove the holiday + try{ + $checkIfOff = elt.up().select('[class = "horde-resource-off"]'); + if (!$checkIfOff.first().empty()){ + elt.up().hide(); + } + } + catch(error){ + // the error is expected to happen + // TODO: find prettier solution + } + } + this.deleteCache([type, calendar]); this.loadCalendar(type, calendar); } From bfcb71af98b67ed697778df9162fbb4f3cdd91b3 Mon Sep 17 00:00:00 2001 From: Rafael te Boekhorst Date: Fri, 27 Jan 2023 22:13:58 +0100 Subject: [PATCH 5/5] use refresh button to remove unwanted calendars --- js/kronolith.js | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/js/kronolith.js b/js/kronolith.js index d4e3953f..7ee6ae52 100644 --- a/js/kronolith.js +++ b/js/kronolith.js @@ -3854,20 +3854,51 @@ KronolithCore = { } if (data.type == 'holiday') { + // getting the holidays that are listed but unselected - let check = this.getCalendarList(data.type); - let checklist = check.select('span.horde-resource-off').map( - item => item = item.textContent - ); - - // checking if the new calendar is in the unselected list - if (checklist.indexOf(data.driver) > -1){ - this.toggleCalendar('holiday', data.driver); - }else{ + let check = this.getCalendarList(data.type); + let checkOff2 = $('kronolithHolidayCalendars'); + try { + console.log(checkOff2); + } catch (error) { + //console.log(error); + + } + + // find if its of the off class. Then just toggle it and try to show it + let offClassTest = false; + try { + offClassTest = checkOff2.select('.horde-resource-off'); + } catch (error) { + //console.log(error); + } + + if(offClassTest !== false && offClassTest.size() > 0){ + // check if name matches and should be shown again + try { + offClassTest.each( + (item) => { + if(item.outerText === data.driver){ + console.log(item.up(1)); + if(!item.up(1).visible()){ + this.toggleCalendar('holiday', data.driver); + item.up(1).show(); + } + else { + this.toggleCalendar('holiday', data.driver); + } + } + } + ); + } catch (error) { + //console.log(error); + } + } else { this.insertCalendarInList('holiday', data.driver, Kronolith.conf.calendars.holiday[data.driver]); this.toggleCalendar('holiday', data.driver); } + form.down('.kronolithCalendarSave').enable(); this.closeRedBox(); this.go(this.lastLocation);