Files
mrb-netbox-topology-views/netbox_topology_views/static_dev/js/images.js
T
MrBlakeandClaude Opus 5.5 cce6e21a09 feat(i18n): translate UI to English and German
Use English as source language for all user-visible strings, wrap them for
translation and ship a German catalog. Add a test that keeps the README's
NetBox range in sync with min_version/max_version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 21:25:38 +01:00

40 lines
1.2 KiB
JavaScript

import { toast } from './toast.js'
const mapping = {}
document.querySelector('form#images').addEventListener('submit', async (e) => {
e.preventDefault()
try {
const res = await fetch('/' + basePath + 'api/plugins/netbox_topology_views/images/save/', {
method: 'POST',
body: JSON.stringify(mapping),
headers: {
'X-CSRFToken': window.CSRF_TOKEN,
'Content-Type': 'application/json'
}
})
if (!res.ok) throw new Error(await res.text())
toast.success(window.topologyI18n?.savedSettings ?? 'Saved settings')
} catch (err) {
console.dir(err)
toast.error(err.message)
}
})
document.querySelectorAll('form#images .dropdown-menu img').forEach((el) => {
el.addEventListener('click', (e) => {
if (!(e.currentTarget instanceof HTMLElement)) return
const {
dataset: { role, image }
} = e.currentTarget
mapping[role] = image
const button = e.currentTarget
.closest('.dropdown')
?.querySelector(`#dropdownMenuButton${role}`)
if (button) button.innerHTML = `<img src="${image}" />`
})
})