Skip to content

Commit

Permalink
[Fix] Add Popup dock server side
Browse files Browse the repository at this point in the history
The popup dock is build client side by the JS and depends on `lizDict`.
Since #4329 the popup dock could be created before the `lizDict` is available.
  • Loading branch information
rldhont committed May 3, 2024
1 parent 3a4f561 commit 327ae66
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 20 deletions.
45 changes: 26 additions & 19 deletions assets/src/legacy/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div class="lizmapPopupContent"><h4>'+lizDict['popup.msg.start']+'</h4></div>';
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('<div class="lizmapPopupContent"><h4>'+lizDict['popup.msg.start']+'</h4></div>');
}
});

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 = '<div class="lizmapPopupContent"><h4>'+lizDict['popup.msg.start']+'</h4></div>';
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('<div class="lizmapPopupContent"><h4>'+lizDict['popup.msg.start']+'</h4></div>');
}
});
} else {
$('#mapmenu .nav-list > li.popupcontent > a > span.icon').append('<i class="icon-comment icon-white" style="margin-left: 4px;"></i>');
$('#mapmenu .nav-list > li.popupcontent > a > span.icon').css('background-image', 'none');
}
}

/**
Expand Down
39 changes: 39 additions & 0 deletions lizmap/modules/lizmap/lib/Project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,15 @@ public function getDefaultDockable()
);
}

if ($this->getOption('popupLocation') === 'dock') {
$dockable[] = new \lizmapMapDockItem(
'popupcontent',
'Popup',
'<div class="menu-content"><div class="lizmapPopupContent"><h4>'.$this->appContext->getLocale('view~dictionnary.popup.msg.start').'</h4></div></div>',
4
);
}

return $dockable;
}

Expand All @@ -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',
'<div class="menu-content"><div class="lizmapPopupContent"><h4>'.$this->appContext->getLocale('view~dictionnary.popup.msg.start').'</h4></div></div>',
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' : '';
Expand Down Expand Up @@ -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',
'<div class="menu-content"><div class="lizmapPopupContent"><h4>'.$this->appContext->getLocale('view~dictionnary.popup.msg.start').'</h4></div></div>',
0
);
}

return $dockable;
}

/**
* Check if the project needs an update which lead to an error.
*
Expand Down
2 changes: 1 addition & 1 deletion lizmap/modules/view/controllers/lizMap.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 327ae66

Please sign in to comment.