Updated action columns rendering
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Sep 2017 12:31:44 +0200
changeset 198 64511592fb27
parent 197 1094ad8e3e1b
child 199 2cef7c7c1894
Updated action columns rendering
src/pyams_skin/table.py
--- a/src/pyams_skin/table.py	Mon Sep 11 12:30:02 2017 +0200
+++ b/src/pyams_skin/table.py	Mon Sep 11 12:31:44 2017 +0200
@@ -201,12 +201,11 @@
                 checked = self.checker
             if not checked:
                 return ''
-        translate = self.request.localizer.translate
         return '''<a class="hint" title="{title}" href="{url}"
                      data-ams-stop-propagation="true"
                      {target} {modal} data-ams-hint-gravity="e">
             {icon}
-        </a>'''.format(title=translate(self.icon_hint),
+        </a>'''.format(title=self.get_icon_hint(item),
                        url=self.get_url(item),
                        target='data-ams-target="{0}"'.format(self.target) if self.target else '',
                        modal='data-toggle="modal"' if self.modal_target else '',
@@ -221,7 +220,13 @@
         return absolute_url(item, self.request, self.url)
 
     def get_icon(self, item):
-        return '<i class="{icon_class}"></i>'.format(icon_class=self.icon_class)
+        return '<i class="{icon_class}"></i>'.format(icon_class=self.get_icon_class(item))
+
+    def get_icon_class(self, item):
+        return self.icon_class
+
+    def get_icon_hint(self, item):
+        return self.request.localizer.translate(self.icon_hint)
 
 
 class JsActionColumn(ActionColumn):
@@ -235,7 +240,37 @@
     """Simple image column"""
 
     def renderCell(self, item):
-        return self.get_icon(item)
+        klass = self.get_icon_class(item)
+        hint = self.get_icon_hint(item)
+        if klass.startswith('fa-'):
+            img = '<i class="fa fa-fw {icon_class} {hint_class}" {title}></i>'.format(
+                icon_class=klass,
+                hint_class='hint opaque align-base' if hint else '',
+                title='title="{hint}"'.format(hint=hint) if hint else '')
+        elif klass.startswith('/'):
+            img = '<img src="{icon_class}" class="{img_class}" {title} />'.format(
+                icon_class=klass,
+                img_class='hint opaque align-base' if hint else '',
+                title='title="{hint}"'.format(hint=hint) if hint else '')
+        else:
+            img = klass
+        return img
+
+
+class SorterColumn(ActionColumn):
+    """Rows sorter column"""
+
+    cssClasses = {'th': 'action',
+                  'td': 'action sorter'}
+
+    icon_class = 'fa fa-fw fa-sort'
+    icon_hint = _("Click and drag to sort rows")
+
+    url = '#'
+    weight = 1
+
+    def get_url(self, item):
+        return '#'
 
 
 @adapter_config(name='actions', context=(Interface, IPyAMSLayer, ITableWithActions), provides=IColumn)