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… // 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,8 +613,10 @@ 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')
L.DomEvent.on(toggle, 'click', this.toggle, this) if (this.isReadOnly()) {
L.DomEvent.on(zoomTo, 'click', this.zoomTo, this) L.DomUtil.addClass(container, 'readonly')
}
else {
L.DomEvent.on(edit, 'click', this.edit, this) L.DomEvent.on(edit, 'click', this.edit, this)
L.DomEvent.on(table, 'click', this.tableEdit, this) L.DomEvent.on(table, 'click', this.tableEdit, this)
L.DomEvent.on( L.DomEvent.on(
@ -623,6 +630,9 @@ L.U.DataLayer.include({
}, },
this 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.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)

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

@ -449,7 +449,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(),