Move Map.renderEditToolbar to controls, for consistency

This commit is contained in:
Yohan Boniface 2023-07-25 17:50:28 +02:00
parent bd48bfc617
commit d449564250
2 changed files with 72 additions and 78 deletions

View file

@ -314,10 +314,7 @@ L.U.EditControl = L.Control.extend({
}, },
onAdd: function (map) { onAdd: function (map) {
const container = L.DomUtil.create( const container = L.DomUtil.create('div', 'leaflet-control-edit-enable'),
'div',
'leaflet-control-edit-enable',
),
edit = L.DomUtil.create('a', '', container) edit = L.DomUtil.create('a', '', container)
edit.href = '#' edit.href = '#'
edit.title = `${L._('Enable editing')} (Ctrl+E)` edit.title = `${L._('Enable editing')} (Ctrl+E)`
@ -1053,6 +1050,76 @@ L.U.Map.include({
}, },
}, },
renderEditToolbar: function () {
const container = L.DomUtil.create(
'div',
'umap-main-edit-toolbox with-transition dark',
this._controlContainer
),
logo = L.DomUtil.add('a', 'logo', container),
name = L.DomUtil.create('a', 'map-name', container),
share_status = L.DomUtil.create('a', 'share-status', container),
update = () => {
name.textContent = this.getDisplayName()
share_status.textContent = L._('Visibility: {status}', {
status: this.permissions.getShareStatusDisplay(),
})
}
update()
name.href = '#'
share_status.href = '#'
logo.href = '/'
if (this.options.user) {
const userLabel = L.DomUtil.add(
'a',
'umap-user',
container,
L._(`My maps ({username})`, { username: this.options.user.name })
)
userLabel.href = this.options.user.url
}
this.help.button(container, 'edit')
L.DomEvent.on(name, 'click', this.edit, this)
L.DomEvent.on(share_status, 'click', this.permissions.edit, this.permissions)
this.on('postsync', L.bind(update, this))
const save = L.DomUtil.create('a', 'leaflet-control-edit-save button', container)
save.href = '#'
save.title = `${L._('Save current edits')} (Ctrl+S)`
save.textContent = L._('Save')
const cancel = L.DomUtil.create('a', 'leaflet-control-edit-cancel', container)
cancel.href = '#'
cancel.title = `${L._('Cancel edits')} (Ctrl+Z)`
cancel.textContent = L._('Cancel all')
const disable = L.DomUtil.create('a', 'leaflet-control-edit-disable', container)
disable.href = '#'
disable.textContent = L._('Disable editing')
disable.title = `${disable.textContent} (Ctrl+E)`
L.DomEvent.addListener(disable, 'click', L.DomEvent.stop).addListener(
disable,
'click',
function (e) {
this.disableEdit(e)
this.ui.closePanel()
},
this
)
L.DomEvent.addListener(save, 'click', L.DomEvent.stop).addListener(
save,
'click',
this.save,
this
)
L.DomEvent.addListener(cancel, 'click', L.DomEvent.stop).addListener(
cancel,
'click',
this.askForReset,
this
)
},
renderShareBox: function () { renderShareBox: function () {
const container = L.DomUtil.create('div', 'umap-share') const container = L.DomUtil.create('div', 'umap-share')
const embedTitle = L.DomUtil.add('h4', '', container, L._('Embed the map')) const embedTitle = L.DomUtil.add('h4', '', container, L._('Embed the map'))

View file

@ -245,7 +245,7 @@ L.U.Map.include({
}, },
this this
) )
this.initEditBar() this.renderEditToolbar()
} }
this.initShortcuts() this.initShortcuts()
this.onceDatalayersLoaded(function () { this.onceDatalayersLoaded(function () {
@ -1802,79 +1802,6 @@ L.U.Map.include({
}) })
}, },
initEditBar: function () {
const container = L.DomUtil.create(
'div',
'umap-main-edit-toolbox with-transition dark',
this._controlContainer
),
logo = L.DomUtil.add('a', 'logo', container),
name = L.DomUtil.create('a', 'map-name', container),
share_status = L.DomUtil.create('a', 'share-status', container),
update = () => {
name.textContent = this.getDisplayName()
share_status.textContent = L._('Visibility: {status}', {
status: this.permissions.getShareStatusDisplay(),
})
}
update()
name.href = '#'
share_status.href = '#'
logo.href = '/'
if (this.options.user) {
const userLabel = L.DomUtil.add(
'a',
'umap-user',
container,
L._(`My maps ({username})`, {username: this.options.user.name})
)
userLabel.href = this.options.user.url
}
this.help.button(container, 'edit')
L.DomEvent.on(name, 'click', this.edit, this)
L.DomEvent.on(share_status, 'click', this.permissions.edit, this.permissions)
this.on('postsync', L.bind(update, this))
const save = L.DomUtil.create('a', 'leaflet-control-edit-save button', container)
save.href = '#'
save.title = `${L._('Save current edits')} (Ctrl+S)`
save.textContent = L._('Save')
const cancel = L.DomUtil.create(
'a',
'leaflet-control-edit-cancel',
container
)
cancel.href = '#'
cancel.title = L._('Cancel edits')
cancel.textContent = `${L._('Cancel all')} (Ctrl+Z)`
const disable = L.DomUtil.create('a', 'leaflet-control-edit-disable', container)
disable.href = '#'
disable.title = disable.textContent = L._('Disable editing')
L.DomEvent.addListener(disable, 'click', L.DomEvent.stop).addListener(
disable,
'click',
function (e) {
this.disableEdit(e)
this.ui.closePanel()
},
this
)
L.DomEvent.addListener(save, 'click', L.DomEvent.stop).addListener(
save,
'click',
this.save,
this
)
L.DomEvent.addListener(cancel, 'click', L.DomEvent.stop).addListener(
cancel,
'click',
this.askForReset,
this
)
},
askForReset: function (e) { askForReset: function (e) {
if (!confirm(L._('Are you sure you want to cancel your changes?'))) return if (!confirm(L._('Are you sure you want to cancel your changes?'))) return
this.reset() this.reset()