[web ui] decorate form buttons with icons (at last) stable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Sat, 07 Nov 2009 22:04:45 +0100
branchstable
changeset 3803 414bb8439002
parent 3802 bc441a75f82c
child 3804 65bc65b2ccce
[web ui] decorate form buttons with icons (at last)
common/tags.py
web/__init__.py
web/data/cancel.png
web/data/external_resources
web/data/ok.png
web/data/plus.png
web/data/trash_can.png
web/data/trash_can_small.png
web/formwidgets.py
web/views/editforms.py
--- a/common/tags.py	Sat Nov 07 18:39:37 2009 +0100
+++ b/common/tags.py	Sat Nov 07 22:04:45 2009 +0100
@@ -18,6 +18,7 @@
         attrs.setdefault('escapecontent', self.escapecontent)
         return simple_sgml_tag(self.name, __content, **attrs)
 
+button = tag('button')
 input = tag('input')
 textarea = tag('textarea')
 a = tag('a')
--- a/web/__init__.py	Sat Nov 07 18:39:37 2009 +0100
+++ b/web/__init__.py	Sat Nov 07 22:04:45 2009 +0100
@@ -23,12 +23,12 @@
 
 class stdmsgs(object):
     """standard ui message (in a class for bw compat)"""
-    BUTTON_OK     = _('button_ok')
-    BUTTON_APPLY  = _('button_apply')
-    BUTTON_CANCEL = _('button_cancel')
-    BUTTON_DELETE = _('button_delete')
-    YES = _('yes')
-    NO  = _('no')
+    BUTTON_OK     = (_('button_ok'), 'OK_ICON')
+    BUTTON_APPLY  = (_('button_apply'), 'APPLY_ICON')
+    BUTTON_CANCEL = (_('button_cancel'), 'CANCEL_ICON')
+    BUTTON_DELETE = (_('button_delete'), 'TRASH_ICON')
+    YES = (_('yes'), None)
+    NO  = (_('no'), None)
 
 
 def eid_param(name, eid):
Binary file web/data/cancel.png has changed
--- a/web/data/external_resources	Sat Nov 07 18:39:37 2009 +0100
+++ b/web/data/external_resources	Sat Nov 07 22:04:45 2009 +0100
@@ -53,3 +53,8 @@
 UPLOAD_ICON = DATADIR/upload.gif
 GMARKER_ICON = DATADIR/gmap_blue_marker.png
 UP_ICON = DATADIR/up.gif
+
+OK_ICON = DATADIR/ok.png
+CANCEL_ICON = DATADIR/cancel.png
+APPLY_ICON = DATADIR/plus.png
+TRASH_ICON = DATADIR/trash_can_small.png
\ No newline at end of file
Binary file web/data/ok.png has changed
Binary file web/data/plus.png has changed
Binary file web/data/trash_can.png has changed
Binary file web/data/trash_can_small.png has changed
--- a/web/formwidgets.py	Sat Nov 07 18:39:37 2009 +0100
+++ b/web/formwidgets.py	Sat Nov 07 22:04:45 2009 +0100
@@ -13,6 +13,7 @@
 from cubicweb.common import tags, uilib
 from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE
 
+from logilab.mtconverter import xml_escape
 
 class FieldWidget(object):
     """abstract widget class"""
@@ -454,7 +455,12 @@
                  setdomid=None, settabindex=None,
                  name='', value='', onclick=None, cwaction=None):
         super(Button, self).__init__(attrs, setdomid, settabindex)
-        self.label = label
+        if isinstance(label, tuple):
+            self.label = label[0]
+            self.icon = label[1]
+        else:
+            self.label = label
+            self.icon = None
         self.name = name
         self.value = ''
         self.onclick = onclick
@@ -476,7 +482,12 @@
                 attrs['id'] = self.name
         if self.settabindex and not 'tabindex' in attrs:
             attrs['tabindex'] = form.req.next_tabindex()
-        return tags.input(value=label, type=self.type, **attrs)
+        if self.icon:
+            img = tags.img(src=form.req.external_resource(self.icon), alt=self.icon)
+        else:
+            img = u''
+        return tags.button(img + xml_escape(label), escapecontent=False,
+                           value=label, type=self.type, **attrs)
 
 
 class SubmitButton(Button):
--- a/web/views/editforms.py	Sat Nov 07 18:39:37 2009 +0100
+++ b/web/views/editforms.py	Sat Nov 07 22:04:45 2009 +0100
@@ -51,8 +51,8 @@
 
     domid = 'deleteconf'
     copy_nav_params = True
-    form_buttons = [Button(stdmsgs.YES, cwaction='delete'),
-                    Button(stdmsgs.NO, cwaction='cancel')]
+    form_buttons = [Button(stdmsgs.BUTTON_DELETE, cwaction='delete'),
+                    Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')]
     @property
     def action(self):
         return self.build_url('edit')