chore: new strategy to update map name when editing it

Also propagate share_status (this may be moved to permissions)
This commit is contained in:
Yohan Boniface 2024-10-04 10:17:34 +02:00
parent 0fdb70ce66
commit 0d7c6e451d
4 changed files with 37 additions and 22 deletions

View file

@ -19,7 +19,12 @@ export default class Caption {
open() { open() {
const container = DomUtil.create('div', 'umap-caption') const container = DomUtil.create('div', 'umap-caption')
const hgroup = DomUtil.element({ tagName: 'hgroup', parent: container }) const hgroup = DomUtil.element({ tagName: 'hgroup', parent: container })
DomUtil.createTitle(hgroup, this.map.options.name, 'icon-caption icon-block') DomUtil.createTitle(
hgroup,
this.map.getDisplayName(),
'icon-caption icon-block',
'map-name'
)
this.map.addAuthorLink('h4', hgroup) this.map.addAuthorLink('h4', hgroup)
if (this.map.options.description) { if (this.map.options.description) {
const description = DomUtil.element({ const description = DomUtil.element({

View file

@ -578,11 +578,15 @@ const ControlsMixin = {
], ],
renderEditToolbar: function () { renderEditToolbar: function () {
const container = L.DomUtil.create( const className = 'umap-main-edit-toolbox'
const container =
document.querySelector(`.${className}`) ||
L.DomUtil.create(
'div', 'div',
'umap-main-edit-toolbox with-transition dark', `${className} with-transition dark`,
this._controlContainer this._controlContainer
) )
container.innerHTML = ''
const leftContainer = L.DomUtil.create('div', 'umap-left-edit-toolbox', container) const leftContainer = L.DomUtil.create('div', 'umap-left-edit-toolbox', container)
const rightContainer = L.DomUtil.create('div', 'umap-right-edit-toolbox', container) const rightContainer = L.DomUtil.create('div', 'umap-right-edit-toolbox', container)
const logo = L.DomUtil.create('div', 'logo', leftContainer) const logo = L.DomUtil.create('div', 'logo', leftContainer)
@ -623,23 +627,10 @@ const ControlsMixin = {
}, },
this this
) )
const update = () => {
const status = this.permissions.getShareStatusDisplay()
nameButton.textContent = this.getDisplayName()
// status is not set until map is saved once
if (status) {
shareStatusButton.textContent = L._('Visibility: {status}', {
status: status,
})
}
}
update()
this.once('saved', L.bind(update, this))
if (this.options.editMode === 'advanced') { if (this.options.editMode === 'advanced') {
L.DomEvent.on(nameButton, 'click', this.editCaption, this) L.DomEvent.on(nameButton, 'click', this.editCaption, this)
L.DomEvent.on(shareStatusButton, 'click', this.permissions.edit, this.permissions) L.DomEvent.on(shareStatusButton, 'click', this.permissions.edit, this.permissions)
} }
this.on('postsync', L.bind(update, this))
if (this.options.user?.id) { if (this.options.user?.id) {
L.DomUtil.createLink( L.DomUtil.createLink(
'umap-user', 'umap-user',

View file

@ -141,10 +141,10 @@ L.DomUtil.createButtonIcon = (parent, className, title, callback, size = 16) =>
return el return el
} }
L.DomUtil.createTitle = (parent, text, className, tag = 'h3') => { L.DomUtil.createTitle = (parent, text, iconClassName, className = '', tag = 'h3') => {
const title = L.DomUtil.create(tag, '', parent) const title = L.DomUtil.create(tag, '', parent)
if (className) L.DomUtil.createIcon(title, className) if (className) L.DomUtil.createIcon(title, iconClassName)
L.DomUtil.add('span', '', title, text) L.DomUtil.add('span', className, title, text)
return title return title
} }

View file

@ -200,6 +200,7 @@ U.Map = L.Map.extend({
this.backup() this.backup()
this.on('click', this.closeInplaceToolbar) this.on('click', this.closeInplaceToolbar)
this.on('contextmenu', this.onContextMenu) this.on('contextmenu', this.onContextMenu)
this.propagate()
}, },
initSyncEngine: async function () { initSyncEngine: async function () {
@ -231,6 +232,7 @@ U.Map = L.Map.extend({
this.renderEditToolbar() this.renderEditToolbar()
this.renderControls() this.renderControls()
this.browser.redraw() this.browser.redraw()
this.propagate()
break break
case 'data': case 'data':
this.redrawVisibleDataLayers() this.redrawVisibleDataLayers()
@ -1097,6 +1099,7 @@ U.Map = L.Map.extend({
} else { } else {
window.location = data.url window.location = data.url
} }
this.propagate()
return true return true
}, },
@ -1118,6 +1121,22 @@ U.Map = L.Map.extend({
this.fire('saved') this.fire('saved')
}, },
propagate: function () {
let els = document.querySelectorAll('.map-name')
for (const el of els) {
el.textContent = this.getDisplayName()
}
const status = this.permissions.getShareStatusDisplay()
els = document.querySelectorAll('.share-status')
for (const el of els) {
if (status) {
el.textContent = L._('Visibility: {status}', {
status: status,
})
}
}
},
star: async function () { star: async function () {
if (!this.options.umap_id) { if (!this.options.umap_id) {
return U.Alert.error(L._('Please save the map first')) return U.Alert.error(L._('Please save the map first'))