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 35d7a5c550
commit 1cefd4e851
3 changed files with 31 additions and 15 deletions

View file

@ -273,7 +273,12 @@ L.U.ContinueLineAction = L.U.BaseVertexAction.extend({
})
// 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({
initialize: function (options) {
L.Toolbar.Control.prototype.initialize.call(this, options)
@ -608,8 +613,10 @@ L.U.DataLayer.include({
edit.title = L._('Edit')
table.title = L._('Edit properties in a table')
remove.title = L._('Delete layer')
L.DomEvent.on(toggle, 'click', this.toggle, this)
L.DomEvent.on(zoomTo, 'click', this.zoomTo, this)
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(
@ -623,6 +630,9 @@ L.U.DataLayer.include({
},
this
)
}
L.DomEvent.on(toggle, 'click', this.toggle, this)
L.DomEvent.on(zoomTo, 'click', this.zoomTo, this)
L.DomUtil.addClass(container, this.getHidableClass())
L.DomUtil.classIf(container, 'off', !this.isVisible())
container.dataset.id = L.stamp(this)

View file

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

View file

@ -449,7 +449,10 @@ class MapDetailMixin:
properties = {
"urls": _urls_for_js(),
"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
"umap_id": self.get_umap_id(),
"starred": self.is_starred(),