Allow to reopen a dialog in dashboard previews

This commit is contained in:
Yohan Boniface 2023-12-22 17:16:06 +01:00 committed by David Larlet
parent ded244c9ff
commit c3cb813c23
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
2 changed files with 9 additions and 3 deletions

View file

@ -67,7 +67,7 @@
const container = this.parentNode const container = this.parentNode
container.innerHTML = data container.innerHTML = data
Array.prototype.forEach.call( Array.prototype.forEach.call(
container.querySelectorAll('script'), container.querySelectorAll('script:not([type="application/json"])'),
function (item) { function (item) {
eval(item.firstChild.textContent) eval(item.firstChild.textContent)
} }

View file

@ -28,12 +28,18 @@
{{ block.super }} {{ block.super }}
<script type="text/javascript"> <script type="text/javascript">
!(function () { !(function () {
const CACHE = {}
for (const mapOpener of document.querySelectorAll("button.map-opener")) { for (const mapOpener of document.querySelectorAll("button.map-opener")) {
mapOpener.addEventListener('click', (event) => { mapOpener.addEventListener('click', (event) => {
event.target.nextElementSibling.showModal() event.target.nextElementSibling.showModal()
const mapId = event.target.dataset.mapId const mapId = event.target.dataset.mapId
if (!document.querySelector(`#${mapId}_target`).hasChildNodes()) {
const previewSettings = JSON.parse(document.getElementById(mapId).textContent) const previewSettings = JSON.parse(document.getElementById(mapId).textContent)
const map = new L.U.Map(`${mapId}_target`, previewSettings) const map = new L.U.Map(`${mapId}_target`, previewSettings)
CACHE[mapId] = map
} else {
CACHE[mapId].invalidateSize()
}
}) })
} }
})() })()