prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 13 Nov 2009 11:16:24 +0100
branchstable
changeset 3840 2eff4348b1e4
parent 3839 84c9aab84d8c
child 3841 b2598c9eeffc
prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
web/component.py
web/data/cubicweb.css
web/views/basecomponents.py
--- a/web/component.py	Fri Nov 13 11:14:48 2009 +0100
+++ b/web/component.py	Fri Nov 13 11:16:24 2009 +0100
@@ -42,14 +42,14 @@
                             help=_('display the component or not')),
         _('order'):    dict(type='Int', default=99,
                             help=_('display order of the component')),
-        _('context'):  dict(type='String', default='header',
+        _('context'):  dict(type='String', default='navtop',
                             vocabulary=(_('navtop'), _('navbottom'),
-                                        _('navcontenttop'), _('navcontentbottom')),
-                            #vocabulary=(_('header'), _('incontext'), _('footer')),
+                                        _('navcontenttop'), _('navcontentbottom'),
+                                        _('ctxtoolbar')),
                             help=_('context where this component should be displayed')),
     }
 
-    context = 'navcontentbottom' # 'footer' | 'header' | 'incontext'
+    context = 'navcontentbottom'
 
     def call(self, view=None):
         return self.cell_call(0, 0, view=view)
--- a/web/data/cubicweb.css	Fri Nov 13 11:14:48 2009 +0100
+++ b/web/data/cubicweb.css	Fri Nov 13 11:16:24 2009 +0100
@@ -592,6 +592,15 @@
   display: inline;
 }
 
+div.ctxtoolbar {
+  float: right;
+  padding-left: 24px;
+  position: relative;
+}
+div.toolbarButton {
+  display: inline;
+}
+
 /***************************************/
 /* messages                            */
 /***************************************/
--- a/web/views/basecomponents.py	Fri Nov 13 11:14:48 2009 +0100
+++ b/web/views/basecomponents.py	Fri Nov 13 11:16:24 2009 +0100
@@ -204,21 +204,18 @@
         self.w(u'&#160;|&#160;'.join(html))
         self.w(u'</div>')
 
-class PdfViewComponent(component.Component):
-    id = 'pdfview'
-    __select__ = yes()
+
+class PdfViewComponent(component.EntityVComponent):
+    id = 'view_page_as_pdf'
+    context = 'ctxtoolbar'
 
-    context = 'header'
-    property_defs = {
-        _('visible'):  dict(type='Boolean', default=True,
-                            help=_('display the pdf icon or not')),
-    }
-
-    def call(self, vid):
-        entity = self.entity(0,0)
-        url = entity.absolute_url(vid=vid, __template='pdf-main-template')
-        self.w(u'<a href="%s" class="otherView"><img src="data/pdf_icon.gif" alt="%s"/></a>' %
-               (xml_escape(url), self.req._('download page as pdf')))
+    def cell_call(self, row, col, view):
+        entity = self.entity(row, col)
+        url = entity.absolute_url(vid=view.id, __template='pdf-main-template')
+        iconurl = self.req.build_url('data/pdf_icon.gif')
+        label = self.req._('Download page as pdf')
+        self.w(u'<a href="%s" title="%s" class="toolbarButton"><img src="%s" alt="%s"/></a>' %
+               (xml_escape(url), label, iconurl, label))