From 327ae66d0219ad799dd17e9f2553db55e874f7ec Mon Sep 17 00:00:00 2001 From: rldhont Date: Wed, 1 May 2024 09:58:44 +0200 Subject: [PATCH] [Fix] Add Popup dock server side The popup dock is build client side by the JS and depends on `lizDict`. Since https://github.com/3liz/lizmap-web-client/pull/4329 the popup dock could be created before the `lizDict` is available. --- assets/src/legacy/map.js | 45 +++++++++++-------- lizmap/modules/lizmap/lib/Project/Project.php | 39 ++++++++++++++++ .../view/controllers/lizMap.classic.php | 2 +- 3 files changed, 66 insertions(+), 20 deletions(-) diff --git a/assets/src/legacy/map.js b/assets/src/legacy/map.js index 4a8621644e..6331394ab5 100644 --- a/assets/src/legacy/map.js +++ b/assets/src/legacy/map.js @@ -1834,29 +1834,36 @@ window.lizMap = function() { break; } } - if ( !popupsAvailable ) + if ( !popupsAvailable ) { + if ($('#mapmenu .nav-list > li.popupcontent > a').length ) { + $('#mapmenu .nav-list > li.popupcontent').remove(); + } return null; + } // Create the dock if needed if( 'popupLocation' in config.options && - config.options.popupLocation != 'map' && - !$('#mapmenu .nav-list > li.popupcontent > a').length ) { - // Verifying the message - if ( !('popup.msg.start' in lizDict) ) - lizDict['popup.msg.start'] = 'Click to the map to get informations.'; - // Initialize dock - var popupContainerId = 'popupcontent'; - var pcontent = '

'+lizDict['popup.msg.start']+'

'; - addDock(popupContainerId, 'Popup', config.options.popupLocation, pcontent, 'icon-comment'); - $('#button-popupcontent').click(function(){ - if($(this).parent().hasClass('active')) { - // clear highlight layer - lizMap.mainLizmap.map.clearHighlightFeatures(); - // remove information - $('#popupcontent > div.menu-content').html('

'+lizDict['popup.msg.start']+'

'); - } - }); - + config.options.popupLocation != 'map' ) { + if ( !$('#mapmenu .nav-list > li.popupcontent > a').length ) { + // Verifying the message + if ( !('popup.msg.start' in lizDict) ) + lizDict['popup.msg.start'] = 'Click to the map to get informations.'; + // Initialize dock + var popupContainerId = 'popupcontent'; + var pcontent = '

'+lizDict['popup.msg.start']+'

'; + addDock(popupContainerId, 'Popup', config.options.popupLocation, pcontent, 'icon-comment'); + $('#button-popupcontent').click(function(){ + if($(this).parent().hasClass('active')) { + // clear highlight layer + lizMap.mainLizmap.map.clearHighlightFeatures(); + // remove information + $('#popupcontent > div.menu-content').html('

'+lizDict['popup.msg.start']+'

'); + } + }); + } else { + $('#mapmenu .nav-list > li.popupcontent > a > span.icon').append(''); + $('#mapmenu .nav-list > li.popupcontent > a > span.icon').css('background-image', 'none'); + } } /** diff --git a/lizmap/modules/lizmap/lib/Project/Project.php b/lizmap/modules/lizmap/lib/Project/Project.php index e8e69f584b..3c10c50b22 100644 --- a/lizmap/modules/lizmap/lib/Project/Project.php +++ b/lizmap/modules/lizmap/lib/Project/Project.php @@ -2181,6 +2181,15 @@ public function getDefaultDockable() ); } + if ($this->getOption('popupLocation') === 'dock') { + $dockable[] = new \lizmapMapDockItem( + 'popupcontent', + 'Popup', + '', + 4 + ); + } + return $dockable; } @@ -2195,6 +2204,15 @@ public function getDefaultMiniDockable() $dockable = array(); $bp = $this->appContext->appConfig()->urlengine['basePath']; + if ($this->getOption('popupLocation') === 'mini-dock') { + $dockable[] = new \lizmapMapDockItem( + 'popupcontent', + 'Popup', + '', + 0 + ); + } + if ($this->hasAttributeLayers()) { // Add layer-export attribute to lizmap-selection-tool component if allowed $layerExport = $this->appContext->aclCheck('lizmap.tools.layer.export', $this->repository->getKey()) ? 'layer-export' : ''; @@ -2355,6 +2373,27 @@ public function getDefaultBottomDockable() return $dockable; } + /** + * @throws \jExceptionSelector + * + * @return \lizmapMapDockItem[] + */ + public function getDefaultRightDockable() + { + $dockable = array(); + + if ($this->getOption('popupLocation') === 'right-dock') { + $dockable[] = new \lizmapMapDockItem( + 'popupcontent', + 'Popup', + '', + 0 + ); + } + + return $dockable; + } + /** * Check if the project needs an update which lead to an error. * diff --git a/lizmap/modules/view/controllers/lizMap.classic.php b/lizmap/modules/view/controllers/lizMap.classic.php index ae35c93e78..2fa50b56e5 100644 --- a/lizmap/modules/view/controllers/lizMap.classic.php +++ b/lizmap/modules/view/controllers/lizMap.classic.php @@ -599,7 +599,7 @@ protected function getProjectDockables() $items = jEvent::notify('mapBottomDockable', array('repository' => $repository, 'project' => $project))->getResponse(); $assign['bottomdockable'] = mapDockItemsMerge($assign['bottomdockable'], $items); - $assign['rightdockable'] = array(); + $assign['rightdockable'] = $lproj->getDefaultRightDockable(); $items = jEvent::notify('mapRightDockable', array('repository' => $repository, 'project' => $project))->getResponse(); $assign['rightdockable'] = mapDockItemsMerge($assign['rightdockable'], $items);