From 0a5ada9bf1d7bc554822ba5ce85a0087f6aaaf40 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 25 Feb 2019 15:50:42 +0100 Subject: [PATCH] js: Suspend Web 2's autorefresh while dragging items If a refresh happens while dragging the drop wont trigger any events and the change is not applied. --- public/js/module.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/public/js/module.js b/public/js/module.js index c38db67..d028b24 100644 --- a/public/js/module.js +++ b/public/js/module.js @@ -33,6 +33,9 @@ this.module.on('click', '.dashboard-tile', this.dashboardTileClick); this.module.on('end', 'div.tiles.sortable', this.tileDropped); + this.module.on('choose', '.sortable', this.suspendAutoRefresh); + this.module.on('unchoose', '.sortable', this.resumeAutoRefresh); + this.module.icinga.logger.debug('BP module initialized'); }, @@ -87,6 +90,18 @@ $(event.currentTarget).find('> .bp-link > a').first().trigger('click'); }, + suspendAutoRefresh: function(event) { + // TODO: If there is a better approach some time, let me know + $(event.originalEvent.from).closest('.container').data('lastUpdate', (new Date()).getTime() + 3600 * 1000); + event.stopPropagation(); + }, + + resumeAutoRefresh: function(event) { + var $container = $(event.originalEvent.from).closest('.container'); + $container.data('lastUpdate', (new Date()).getTime() - ($container.data('icingaRefresh') || 10) * 1000); + event.stopPropagation(); + }, + tileDropped: function(event) { var evt = event.originalEvent; if (evt.oldIndex !== evt.newIndex) {