web/views/basecomponents.py
changeset 6428 de95bbed8781
parent 6396 a9e4c51fc1c1
child 6429 72669e7950c1
equal deleted inserted replaced
6427:c8a5ac2d1eaa 6428:de95bbed8781
    70             self.w(u'<input type="hidden" name="__mode" value="%s"/>'
    70             self.w(u'<input type="hidden" name="__mode" value="%s"/>'
    71                    % ':'.join(req.search_state[1]))
    71                    % ':'.join(req.search_state[1]))
    72         self.w(u'</form></div>')
    72         self.w(u'</form></div>')
    73 
    73 
    74 
    74 
    75 class ApplLogo(component.Component):
    75 
    76     """build the instance logo, usually displayed in the header"""
    76 class HeaderComponent(component.CtxComponent): # XXX rename properly along with related context
    77     __regid__ = 'logo'
       
    78     cw_property_defs = VISIBLE_PROP_DEF
       
    79     # don't want user to hide this component using an cwproperty
       
    80     site_wide = True
       
    81 
       
    82     def call(self):
       
    83         self.w(u'<a href="%s"><img id="logo" src="%s" alt="logo"/></a>'
       
    84                % (self._cw.base_url(), self._cw.uiprops['LOGO']))
       
    85 
       
    86 
       
    87 class ApplHelp(component.Component):
       
    88     """build the help button, usually displayed in the header"""
       
    89     __regid__ = 'help'
       
    90     cw_property_defs = VISIBLE_PROP_DEF
       
    91     def call(self):
       
    92         self.w(u'<a href="%s" class="help" title="%s">&#160;</a>'
       
    93                % (self._cw.build_url(_restpath='doc/main'),
       
    94                   self._cw._(u'help'),))
       
    95 
       
    96 
       
    97 class _UserLink(component.Component):
       
    98     """if the user is the anonymous user, build a link to login else display a menu
    77     """if the user is the anonymous user, build a link to login else display a menu
    99     with user'action (preference, logout, etc...)
    78     with user'action (preference, logout, etc...)
   100     """
    79     """
   101     __abstract__ = True
    80     __abstract__ = True
   102     __regid__ = 'loggeduserlink'
    81     cw_property_defs = component.override_ctx(
   103     cw_property_defs = VISIBLE_PROP_DEF
    82         component.CtxComponent,
       
    83         vocabulary=['header-left', 'header-center', 'header-right'])
   104     # don't want user to hide this component using an cwproperty
    84     # don't want user to hide this component using an cwproperty
   105     site_wide = True
    85     site_wide = True
   106 
    86     context = _('header-center')
   107 
    87 
   108 class CookieAnonUserLink(_UserLink):
    88 
   109     __select__ = (_UserLink.__select__ & anonymous_user()
    89 class ApplLogo(HeaderComponent):
       
    90     """build the instance logo, usually displayed in the header"""
       
    91     __regid__ = 'logo'
       
    92     order = -1
       
    93 
       
    94     def render(self, w):
       
    95         w(u'<a href="%s"><img id="logo" src="%s" alt="logo"/></a>'
       
    96           % (self._cw.base_url(), self._cw.uiprops['LOGO']))
       
    97 
       
    98 
       
    99 class ApplicationName(HeaderComponent):
       
   100     """display the instance name"""
       
   101     __regid__ = 'appliname'
       
   102     context = _('header-center')
       
   103 
       
   104     def render(self, w):
       
   105         title = self._cw.property_value('ui.site-title')
       
   106         if title:
       
   107             w(u'<span id="appliName"><a href="%s">%s</a></span>' % (
       
   108                 self._cw.base_url(), xml_escape(title)))
       
   109 
       
   110 
       
   111 class CookieLoginComponent(HeaderComponent):
       
   112     __regid__ = 'anonuserlink'
       
   113     __select__ = (HeaderComponent.__select__ & anonymous_user()
   110                   & configuration_values('auth-mode', 'cookie'))
   114                   & configuration_values('auth-mode', 'cookie'))
       
   115     context = 'header-right'
   111     loginboxid = 'popupLoginBox'
   116     loginboxid = 'popupLoginBox'
       
   117     _html = u"""[<a class="logout" title="%s" href="javascript:
       
   118 cw.htmlhelpers.popupLoginBox('%s', '__login');">%s</a>]"""
       
   119 
       
   120     def render(self, w):
       
   121         # XXX bw compat, though should warn about subclasses redefining call
       
   122         self.w = w
       
   123         self.call()
   112 
   124 
   113     def call(self):
   125     def call(self):
   114         w = self.w
   126         self.w(self._html % (self._cw._('login / password'),
   115         w(self._cw._('anonymous'))
   127                              self.loginboxid, self._cw._('i18n_login_popup')))
   116         w(u"""[<a class="logout" href="javascript: cw.htmlhelpers.popupLoginBox('%s', '__login');">%s</a>]"""
       
   117           % (self.loginboxid, self._cw._('i18n_login_popup')))
       
   118         self.wview('logform', rset=self.cw_rset, id=self.loginboxid,
   128         self.wview('logform', rset=self.cw_rset, id=self.loginboxid,
   119                    klass='hidden', title=False, showmessage=False)
   129                    klass='hidden', title=False, showmessage=False)
   120 
   130 
   121 AnonUserLink = class_renamed('AnonUserLink', CookieAnonUserLink)
   131 
   122 
   132 class HTTPLoginComponent(CookieLoginComponent):
   123 class HTTPAnonUserLink(_UserLink):
   133     __select__ = (HeaderComponent.__select__ & anonymous_user()
   124     __select__ = (_UserLink.__select__ & anonymous_user()
       
   125                   & configuration_values('auth-mode', 'http'))
   134                   & configuration_values('auth-mode', 'http'))
   126 
   135 
   127     def call(self):
   136     def render(self, w):
   128         w = self.w
       
   129         w(self._cw._('anonymous'))
       
   130         # this redirects to the 'login' controller which in turn
   137         # this redirects to the 'login' controller which in turn
   131         # will raise a 401/Unauthorized
   138         # will raise a 401/Unauthorized
   132         w(u'&#160;[<a class="logout" href="%s">%s</a>]'
   139         req = self._cw
   133           % (self._cw.build_url('login'), self._cw._('login')))
   140         w(u'[<a class="logout" title="%s" href="%s">%s</a>]'
   134 
   141           % (req._('login / password'), req.build_url('login'), req._('login')))
   135 class UserLink(_UserLink):
   142 
   136     __select__ = _UserLink.__select__ & authenticated_user()
   143 
   137 
   144 _UserLink = class_renamed('_UserLink', HeaderComponent)
   138     def call(self):
   145 AnonUserLink = class_renamed('AnonUserLink', CookieLoginComponent)
       
   146 AnonUserLink.__abstract__ = True
       
   147 AnonUserLink.__select__ &= yes(1)
       
   148 
       
   149 
       
   150 class AnonUserStatusLink(HeaderComponent):
       
   151     __regid__ = 'userstatus'
       
   152     __select__ = HeaderComponent.__select__ & anonymous_user()
       
   153     context = _('header-right')
       
   154     order = HeaderComponent.order - 10
       
   155 
       
   156     def render(self, w):
       
   157         w(u'<span class="caption">%s</span>' % self._cw._('anonymous'))
       
   158 
       
   159 
       
   160 class AuthenticatedUserStatus(AnonUserStatusLink):
       
   161     __select__ = HeaderComponent.__select__ & authenticated_user()
       
   162 
       
   163     def render(self, w):
   139         # display useractions and siteactions
   164         # display useractions and siteactions
   140         actions = self._cw.vreg['actions'].possible_actions(self._cw, rset=self.cw_rset)
   165         actions = self._cw.vreg['actions'].possible_actions(self._cw, rset=self.cw_rset)
   141         box = MenuWidget('', 'userActionsBox', _class='', islist=False)
   166         box = MenuWidget('', 'userActionsBox', _class='', islist=False)
   142         menu = PopupBoxMenu(self._cw.user.login, isitem=False)
   167         menu = PopupBoxMenu(self._cw.user.login, isitem=False)
   143         box.append(menu)
   168         box.append(menu)
   147         if actions.get('useractions') and actions.get('siteactions'):
   172         if actions.get('useractions') and actions.get('siteactions'):
   148             menu.append(BoxSeparator())
   173             menu.append(BoxSeparator())
   149         for action in actions.get('siteactions', ()):
   174         for action in actions.get('siteactions', ()):
   150             menu.append(BoxLink(action.url(), self._cw._(action.title),
   175             menu.append(BoxLink(action.url(), self._cw._(action.title),
   151                                 action.html_class()))
   176                                 action.html_class()))
   152         box.render(w=self.w)
   177         box.render(w=w)
   153 
   178 
   154 
   179 
   155 class ApplicationMessage(component.Component):
   180 class ApplicationMessage(component.Component):
   156     """display messages given using the __message parameter into a special div
   181     """display messages given using the __message parameter into a special div
   157     section
   182     section
   167         self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' %
   192         self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' %
   168                (toggle_action('appMsg'), (msgs and ' ' or 'hidden')))
   193                (toggle_action('appMsg'), (msgs and ' ' or 'hidden')))
   169         for msg in msgs:
   194         for msg in msgs:
   170             self.w(u'<div class="message" id="%s">%s</div>' % (self.domid, msg))
   195             self.w(u'<div class="message" id="%s">%s</div>' % (self.domid, msg))
   171         self.w(u'</div>')
   196         self.w(u'</div>')
   172 
       
   173 
       
   174 class ApplicationName(component.Component):
       
   175     """display the instance name"""
       
   176     __regid__ = 'appliname'
       
   177     cw_property_defs = VISIBLE_PROP_DEF
       
   178     # don't want user to hide this component using an cwproperty
       
   179     site_wide = True
       
   180 
       
   181     def call(self):
       
   182         title = self._cw.property_value('ui.site-title')
       
   183         if title:
       
   184             self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % (
       
   185                 self._cw.base_url(), xml_escape(title)))
       
   186 
   197 
   187 
   198 
   188 class EtypeRestrictionComponent(component.Component):
   199 class EtypeRestrictionComponent(component.Component):
   189     """displays the list of entity types contained in the resultset
   200     """displays the list of entity types contained in the resultset
   190     to be able to filter accordingly.
   201     to be able to filter accordingly.