web/views/basecomponents.py
changeset 3451 6b46d73823f5
parent 3407 da9cc8cc7c5f
child 3659 993997b4b41d
equal deleted inserted replaced
3448:495862266785 3451:6b46d73823f5
    35 
    35 
    36     def call(self, view=None):
    36     def call(self, view=None):
    37         if hasattr(view, 'filter_box_context_info'):
    37         if hasattr(view, 'filter_box_context_info'):
    38             rset = view.filter_box_context_info()[0]
    38             rset = view.filter_box_context_info()[0]
    39         else:
    39         else:
    40             rset = self.rset
    40             rset = self.cw_rset
    41         # display multilines query as one line
    41         # display multilines query as one line
    42         rql = rset is not None and rset.printable_rql(encoded=False) or self.req.form.get('rql', '')
    42         rql = rset is not None and rset.printable_rql(encoded=False) or self._cw.form.get('rql', '')
    43         rql = rql.replace(u"\n", u" ")
    43         rql = rql.replace(u"\n", u" ")
    44         req = self.req
    44         req = self._cw
    45         self.w(u'''<div id="rqlinput" class="%s">
    45         self.w(u'''<div id="rqlinput" class="%s">
    46           <form action="%s">
    46           <form action="%s">
    47 <fieldset>
    47 <fieldset>
    48 <input type="text" id="rql" name="rql" value="%s"  title="%s" tabindex="%s" accesskey="q" class="searchField" />
    48 <input type="text" id="rql" name="rql" value="%s"  title="%s" tabindex="%s" accesskey="q" class="searchField" />
    49 <input type="submit" value="" class="rqlsubmit" tabindex="%s" />
    49 <input type="submit" value="" class="rqlsubmit" tabindex="%s" />
    50 </fieldset>
    50 </fieldset>
    51 ''' % (not self.cw_propval('visible') and 'hidden' or '',
    51 ''' % (not self.cw_propval('visible') and 'hidden' or '',
    52        self.build_url('view'), xml_escape(rql), req._('full text or RQL query'), req.next_tabindex(),
    52        self._cw.build_url('view'), xml_escape(rql), req._('full text or RQL query'), req.next_tabindex(),
    53         req.next_tabindex()))
    53         req.next_tabindex()))
    54         if self.req.search_state[0] != 'normal':
    54         if self._cw.search_state[0] != 'normal':
    55             self.w(u'<input type="hidden" name="__mode" value="%s"/>'
    55             self.w(u'<input type="hidden" name="__mode" value="%s"/>'
    56                    % ':'.join(req.search_state[1]))
    56                    % ':'.join(req.search_state[1]))
    57         self.w(u'</form></div>')
    57         self.w(u'</form></div>')
    58 
    58 
    59 
    59 
    64     # don't want user to hide this component using an cwproperty
    64     # don't want user to hide this component using an cwproperty
    65     site_wide = True
    65     site_wide = True
    66 
    66 
    67     def call(self):
    67     def call(self):
    68         self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>'
    68         self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>'
    69                % (self.req.base_url(), self.req.external_resource('LOGO')))
    69                % (self._cw.base_url(), self._cw.external_resource('LOGO')))
    70 
    70 
    71 
    71 
    72 class ApplHelp(component.Component):
    72 class ApplHelp(component.Component):
    73     """build the help button, usually displayed in the header"""
    73     """build the help button, usually displayed in the header"""
    74     __regid__ = 'help'
    74     __regid__ = 'help'
    75     cw_property_defs = VISIBLE_PROP_DEF
    75     cw_property_defs = VISIBLE_PROP_DEF
    76     def call(self):
    76     def call(self):
    77         self.w(u'<a href="%s" class="help" title="%s">&#160;</a>'
    77         self.w(u'<a href="%s" class="help" title="%s">&#160;</a>'
    78                % (self.build_url(_restpath='doc/main'),
    78                % (self._cw.build_url(_restpath='doc/main'),
    79                   self.req._(u'help'),))
    79                   self._cw._(u'help'),))
    80 
    80 
    81 
    81 
    82 class UserLink(component.Component):
    82 class UserLink(component.Component):
    83     """if the user is the anonymous user, build a link to login
    83     """if the user is the anonymous user, build a link to login
    84     else a link to the connected user object with a loggout link
    84     else a link to the connected user object with a loggout link
    87     # don't want user to hide this component using an cwproperty
    87     # don't want user to hide this component using an cwproperty
    88     site_wide = True
    88     site_wide = True
    89     __regid__ = 'loggeduserlink'
    89     __regid__ = 'loggeduserlink'
    90 
    90 
    91     def call(self):
    91     def call(self):
    92         if not self.req.cnx.anonymous_connection:
    92         if not self._cw.cnx.anonymous_connection:
    93             # display useractions and siteactions
    93             # display useractions and siteactions
    94             actions = self.vreg['actions'].possible_actions(self.req, rset=self.rset)
    94             actions = self._cw.vreg['actions'].possible_actions(self._cw, rset=self.cw_rset)
    95             box = MenuWidget('', 'userActionsBox', _class='', islist=False)
    95             box = MenuWidget('', 'userActionsBox', _class='', islist=False)
    96             menu = PopupBoxMenu(self.req.user.login, isitem=False)
    96             menu = PopupBoxMenu(self._cw.user.login, isitem=False)
    97             box.append(menu)
    97             box.append(menu)
    98             for action in actions.get('useractions', ()):
    98             for action in actions.get('useractions', ()):
    99                 menu.append(BoxLink(action.url(), self.req._(action.title),
    99                 menu.append(BoxLink(action.url(), self._cw._(action.title),
   100                                     action.html_class()))
   100                                     action.html_class()))
   101             if actions.get('useractions') and actions.get('siteactions'):
   101             if actions.get('useractions') and actions.get('siteactions'):
   102                 menu.append(BoxSeparator())
   102                 menu.append(BoxSeparator())
   103             for action in actions.get('siteactions', ()):
   103             for action in actions.get('siteactions', ()):
   104                 menu.append(BoxLink(action.url(), self.req._(action.title),
   104                 menu.append(BoxLink(action.url(), self._cw._(action.title),
   105                                     action.html_class()))
   105                                     action.html_class()))
   106             box.render(w=self.w)
   106             box.render(w=self.w)
   107         else:
   107         else:
   108             self.anon_user_link()
   108             self.anon_user_link()
   109 
   109 
   110     def anon_user_link(self):
   110     def anon_user_link(self):
   111         if self.config['auth-mode'] == 'cookie':
   111         if self._cw.config['auth-mode'] == 'cookie':
   112             self.w(self.req._('anonymous'))
   112             self.w(self._cw._('anonymous'))
   113             self.w(u'''&#160;[<a class="logout" href="javascript: popupLoginBox();">%s</a>]'''
   113             self.w(u'''&#160;[<a class="logout" href="javascript: popupLoginBox();">%s</a>]'''
   114                    % (self.req._('i18n_login_popup')))
   114                    % (self._cw._('i18n_login_popup')))
   115         else:
   115         else:
   116             self.w(self.req._('anonymous'))
   116             self.w(self._cw._('anonymous'))
   117             self.w(u'&#160;[<a class="logout" href="%s">%s</a>]'
   117             self.w(u'&#160;[<a class="logout" href="%s">%s</a>]'
   118                    % (self.build_url('login'), self.req._('login')))
   118                    % (self._cw.build_url('login'), self._cw._('login')))
   119 
   119 
   120 
   120 
   121 class ApplicationMessage(component.Component):
   121 class ApplicationMessage(component.Component):
   122     """display messages given using the __message parameter into a special div
   122     """display messages given using the __message parameter into a special div
   123     section
   123     section
   126     __regid__ = 'applmessages'
   126     __regid__ = 'applmessages'
   127     # don't want user to hide this component using an cwproperty
   127     # don't want user to hide this component using an cwproperty
   128     cw_property_defs = {}
   128     cw_property_defs = {}
   129 
   129 
   130     def call(self):
   130     def call(self):
   131         msgs = [msg for msg in (self.req.get_shared_data('sources_error', pop=True),
   131         msgs = [msg for msg in (self._cw.get_shared_data('sources_error', pop=True),
   132                                 self.req.message) if msg]
   132                                 self._cw.message) if msg]
   133         self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' %
   133         self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' %
   134                (toggle_action('appMsg'), (msgs and ' ' or 'hidden')))
   134                (toggle_action('appMsg'), (msgs and ' ' or 'hidden')))
   135         for msg in msgs:
   135         for msg in msgs:
   136             self.w(u'<div class="message" id="%s">%s</div>' % (
   136             self.w(u'<div class="message" id="%s">%s</div>' % (
   137                 self.div_id(), msg))
   137                 self.div_id(), msg))
   144     cw_property_defs = VISIBLE_PROP_DEF
   144     cw_property_defs = VISIBLE_PROP_DEF
   145     # don't want user to hide this component using an cwproperty
   145     # don't want user to hide this component using an cwproperty
   146     site_wide = True
   146     site_wide = True
   147 
   147 
   148     def call(self):
   148     def call(self):
   149         title = self.req.property_value('ui.site-title')
   149         title = self._cw.property_value('ui.site-title')
   150         if title:
   150         if title:
   151             self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % (
   151             self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % (
   152                 self.req.base_url(), xml_escape(title)))
   152                 self._cw.base_url(), xml_escape(title)))
   153 
   153 
   154 
   154 
   155 class SeeAlsoVComponent(component.RelatedObjectsVComponent):
   155 class SeeAlsoVComponent(component.RelatedObjectsVComponent):
   156     """display any entity's see also"""
   156     """display any entity's see also"""
   157     __regid__ = 'seealso'
   157     __regid__ = 'seealso'
   175     # don't want user to hide this component using an cwproperty
   175     # don't want user to hide this component using an cwproperty
   176     site_wide = True
   176     site_wide = True
   177     visible = False # disabled by default
   177     visible = False # disabled by default
   178 
   178 
   179     def call(self):
   179     def call(self):
   180         _ = self.req._
   180         _ = self._cw._
   181         self.w(u'<div id="etyperestriction">')
   181         self.w(u'<div id="etyperestriction">')
   182         restrtype = self.req.form.get('__restrtype')
   182         restrtype = self._cw.form.get('__restrtype')
   183         restrtypes = self.req.form.get('__restrtypes', '').split(',')
   183         restrtypes = self._cw.form.get('__restrtypes', '').split(',')
   184         restrrql = self.req.form.get('__restrrql')
   184         restrrql = self._cw.form.get('__restrrql')
   185         if not restrrql:
   185         if not restrrql:
   186             rqlst = self.rset.syntax_tree()
   186             rqlst = self.cw_rset.syntax_tree()
   187             restrrql = rqlst.as_string(self.req.encoding, self.rset.args)
   187             restrrql = rqlst.as_string(self._cw.encoding, self.cw_rset.args)
   188             restrtypes = self.rset.column_types(0)
   188             restrtypes = self.cw_rset.column_types(0)
   189         else:
   189         else:
   190             rqlst = parse(restrrql)
   190             rqlst = parse(restrrql)
   191         html = []
   191         html = []
   192         on_etype = False
   192         on_etype = False
   193         etypes = sorted((display_name(self.req, etype).capitalize(), etype)
   193         etypes = sorted((display_name(self._cw, etype).capitalize(), etype)
   194                         for etype in restrtypes)
   194                         for etype in restrtypes)
   195         for elabel, etype in etypes:
   195         for elabel, etype in etypes:
   196             if etype == restrtype:
   196             if etype == restrtype:
   197                 html.append(u'<span class="selected">%s</span>' % elabel)
   197                 html.append(u'<span class="selected">%s</span>' % elabel)
   198                 on_etype = True
   198                 on_etype = True
   199             else:
   199             else:
   200                 rqlst.save_state()
   200                 rqlst.save_state()
   201                 for select in rqlst.children:
   201                 for select in rqlst.children:
   202                     select.add_type_restriction(select.selection[0], etype)
   202                     select.add_type_restriction(select.selection[0], etype)
   203                 newrql = rqlst.as_string(self.req.encoding, self.rset.args)
   203                 newrql = rqlst.as_string(self._cw.encoding, self.cw_rset.args)
   204                 url = self.build_url(rql=newrql, __restrrql=restrrql,
   204                 url = self._cw.build_url(rql=newrql, __restrrql=restrrql,
   205                                      __restrtype=etype, __restrtypes=','.join(restrtypes))
   205                                          __restrtype=etype, __restrtypes=','.join(restrtypes))
   206                 html.append(u'<span><a href="%s">%s</a></span>' % (
   206                 html.append(u'<span><a href="%s">%s</a></span>' % (
   207                         xml_escape(url), elabel))
   207                         xml_escape(url), elabel))
   208                 rqlst.recover()
   208                 rqlst.recover()
   209         if on_etype:
   209         if on_etype:
   210             url = self.build_url(rql=restrrql)
   210             url = self._cw.build_url(rql=restrrql)
   211             html.insert(0, u'<span><a href="%s">%s</a></span>' % (
   211             html.insert(0, u'<span><a href="%s">%s</a></span>' % (
   212                     url, _('Any')))
   212                     url, _('Any')))
   213         else:
   213         else:
   214             html.insert(0, u'<span class="selected">%s</span>' % _('Any'))
   214             html.insert(0, u'<span class="selected">%s</span>' % _('Any'))
   215         self.w(u'&#160;|&#160;'.join(html))
   215         self.w(u'&#160;|&#160;'.join(html))
   227 
   227 
   228     def call(self, vid):
   228     def call(self, vid):
   229         entity = self.entity(0,0)
   229         entity = self.entity(0,0)
   230         url = entity.absolute_url(vid=vid, __template='pdf-main-template')
   230         url = entity.absolute_url(vid=vid, __template='pdf-main-template')
   231         self.w(u'<a href="%s" class="otherView"><img src="data/pdf_icon.gif" alt="%s"/></a>' %
   231         self.w(u'<a href="%s" class="otherView"><img src="data/pdf_icon.gif" alt="%s"/></a>' %
   232                (xml_escape(url), self.req._('download page as pdf')))
   232                (xml_escape(url), self._cw._('download page as pdf')))
   233 
   233 
   234 
   234 
   235 
   235 
   236 def registration_callback(vreg):
   236 def registration_callback(vreg):
   237     vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,))
   237     vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,))