web/views/basecomponents.py
branchtls-sprint
changeset 661 4f61eb8a96b7
parent 658 b5c73b5cdc68
child 688 cddfbdee0eb3
equal deleted inserted replaced
660:5233a9457f6b 661:4f61eb8a96b7
    18 from cubicweb.schema import display_name
    18 from cubicweb.schema import display_name
    19 from cubicweb.common.selectors import (chainfirst, two_etypes_rset,
    19 from cubicweb.common.selectors import (chainfirst, two_etypes_rset,
    20                                     match_form_params)
    20                                     match_form_params)
    21 
    21 
    22 from cubicweb.web.htmlwidgets import MenuWidget, PopupBoxMenu, BoxSeparator, BoxLink
    22 from cubicweb.web.htmlwidgets import MenuWidget, PopupBoxMenu, BoxSeparator, BoxLink
    23 from cubicweb.web.component import (VComponent, EntityVComponent, 
    23 from cubicweb.web.component import (Component, EntityVComponent, 
    24                                     RelatedObjectsVComponent)
    24                                     RelatedObjectsVComponent)
    25 
    25 
    26 _ = unicode
    26 _ = unicode
    27 
    27 
    28 
    28 
    29 class RQLInputForm(VComponent):
    29 class RQLInputForm(Component):
    30     """build the rql input form, usually displayed in the header"""
    30     """build the rql input form, usually displayed in the header"""
    31     id = 'rqlinput'
    31     id = 'rqlinput'
    32     visible = False
    32     visible = False
    33        
    33        
    34     def call(self, view=None):
    34     def call(self, view=None):
    53             self.w(u'<input type="hidden" name="__mode" value="%s"/>'
    53             self.w(u'<input type="hidden" name="__mode" value="%s"/>'
    54                    % ':'.join(req.search_state[1]))
    54                    % ':'.join(req.search_state[1]))
    55         self.w(u'</form></div>')
    55         self.w(u'</form></div>')
    56 
    56 
    57 
    57 
    58 class ApplLogo(VComponent):
    58 class ApplLogo(Component):
    59     """build the application logo, usually displayed in the header"""
    59     """build the application logo, usually displayed in the header"""
    60     id = 'logo'
    60     id = 'logo'
    61     site_wide = True # don't want user to hide this component using an eproperty
    61     site_wide = True # don't want user to hide this component using an eproperty
    62     def call(self):
    62     def call(self):
    63         self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>'
    63         self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>'
    64                % (self.req.base_url(), self.req.external_resource('LOGO')))
    64                % (self.req.base_url(), self.req.external_resource('LOGO')))
    65 
    65 
    66 
    66 
    67 class ApplHelp(VComponent):
    67 class ApplHelp(Component):
    68     """build the help button, usually displayed in the header"""
    68     """build the help button, usually displayed in the header"""
    69     id = 'help'
    69     id = 'help'
    70     def call(self):
    70     def call(self):
    71         self.w(u'<a href="%s" class="help" title="%s">&nbsp;</a>'
    71         self.w(u'<a href="%s" class="help" title="%s">&nbsp;</a>'
    72                % (self.build_url(_restpath='doc/main'),
    72                % (self.build_url(_restpath='doc/main'),
    73                   self.req._(u'help'),))
    73                   self.req._(u'help'),))
    74 
    74 
    75 
    75 
    76 class UserLink(VComponent):
    76 class UserLink(Component):
    77     """if the user is the anonymous user, build a link to login
    77     """if the user is the anonymous user, build a link to login
    78     else a link to the connected user object with a loggout link
    78     else a link to the connected user object with a loggout link
    79     """
    79     """
    80     id = 'loggeduserlink'
    80     id = 'loggeduserlink'
    81     site_wide = True # don't want user to hide this component using an eproperty
    81     site_wide = True # don't want user to hide this component using an eproperty
   112             self.w(self.req._('anonymous'))
   112             self.w(self.req._('anonymous'))
   113             self.w(u'&nbsp;[<a class="logout" href="%s">%s</a>]'
   113             self.w(u'&nbsp;[<a class="logout" href="%s">%s</a>]'
   114                    % (self.build_url('login'), self.req._('login')))
   114                    % (self.build_url('login'), self.req._('login')))
   115 
   115 
   116 
   116 
   117 class ApplicationMessage(VComponent):
   117 class ApplicationMessage(Component):
   118     """display application's messages given using the __message parameter
   118     """display application's messages given using the __message parameter
   119     into a special div section
   119     into a special div section
   120     """
   120     """
   121     __selectors__ = yes,
   121     __selectors__ = yes,
   122     id = 'applmessages'
   122     id = 'applmessages'
   167         if rset:
   167         if rset:
   168             self.wview('table', rset, title=_(self.title), displayactions=False,
   168             self.wview('table', rset, title=_(self.title), displayactions=False,
   169                        displaycols=displaycols, headers=headers)
   169                        displaycols=displaycols, headers=headers)
   170 
   170 
   171 
   171 
   172 class ApplicationName(VComponent):
   172 class ApplicationName(Component):
   173     """display the application name"""
   173     """display the application name"""
   174     id = 'appliname'
   174     id = 'appliname'
   175 
   175 
   176     def call(self):
   176     def call(self):
   177         self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % (self.req.base_url(),
   177         self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % (self.req.base_url(),
   188     # register msg not generated since no entity use see_also in cubicweb itself
   188     # register msg not generated since no entity use see_also in cubicweb itself
   189     title = _('contentnavigation_seealso')
   189     title = _('contentnavigation_seealso')
   190     help = _('contentnavigation_seealso_description')
   190     help = _('contentnavigation_seealso_description')
   191 
   191 
   192     
   192     
   193 class EtypeRestrictionComponent(VComponent):
   193 class EtypeRestrictionComponent(Component):
   194     """displays the list of entity types contained in the resultset
   194     """displays the list of entity types contained in the resultset
   195     to be able to filter accordingly.
   195     to be able to filter accordingly.
   196     """
   196     """
   197     id = 'etypenavigation'
   197     id = 'etypenavigation'
   198     __select__ = classmethod(chainfirst(two_etypes_rset, match_form_params))
   198     __select__ = classmethod(chainfirst(two_etypes_rset, match_form_params))
   238         self.w(u'&nbsp;|&nbsp;'.join(html))
   238         self.w(u'&nbsp;|&nbsp;'.join(html))
   239         self.w(u'</div>')
   239         self.w(u'</div>')
   240         
   240         
   241 
   241 
   242 
   242 
   243 class RSSFeedURL(VComponent):
   243 class RSSFeedURL(Component):
   244     id = 'rss_feed_url'
   244     id = 'rss_feed_url'
   245     __selectors__ = (non_final_entity(),)
   245     __selectors__ = (non_final_entity(),)
   246     
   246     
   247     def feed_url(self):
   247     def feed_url(self):
   248         return self.build_url(rql=self.limited_rql(), vid='rss')
   248         return self.build_url(rql=self.limited_rql(), vid='rss')
   249 
   249 
   250 class RSSEntityFeedURL(VComponent):
   250 class RSSEntityFeedURL(Component):
   251     id = 'rss_feed_url'
   251     id = 'rss_feed_url'
   252     __selectors__ = (non_final_entity(), one_line_rset)
   252     __selectors__ = (non_final_entity(), one_line_rset)
   253     
   253     
   254     def feed_url(self):
   254     def feed_url(self):
   255         return self.entity(0, 0).rss_feed_url()
   255         return self.entity(0, 0).rss_feed_url()