From d449564250f8365bf7df068ad5f0237e93cf474b Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 25 Jul 2023 17:50:28 +0200 Subject: [PATCH] Move Map.renderEditToolbar to controls, for consistency --- umap/static/umap/js/umap.controls.js | 75 ++++++++++++++++++++++++++-- umap/static/umap/js/umap.js | 75 +--------------------------- 2 files changed, 72 insertions(+), 78 deletions(-) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 8b666d3c..b0d093c6 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -314,10 +314,7 @@ L.U.EditControl = L.Control.extend({ }, onAdd: function (map) { - const container = L.DomUtil.create( - 'div', - 'leaflet-control-edit-enable', - ), + const container = L.DomUtil.create('div', 'leaflet-control-edit-enable'), edit = L.DomUtil.create('a', '', container) edit.href = '#' 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 () { const container = L.DomUtil.create('div', 'umap-share') const embedTitle = L.DomUtil.add('h4', '', container, L._('Embed the map')) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index c9659080..b8b4bb0d 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -245,7 +245,7 @@ L.U.Map.include({ }, this ) - this.initEditBar() + this.renderEditToolbar() } this.initShortcuts() 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) { if (!confirm(L._('Are you sure you want to cancel your changes?'))) return this.reset()