From 3b9dee051150bad44573bdf75557ac964c93a19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 11 Dec 2018 18:20:51 +0100 Subject: [PATCH] backoffice: don't let map popups block filter changes (#28913) --- wcs/qommon/static/js/qommon.map.js | 9 ++++++--- wcs/qommon/static/js/wcs.listing.js | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/wcs/qommon/static/js/qommon.map.js b/wcs/qommon/static/js/qommon.map.js index 8ff1ed67b..2db2416c6 100644 --- a/wcs/qommon/static/js/qommon.map.js +++ b/wcs/qommon/static/js/qommon.map.js @@ -118,7 +118,10 @@ $(window).on('load', function() { } $(document).on('backoffice-filter-change', function(event, listing_settings) { - if ($('.leaflet-popup').length > 0) return; + if ($('.leaflet-popup').length > 0 && listing_settings.auto == true) { + /* disable autorefresh when a popup is open */ + return; + } $('.qommon-map').each(function() { var base_url = $(this).data('geojson-url').split('?')[0]; map.eachLayer(function(layer) { @@ -126,7 +129,7 @@ $(window).on('load', function() { map.removeLayer(layer); } }); - $.getJSON(base_url + '?' + listing_settings, function(data) { + $.getJSON(base_url + '?' + listing_settings.qs, function(data) { var geo_json = L.geoJson(data, { onEachFeature: function(feature, layer) { if (feature.properties.display_fields.length > 0) { @@ -163,7 +166,7 @@ $(window).on('load', function() { }); }); if ($(this).data('geojson-url')) { - $(document).trigger('backoffice-filter-change', $('form#listing-settings').serialize()); + $(document).trigger('backoffice-filter-change', {qs: $('form#listing-settings').serialize()}); } }); $(document).trigger('wcs:maps-ready'); diff --git a/wcs/qommon/static/js/wcs.listing.js b/wcs/qommon/static/js/wcs.listing.js index 44ae12925..c078bf006 100644 --- a/wcs/qommon/static/js/wcs.listing.js +++ b/wcs/qommon/static/js/wcs.listing.js @@ -60,8 +60,14 @@ function prepare_column_headers() { }); } +function autorefresh_table() { + $(document).trigger('backoffice-filter-change', + {qs: $('form#listing-settings').serialize(), auto: true}); +} + function refresh_table() { - $(document).trigger('backoffice-filter-change', $('form#listing-settings').serialize()); + $(document).trigger('backoffice-filter-change', + {qs: $('form#listing-settings').serialize(), auto: false}); } $(document).on('backoffice-filter-change', function(event, listing_settings) { @@ -69,7 +75,7 @@ $(document).on('backoffice-filter-change', function(event, listing_settings) { var pathname = window.location.pathname.replace(/^\/+/, '/'); $.ajax({ - url: pathname + '?ajax=true&' + listing_settings, + url: pathname + '?ajax=true&' + listing_settings.qs, beforeSend: function() { $('#more-user-links, #listing, #statistics').addClass('activity'); }, complete: function() { $('#more-user-links, #listing, #statistics').removeClass('activity'); }, success: function(html) { @@ -83,10 +89,10 @@ $(document).on('backoffice-filter-change', function(event, listing_settings) { prepare_row_links(); prepare_column_headers(); $('a[data-base-href]').each(function(idx, elem) { - $(elem).attr('href', $(elem).data('base-href') + '?' + listing_settings); + $(elem).attr('href', $(elem).data('base-href') + '?' + listing_settings.qs); }); if (window.history) { - window.history.replaceState(null, null, pathname + '?' + listing_settings); + window.history.replaceState(null, null, pathname + '?' + listing_settings.qs); } /* makes sure activity and disabled-during-submit are removed */ $('#more-user-links, #listing, #statistics').removeClass('activity'); @@ -178,7 +184,7 @@ $(function() { return true; } event.preventDefault(); - $(document).trigger('backoffice-filter-change', $('form#listing-settings').serialize()); + $(document).trigger('backoffice-filter-change', {qs: $('form#listing-settings').serialize()}); return false; }); @@ -186,7 +192,7 @@ $(function() { var idle_id = null; $(window).on('mousemove keydown mousedown touchstart', function() { if (idle_id) window.clearInterval(idle_id); - idle_id = setInterval(refresh_table, 30000); + idle_id = setInterval(autorefresh_table, 30000); }); } -- 2.20.0.rc2