Use default container delete view for map layers
authorThierry Florac <thierry.florac@onf.fr>
Wed, 11 Apr 2018 11:08:14 +0200
changeset 37 f8916da0b16b
parent 36 3ccb1e8d695f
child 38 961de1f9ed3a
Use default container delete view for map layers
src/pyams_gis/zmi/utility.py
--- a/src/pyams_gis/zmi/utility.py	Wed Apr 11 11:05:22 2018 +0200
+++ b/src/pyams_gis/zmi/utility.py	Wed Apr 11 11:08:14 2018 +0200
@@ -32,7 +32,7 @@
 from pyams_form.form import AJAXEditForm
 from pyams_i18n.column import I18nAttrColumn
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.container import ContainerView
+from pyams_skin.container import ContainerView, delete_container_element
 from pyams_skin.page import DefaultPageHeaderAdapter
 from pyams_skin.table import DefaultElementEditorAdapter, BaseTable, I18nColumn, TrashColumn
 from pyams_skin.viewlet.menu import MenuItem
@@ -88,12 +88,9 @@
     def data_attributes(self):
         manager = query_utility(IMapManager)
         attributes = super(MapManagerLayersTable, self).data_attributes
-        table_attrs = {'data-ams-location': absolute_url(manager, self.request),
-                       'data-ams-delete-target': 'delete-layer.json'}
-        if 'table' in attributes:
-            attributes['table'].update(table_attrs)
-        else:
-            attributes['table'] = table_attrs
+        attributes.setdefault('table', {}).update({
+            'data-ams-location': absolute_url(manager, self.request)
+        })
         return attributes
 
 
@@ -136,6 +133,13 @@
     permission = MANAGE_SYSTEM_PERMISSION
 
 
+@view_config(name='delete-element.json', context=IMapManager, request_type=IPyAMSLayer,
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
+def delete_map_manager_layer(request):
+    """Delete layer from map manager"""
+    return delete_container_element(request, ignore_permission=True)
+
+
 @adapter_config(context=(ISite, IAdminLayer, MapManagerLayersTable), provides=IValues)
 class MapManagerValuesAdapter(ContextRequestViewAdapter):
     """Map manager layers table values adapter"""
@@ -182,6 +186,8 @@
 class MapManagerConfigurationEditForm(AdminDialogEditForm):
     """Map manager edit form"""
 
+    prefix = 'map_configuration.'
+
     title = _("Maps manager")
     legend = _("Default map configuration")
     icon_css_class = 'fa fa-fw fa-map-marker'
@@ -202,24 +208,6 @@
     """Map manager edit form, JSON renderer"""
 
 
-@view_config(name='delete-layer.json', context=IMapManager, request_type=IPyAMSLayer,
-             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
-def delete_map_manager_layer(request):
-    """Delete layer from map manager"""
-    translate = request.localizer.translate
-    name = request.params.get('object_name')
-    if not name:
-        return {'status': 'message',
-                'messagebox': {'status': 'error',
-                               'content': translate(_("No provided object_name argument!"))}}
-    if name not in request.context:
-        return {'status': 'message',
-                'messagebox': {'status': 'error',
-                               'content': translate(_("Given layer name doesn't exist!"))}}
-    del request.context[name]
-    return {'status': 'success'}
-
-
 @view_config(name='get-map-configuration.json', context=Interface, request_type=IPyAMSLayer,
              renderer='json', xhr=True)
 def get_map_configuration(request):