Hide create/delete datalayers button + map settings to users without rights

This commit is contained in:
Yohan Boniface 2023-09-08 16:44:45 +02:00
parent 05726236ce
commit 73e95dcf07
3 changed files with 37 additions and 25 deletions

View file

@ -273,7 +273,12 @@ L.U.ContinueLineAction = L.U.BaseVertexAction.extend({
}) })
// Leaflet.Toolbar doesn't allow twice same toolbar class… // Leaflet.Toolbar doesn't allow twice same toolbar class…
L.U.SettingsToolbar = L.Toolbar.Control.extend({}) L.U.SettingsToolbar = L.Toolbar.Control.extend({
addTo: function (map) {
if (map.options.allowMapEdit === false) return
L.Toolbar.Control.prototype.addTo.call(this, map)
},
})
L.U.DrawToolbar = L.Toolbar.Control.extend({ L.U.DrawToolbar = L.Toolbar.Control.extend({
initialize: function (options) { initialize: function (options) {
L.Toolbar.Control.prototype.initialize.call(this, options) L.Toolbar.Control.prototype.initialize.call(this, options)
@ -608,21 +613,26 @@ L.U.DataLayer.include({
edit.title = L._('Edit') edit.title = L._('Edit')
table.title = L._('Edit properties in a table') table.title = L._('Edit properties in a table')
remove.title = L._('Delete layer') remove.title = L._('Delete layer')
if (this.isReadOnly()) {
L.DomUtil.addClass(container, 'readonly')
}
else {
L.DomEvent.on(edit, 'click', this.edit, this)
L.DomEvent.on(table, 'click', this.tableEdit, this)
L.DomEvent.on(
remove,
'click',
function () {
if (!this.isVisible()) return
if (!confirm(L._('Are you sure you want to delete this layer?'))) return
this._delete()
this.map.ui.closePanel()
},
this
)
}
L.DomEvent.on(toggle, 'click', this.toggle, this) L.DomEvent.on(toggle, 'click', this.toggle, this)
L.DomEvent.on(zoomTo, 'click', this.zoomTo, this) L.DomEvent.on(zoomTo, 'click', this.zoomTo, this)
L.DomEvent.on(edit, 'click', this.edit, this)
L.DomEvent.on(table, 'click', this.tableEdit, this)
L.DomEvent.on(
remove,
'click',
function () {
if (!this.isVisible()) return
if (!confirm(L._('Are you sure you want to delete this layer?'))) return
this._delete()
this.map.ui.closePanel()
},
this
)
L.DomUtil.addClass(container, this.getHidableClass()) L.DomUtil.addClass(container, this.getHidableClass())
L.DomUtil.classIf(container, 'off', !this.isVisible()) L.DomUtil.classIf(container, 'off', !this.isVisible())
container.dataset.id = L.stamp(this) container.dataset.id = L.stamp(this)
@ -1130,14 +1140,10 @@ L.U.Map.include({
toggleCaveat() toggleCaveat()
const download = L.DomUtil.create('a', 'button', container) const download = L.DomUtil.create('a', 'button', container)
download.textContent = L._('Download data') download.textContent = L._('Download data')
L.DomEvent.on( L.DomEvent.on(download, 'click', () => {
download, if (typeInput.value === 'umap') this.fullDownload()
'click', else this.download(typeInput.value)
() => { })
if (typeInput.value === 'umap') this.fullDownload()
else this.download(typeInput.value)
}
)
this.ui.openPanel({ data: { html: container } }) this.ui.openPanel({ data: { html: container } })
}, },
@ -1153,11 +1159,11 @@ L.U.Map.include({
let name = this.options.name || 'data' let name = this.options.name || 'data'
name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase() name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase()
const filename = name + type.ext const filename = name + type.ext
return {content, filetype: type.filetype, filename} return { content, filetype: type.filetype, filename }
}, },
download: function (mode) { download: function (mode) {
const {content, filetype, filename} = this.format(mode) const { content, filetype, filename } = this.format(mode)
const blob = new Blob([content], { type: filetype }) const blob = new Blob([content], { type: filetype })
window.URL = window.URL || window.webkitURL window.URL = window.URL || window.webkitURL
const el = document.createElement('a') const el = document.createElement('a')

View file

@ -756,15 +756,18 @@ a.map-name:after {
.umap-toggle-edit { .umap-toggle-edit {
background-position: -44px -48px; background-position: -44px -48px;
} }
.readonly .layer-table-edit,
.off .layer-table-edit { .off .layer-table-edit {
background-position: -74px -1px; background-position: -74px -1px;
} }
.readonly .layer-edit,
.off .layer-edit { .off .layer-edit {
background-position: -51px -72px; background-position: -51px -72px;
} }
.off .layer-zoom_to { .off .layer-zoom_to {
background-position: -25px -54px; background-position: -25px -54px;
} }
.readonly .layer-delete,
.off .layer-delete { .off .layer-delete {
background-position: -122px -121px; background-position: -122px -121px;
} }

View file

@ -448,7 +448,10 @@ class MapDetailMixin:
properties = { properties = {
"urls": _urls_for_js(), "urls": _urls_for_js(),
"tilelayers": TileLayer.get_list(), "tilelayers": TileLayer.get_list(),
"allowEdit": self.is_edit_allowed(), "allowEdit": self.is_edit_allowed(), # showEditMode
"allowMapEdit": self.object.can_edit(self.request.user, self.request)
if self.object
else True, # FIXME naming
"default_iconUrl": "%sumap/img/marker.png" % settings.STATIC_URL, # noqa "default_iconUrl": "%sumap/img/marker.png" % settings.STATIC_URL, # noqa
"umap_id": self.get_umap_id(), "umap_id": self.get_umap_id(),
"starred": self.is_starred(), "starred": self.is_starred(),