From 2df67647d8109119c193bcb6fc1c25748c304d1d Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 9 Mar 2021 10:06:51 -0700 Subject: [PATCH] Calendar: Better refresh when toggling integrated apps --- calendar/js/app.js | 20 ++++++++++++++++---- calendar/js/app.ts | 26 +++++++++++++++++++++----- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/calendar/js/app.js b/calendar/js/app.js index 73d433af39..b72a978783 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -803,19 +803,31 @@ var CalendarApp = /** @class */ (function (_super) { } // Make sure it's an array, not an object integration_preference = jQuery.extend([], integration_preference); + var callback = function () { }; if (action.checked) { integration_preference.push(app); + // After the preference change is done, get new info which should now include the app + callback = function () { + this._fetch_data(this.state); + }.bind(this); } else { var index = integration_preference.indexOf(app); if (index > -1) { integration_preference.splice(index, 1); } + // Clear any events from that app + var events = egw.dataKnownUIDs('calendar'); + for (var i = 0; i < events.length; i++) { + var event_data = egw.dataGetUIDdata("calendar::" + events[i]).data || { app: "calendar" }; + if (event_data && event_data.app === app) { + // Remove entry, then delete it from the cache + egw.dataStoreUID("calendar::" + events[i], null); + egw.dataDeleteUID('calendar::' + events[i]); + } + } } - egw.set_preference("calendar", "integration_toggle", integration_preference); - // Force redraw to current state with new info, but wait a bit to let preference change get there first - this._clear_cache(); - window.setTimeout(function () { this.setState({ state: this.state }); }.bind(this), 500); + egw.set_preference("calendar", "integration_toggle", integration_preference, callback); }; /** * Set the app header diff --git a/calendar/js/app.ts b/calendar/js/app.ts index 6729db7d99..b83193716e 100644 --- a/calendar/js/app.ts +++ b/calendar/js/app.ts @@ -799,9 +799,16 @@ class CalendarApp extends EgwApp // Make sure it's an array, not an object integration_preference = jQuery.extend([],integration_preference); + let callback = function() {}; + if(action.checked) { integration_preference.push(app); + + // After the preference change is done, get new info which should now include the app + callback = function() { + this._fetch_data(this.state); + }.bind(this); } else { @@ -809,12 +816,21 @@ class CalendarApp extends EgwApp if (index > -1) { integration_preference.splice(index, 1); } - } - egw.set_preference("calendar","integration_toggle",integration_preference); - // Force redraw to current state with new info, but wait a bit to let preference change get there first - this._clear_cache(); - window.setTimeout(function() {this.setState({state: this.state})}.bind(this),500); + // Clear any events from that app + let events = egw.dataKnownUIDs('calendar'); + for(let i = 0; i < events.length; i++) + { + let event_data = egw.dataGetUIDdata("calendar::" + events[i]).data || {app: "calendar"}; + if(event_data && event_data.app === app) + { + // Remove entry, then delete it from the cache + egw.dataStoreUID("calendar::"+events[i], null); + egw.dataDeleteUID('calendar::' + events[i]); + } + } + } + egw.set_preference("calendar","integration_toggle",integration_preference, callback); } /**