Updated container eleement attribute switcher column
authorThierry Florac <thierry.florac@onf.fr>
Fri, 20 Jul 2018 12:40:13 +0200
changeset 384 2acc13873f0d
parent 383 86e1eae8090e
child 385 7547887dc2fb
Updated container eleement attribute switcher column
src/pyams_skin/table.py
--- a/src/pyams_skin/table.py	Fri Jul 20 12:39:53 2018 +0200
+++ b/src/pyams_skin/table.py	Fri Jul 20 12:40:13 2018 +0200
@@ -357,26 +357,27 @@
         return '#'
 
 
-class VisibilitySwitcherColumn(JsActionColumn):
-    """Visibility switcher column"""
+class AttributeSwitcherColumn(JsActionColumn):
+    """Switcher column"""
 
     cssClasses = {'th': 'action',
                   'td': 'action switcher'}
 
-    switch_attribute = 'visible'
-    visible_icon_class = 'fa fa-fw fa-eye'
-    hidden_icon_class = 'fa fa-fw fa-eye-slash text-danger'
+    icon_hint = _("Switch element attribute")
+
+    switch_attribute = None
 
-    icon_hint = _("Switch element visibility")
+    on_icon_class = 'fa fa-fw fa-eye'
+    off_icon_class = 'fa fa-fw fa-eye-slash text-danger'
 
-    url = 'MyAMS.container.switchElementVisibility'
+    url = 'MyAMS.container.switchElementAttribute'
     weight = 5
 
     def get_icon(self, item):
         if getattr(item, self.switch_attribute):
-            icon_class = self.visible_icon_class
+            icon_class = self.on_icon_class
         else:
-            icon_class = self.hidden_icon_class
+            icon_class = self.off_icon_class
         return '<i class="{0}"></i>'.format(icon_class)
 
     def renderCell(self, item):
@@ -384,7 +385,17 @@
         if permission and not self.request.has_permission(permission, context=item):
             return self.get_icon(item)
         else:
-            return super(VisibilitySwitcherColumn, self).renderCell(item)
+            return super(AttributeSwitcherColumn, self).renderCell(item)
+
+
+class VisibilitySwitcherColumn(AttributeSwitcherColumn):
+    """Visibility switcher column"""
+
+    switch_attribute = 'visible'
+
+    icon_hint = _("Switch element visibility")
+
+    url = 'MyAMS.container.switchElementVisibility'
 
 
 @adapter_config(name='actions', context=(Interface, IPyAMSLayer, ITableWithActions), provides=IColumn)