Add share_status in edit toolbar

This commit is contained in:
Yohan Boniface 2023-07-25 09:02:08 +02:00
parent a74439ac47
commit 4e606d81bc
3 changed files with 27 additions and 9 deletions

View file

@ -67,13 +67,11 @@ L.U.Map.include({
initialize: function (el, geojson) {
// Locale name (pt_PT, en_US…)
// To be used for Django localization
if (geojson.properties.locale)
L.setLocale(geojson.properties.locale)
if (geojson.properties.locale) L.setLocale(geojson.properties.locale)
// Language code (pt-pt, en-us…)
// To be used in javascript APIs
if (geojson.properties.lang)
L.lang = geojson.properties.lang
if (geojson.properties.lang) L.lang = geojson.properties.lang
// Don't let default autocreation of controls
const zoomControl =
@ -91,7 +89,7 @@ L.U.Map.include({
this.ui = new L.U.UI(this._container)
this.xhr = new L.U.Xhr(this.ui)
this.xhr.on('dataloading', (e) => this.fire('dataloading', e))
this.xhr.on('dataloading', (e) => this.fire('dataloading', e))
this.xhr.on('dataload', (e) => this.fire('dataload', e))
this.initLoader()
@ -1811,19 +1809,31 @@ L.U.Map.include({
this._controlContainer
),
logo = L.DomUtil.add('a', 'logo', container),
name = L.DomUtil.add('a', 'map-name', container, this.getDisplayName()),
setName = function () {
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, this.options.user.name)
const userLabel = L.DomUtil.add(
'a',
'umap-user',
container,
this.options.user.name
)
userLabel.href = this.options.user.url
}
this.help.button(container, 'edit')
L.DomEvent.on(name, 'click', this.edit, this)
this.on('postsync', L.bind(setName, 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)`

View file

@ -160,6 +160,7 @@ L.U.MapPermissions = L.Class.extend({
this.commit()
this.isDirty = false
this.map.continueSaving()
this.map.fire('postsync')
},
})
},
@ -194,4 +195,8 @@ L.U.MapPermissions = L.Class.extend({
commit: function () {
L.Util.extend(this.map.options.permissions, this.options)
},
getShareStatusDisplay: function () {
return Object.fromEntries(this.map.options.share_statuses)[this.options.share_status]
}
})

View file

@ -479,6 +479,9 @@ ul.photon-autocomplete {
margin-right: 5px;
font-weight: bold;
}
.umap-main-edit-toolbox .share-status {
margin: 0 5px;
}
.umap-edit-enabled .umap-main-edit-toolbox {
top: 0;
}