web/views/tabs.py
author Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
Thu, 26 Nov 2015 11:30:54 +0100
changeset 10935 049209b9e9d6
parent 10666 7f6b5f023884
permissions -rw-r--r--
[qunit] stop dealing with filesystem paths qunit tests need a few things served by cubicweb: - qunit itself, which is now handled by CWDevtoolsStaticController (serving files in cubicweb/devtools/data) - standard cubicweb or cubes data files, handled by the DataController - the tests themselves and their dependencies. These can live in <apphome>/data or <apphome>/static and be served by one of the STATIC_CONTROLLERS This avoids having to guess in CWSoftwareRootStaticController where to serve things from (some files may be installed, others are in the source tree), and should hopefully make it possible to have these tests pass when using tox, and to write qunit tests for cubes, outside of cubicweb itself. This requires modifying the tests to only declare URL paths instead of filesystem paths, and moving support files below test/data/static.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8512
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
     1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5370
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6466
43d71dd8a8ec cleanup and 3.10 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6193
diff changeset
    18
"""base classes to handle tabbed views"""
235
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
    19
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
    20
__docformat__ = "restructuredtext en"
10666
7f6b5f023884 [py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10612
diff changeset
    21
from cubicweb import _
235
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
    22
10612
84468b90e9c1 [py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9388
diff changeset
    23
from six import string_types
84468b90e9c1 [py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9388
diff changeset
    24
4602
fe5aad04f08b proper deprecation of TabedPrimaryView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4601
diff changeset
    25
from logilab.common.deprecation import class_renamed
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2264
diff changeset
    26
from logilab.mtconverter import xml_escape
214
aaf2957bf69e tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    27
235
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
    28
from cubicweb import NoSelectableObject, role
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    29
from cubicweb import tags, uilib, utils
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8103
diff changeset
    30
from cubicweb.predicates import partial_has_related_entities
981
d86d1ee3b60e fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents: 940
diff changeset
    31
from cubicweb.view import EntityView
3570
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
    32
from cubicweb.web.views import primary
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    33
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    34
class LazyViewMixin(object):
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    35
    """provides two convenience methods for the tab machinery.
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    36
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    37
    Can also be used to lazy-load arbitrary views.
510
6b92504d77c1 [tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 504
diff changeset
    38
    """
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    39
559
7cfd3d11edc8 [tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 547
diff changeset
    40
    def _prepare_bindings(self, vid, reloadable):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
    41
        self._cw.add_onload(u"""
559
7cfd3d11edc8 [tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 547
diff changeset
    42
  jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) {
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    43
     loadNow('#lazy-%(vid)s', '#%(vid)s-hole', %(reloadable)s);
559
7cfd3d11edc8 [tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 547
diff changeset
    44
  });""" % {'event': 'load_%s' % vid, 'vid': vid,
7cfd3d11edc8 [tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 547
diff changeset
    45
            'reloadable' : str(reloadable).lower()})
7cfd3d11edc8 [tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 547
diff changeset
    46
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
    47
    def lazyview(self, vid, rql=None, eid=None, rset=None, tabid=None,
1000
90705536b7c8 [tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 999
diff changeset
    48
                 reloadable=False, show_spinbox=True, w=None):
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    49
        """a lazy version of wview"""
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    50
        w = w or self.w
7253
68b9e21efa63 [js] delete empty js files (incluced in cw.ajax.js)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7233
diff changeset
    51
        self._cw.add_js('cubicweb.ajax.js')
8442
202625f247b4 [views/tabs] fix rql/eid param conflict when either one is already in the request form (closes #2405249)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8237
diff changeset
    52
        # the form is copied into urlparams to please the inner views
202625f247b4 [views/tabs] fix rql/eid param conflict when either one is already in the request form (closes #2405249)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8237
diff changeset
    53
        # that might want to take params from it
202625f247b4 [views/tabs] fix rql/eid param conflict when either one is already in the request form (closes #2405249)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8237
diff changeset
    54
        # beware of already present rql or eid elements
202625f247b4 [views/tabs] fix rql/eid param conflict when either one is already in the request form (closes #2405249)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8237
diff changeset
    55
        # to be safe of collision a proper argument passing protocol
202625f247b4 [views/tabs] fix rql/eid param conflict when either one is already in the request form (closes #2405249)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8237
diff changeset
    56
        # (with namespaces) should be used instead of the current
202625f247b4 [views/tabs] fix rql/eid param conflict when either one is already in the request form (closes #2405249)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8237
diff changeset
    57
        # ad-hockery
7067
f239da8e7c39 [tabs] forward url parameters to lazy tabs views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6582
diff changeset
    58
        urlparams = self._cw.form.copy()
8442
202625f247b4 [views/tabs] fix rql/eid param conflict when either one is already in the request form (closes #2405249)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8237
diff changeset
    59
        urlparams.pop('rql', None)
202625f247b4 [views/tabs] fix rql/eid param conflict when either one is already in the request form (closes #2405249)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8237
diff changeset
    60
        urlparams.pop('eid', None)
7067
f239da8e7c39 [tabs] forward url parameters to lazy tabs views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6582
diff changeset
    61
        urlparams.update({'vid' : vid, 'fname' : 'view'})
1000
90705536b7c8 [tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 999
diff changeset
    62
        if rql:
90705536b7c8 [tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 999
diff changeset
    63
            urlparams['rql'] = rql
90705536b7c8 [tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 999
diff changeset
    64
        elif eid:
8237
f854cf9b089e [tabs] use eid parameter instead of rql when an eid is given. Closes #2186288
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8216
diff changeset
    65
            urlparams['eid'] = eid
1000
90705536b7c8 [tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 999
diff changeset
    66
        elif rset:
90705536b7c8 [tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 999
diff changeset
    67
            urlparams['rql'] = rset.printable_rql()
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
    68
        if tabid is None:
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
    69
            tabid = uilib.domid(vid)
543
c0f2b6378f70 simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 542
diff changeset
    70
        w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % (
8728
75be9de9d68e [web] Use the new '/ajax' URL path to access the AjaxController (closes #2758254)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8531
diff changeset
    71
            tabid, xml_escape(self._cw.build_url('ajax', **urlparams))))
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    72
        if show_spinbox:
8095
5ad0f8ac7561 [web/views/tabs] improve non graphical experince with tabs (closes #2097405)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 7879
diff changeset
    73
            # Don't use ``alt`` since image is a *visual* helper for ajax
8191
eceaf9e21966 [js] better support for no js in tabs (closes #2162092)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8103
diff changeset
    74
            w(u'<img style="display: none" src="%s" alt="" id="%s-hole"/>'
8095
5ad0f8ac7561 [web/views/tabs] improve non graphical experince with tabs (closes #2097405)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 7879
diff changeset
    75
              % (xml_escape(self._cw.data_url('loading.gif')), tabid))
5370
dc6f3247bfc2 [lazy view] give it a proper hole node in the no spinbox case
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5151
diff changeset
    76
        else:
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
    77
            w(u'<div id="%s-hole"></div>' % tabid)
8191
eceaf9e21966 [js] better support for no js in tabs (closes #2162092)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8103
diff changeset
    78
        w(u'<noscript><p>%s <a id="seo-%s" href="%s">%s</a></p></noscript>'
8095
5ad0f8ac7561 [web/views/tabs] improve non graphical experince with tabs (closes #2097405)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 7879
diff changeset
    79
          % (xml_escape(self._cw._('Link:')),
5ad0f8ac7561 [web/views/tabs] improve non graphical experince with tabs (closes #2097405)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 7879
diff changeset
    80
             tabid,
5ad0f8ac7561 [web/views/tabs] improve non graphical experince with tabs (closes #2097405)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 7879
diff changeset
    81
             xml_escape(self._cw.build_url(**urlparams)),
5ad0f8ac7561 [web/views/tabs] improve non graphical experince with tabs (closes #2097405)
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 7879
diff changeset
    82
             xml_escape(self._cw._(tabid))))
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    83
        w(u'</div>')
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
    84
        self._prepare_bindings(tabid, reloadable)
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    85
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    86
    def forceview(self, vid):
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    87
        """trigger an event that will force immediate loading of the view on dom
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    88
        readyness
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    89
        """
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    90
        self._cw.add_onload(uilib.js.triggerLoad(vid))
543
c0f2b6378f70 simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 542
diff changeset
    91
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    92
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    93
class TabsMixin(LazyViewMixin):
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    94
    """a tab mixin to easily get jQuery based, lazy, ajax tabs"""
8512
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
    95
    lazy = True
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
    96
606
40c7c2cf0797 [tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 559
diff changeset
    97
    @property
40c7c2cf0797 [tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 559
diff changeset
    98
    def cookie_name(self):
4085
002ba2a3bb13 api update again
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
    99
        return str('%s_active_tab' % self._cw.vreg.config.appid)
606
40c7c2cf0797 [tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 559
diff changeset
   100
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   101
    def active_tab(self, default):
3589
a5432f99f2d9 backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460 3576
diff changeset
   102
        if 'tab' in self._cw.form:
a5432f99f2d9 backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460 3576
diff changeset
   103
            return self._cw.form['tab']
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   104
        cookies = self._cw.get_cookie()
606
40c7c2cf0797 [tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 559
diff changeset
   105
        cookiename = self.cookie_name
1000
90705536b7c8 [tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 999
diff changeset
   106
        activetab = cookies.get(cookiename)
235
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
   107
        if activetab is None:
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   108
            domid = uilib.domid(default)
7855
54283a5b7afc [web request] fix cookie 'expires' formating (closes #1953945)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7820
diff changeset
   109
            self._cw.set_cookie(cookiename, domid)
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   110
            return domid
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   111
        return activetab.value
214
aaf2957bf69e tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   112
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   113
    def prune_tabs(self, tabs, default_tab):
490
b84d64db2350 [tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 489
diff changeset
   114
        selected_tabs = []
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   115
        may_be_active_tab = self.active_tab(default_tab)
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   116
        active_tab = uilib.domid(default_tab)
3589
a5432f99f2d9 backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460 3576
diff changeset
   117
        viewsvreg = self._cw.vreg['views']
490
b84d64db2350 [tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 489
diff changeset
   118
        for tab in tabs:
10612
84468b90e9c1 [py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9388
diff changeset
   119
            if isinstance(tab, string_types):
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   120
                tabid, tabkwargs = tab, {}
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   121
            else:
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   122
                tabid, tabkwargs = tab
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   123
                tabkwargs = tabkwargs.copy()
8526
ed0fbbf507bb [ui tabs] avoid duplicate rset argument if already specified in tab kwargs. Closes #2464786
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8512
diff changeset
   124
            tabkwargs.setdefault('rset', self.cw_rset)
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   125
            vid = tabkwargs.get('vid', tabid)
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   126
            domid = uilib.domid(tabid)
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   127
            try:
8526
ed0fbbf507bb [ui tabs] avoid duplicate rset argument if already specified in tab kwargs. Closes #2464786
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8512
diff changeset
   128
                viewsvreg.select(vid, self._cw, tabid=domid, **tabkwargs)
490
b84d64db2350 [tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 489
diff changeset
   129
            except NoSelectableObject:
b84d64db2350 [tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 489
diff changeset
   130
                continue
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   131
            selected_tabs.append((tabid, domid, tabkwargs))
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   132
            if domid == may_be_active_tab:
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   133
                active_tab = domid
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   134
        return selected_tabs, active_tab
490
b84d64db2350 [tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 489
diff changeset
   135
1997
554eb4dd533d [views] get tabs to work with startup views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   136
    def render_tabs(self, tabs, default, entity=None):
2264
17b8a6ad58fc cleanup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2258
diff changeset
   137
        # delegate to the default tab if there is more than one entity
17b8a6ad58fc cleanup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2258
diff changeset
   138
        # in the result set (tabs are pretty useless there)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   139
        if entity and len(self.cw_rset) > 1:
1379
6c6dbc0df829 MUST NOT consider req.form['rql'] in a view, use len(rset) > 1 to detect if we can apply tabs or not
sylvain.thenault@logilab.fr
parents: 1112
diff changeset
   140
            entity.view(default, w=self.w)
6c6dbc0df829 MUST NOT consider req.form['rql'] in a view, use len(rset) > 1 to detect if we can apply tabs or not
sylvain.thenault@logilab.fr
parents: 1112
diff changeset
   141
            return
7233
614f23606091 [js/css] remove old versions of ui.tabs/slider etc.; closes #1625085
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7070
diff changeset
   142
        self._cw.add_css('jquery.ui.css')
7820
2c73fc529a20 [tabs] do not use an ajax call to set cookie value, use jquery.cookie helper instead (closes #1944522)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7819
diff changeset
   143
        self._cw.add_js(('jquery.ui.js', 'cubicweb.ajax.js', 'jquery.cookie.js'))
490
b84d64db2350 [tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 489
diff changeset
   144
        # prune tabs : not all are to be shown
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   145
        tabs, active_tab = self.prune_tabs(tabs, default)
214
aaf2957bf69e tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   146
        # build the html structure
235
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
   147
        w = self.w
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   148
        uid = entity and entity.eid or utils.make_uid('tab')
2386
b246d5cee44e [tabs] backport entity-less support for tabs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2383
diff changeset
   149
        w(u'<div id="entity-tabs-%s">' % uid)
2673
9e639925ca2f Backed out changeset 3e1d2ab5f8c0 (restore ui.tabs.js instead of jquery tools)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2123
diff changeset
   150
        w(u'<ul>')
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   151
        active_tab_idx = None
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   152
        for i, (tabid, domid, tabkwargs) in enumerate(tabs):
235
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
   153
            w(u'<li>')
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   154
            w(u'<a href="#%s">' % domid)
3589
a5432f99f2d9 backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460 3576
diff changeset
   155
            w(tabkwargs.pop('label', self._cw._(tabid)))
235
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
   156
            w(u'</a>')
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
   157
            w(u'</li>')
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   158
            if domid == active_tab:
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   159
                active_tab_idx = i
235
b43362d92a1d rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 220
diff changeset
   160
        w(u'</ul>')
6083
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   161
        for tabid, domid, tabkwargs in tabs:
8d69ef5f086a [tabs] take care, vid may not be a valid dom id (for jQuery at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   162
            w(u'<div id="%s">' % domid)
8512
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
   163
            if self.lazy:
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
   164
                tabkwargs.setdefault('tabid', domid)
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
   165
                tabkwargs.setdefault('vid', tabid)
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
   166
                self.lazyview(**tabkwargs)
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
   167
            else:
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
   168
                self._cw.view(tabid, w=self.w, **tabkwargs)
485
0f830732be19 [tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 235
diff changeset
   169
            w(u'</div>')
7233
614f23606091 [js/css] remove old versions of ui.tabs/slider etc.; closes #1625085
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7070
diff changeset
   170
        w(u'</div>')
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   171
        # call the setTab() JS function *after* each tab is generated
543
c0f2b6378f70 simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 542
diff changeset
   172
        # because the callback binding needs to be done before
2383
96780c1e0c53 shrink a bit the tabs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2381
diff changeset
   173
        # XXX make work history: true
8512
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
   174
        if self.lazy:
5161573ba806 [tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8442
diff changeset
   175
            self._cw.add_onload(u"""
8531
e150b4bcbfaa [tabs] fix pb with non-lazy tabs: style isn't properly set due to missing jquery.ui activation. Closes #2465657
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8526
diff changeset
   176
  jQuery('#entity-tabs-%(uid)s').tabs(
9388
4c34a63bd113 update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8728
diff changeset
   177
    { active: %(tabindex)s,
4c34a63bd113 update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8728
diff changeset
   178
      activate: function(event, ui) {
4c34a63bd113 update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8728
diff changeset
   179
        setTab(ui.newPanel.attr('id'), '%(cookiename)s');
7819
93d9a9c29bfb [tabs] fix clic on tab that does nothing (closes #1942750)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7742
diff changeset
   180
      }
93d9a9c29bfb [tabs] fix clic on tab that does nothing (closes #1942750)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7742
diff changeset
   181
    });
6952
7de13eb473e3 [tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   182
  setTab('%(domid)s', '%(cookiename)s');
3569
89a60802711b [tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3209
diff changeset
   183
""" % {'tabindex'   : active_tab_idx,
8531
e150b4bcbfaa [tabs] fix pb with non-lazy tabs: style isn't properly set due to missing jquery.ui activation. Closes #2465657
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8526
diff changeset
   184
       'domid'      : active_tab,
e150b4bcbfaa [tabs] fix pb with non-lazy tabs: style isn't properly set due to missing jquery.ui activation. Closes #2465657
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8526
diff changeset
   185
       'uid'        : uid,
2674
ff6114c2c416 merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2386 2673
diff changeset
   186
       'cookiename' : self.cookie_name})
8531
e150b4bcbfaa [tabs] fix pb with non-lazy tabs: style isn't properly set due to missing jquery.ui activation. Closes #2465657
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8526
diff changeset
   187
        else:
e150b4bcbfaa [tabs] fix pb with non-lazy tabs: style isn't properly set due to missing jquery.ui activation. Closes #2465657
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8526
diff changeset
   188
            self._cw.add_onload(
9388
4c34a63bd113 update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8728
diff changeset
   189
                u"jQuery('#entity-tabs-%(uid)s').tabs({active: %(tabindex)s});"
8531
e150b4bcbfaa [tabs] fix pb with non-lazy tabs: style isn't properly set due to missing jquery.ui activation. Closes #2465657
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8526
diff changeset
   190
                % {'tabindex': active_tab_idx, 'uid': uid})
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   191
3026
17644247f0ff fix emacs syntaxic colorization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2675
diff changeset
   192
982
ba5257deec7d rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents: 981
diff changeset
   193
class EntityRelationView(EntityView):
ba5257deec7d rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents: 981
diff changeset
   194
    """view displaying entity related stuff.
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   195
    Such a view _must_ provide the rtype, target and vid attributes :
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   196
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   197
    Example :
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   198
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   199
    class ProjectScreenshotsView(EntityRelationView):
542
46d4ff5aa917 use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 522
diff changeset
   200
        '''display project's screenshots'''
3408
c92170fca813 [api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3230
diff changeset
   201
        __regid__ = title = _('projectscreenshots')
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   202
        __select__ = EntityRelationView.__select__ & is_instance('Project')
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   203
        rtype = 'screenshot'
982
ba5257deec7d rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents: 981
diff changeset
   204
        role = 'subject'
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   205
        vid = 'gallery'
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   206
3209
c2c8f88a4520 allow user to give ?tab=tabname and be set to the right tab (part of #345399)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3026
diff changeset
   207
    in this example, entities related to project entity by the 'screenshot'
982
ba5257deec7d rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents: 981
diff changeset
   208
    relation (where the project is subject of the relation) will be displayed
ba5257deec7d rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents: 981
diff changeset
   209
    using the 'gallery' view.
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   210
    """
838
f2c56312b03a rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 782
diff changeset
   211
    __select__ = EntityView.__select__ & partial_has_related_entities()
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   212
    vid = 'list'
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7855
diff changeset
   213
    # to be defined in concrete classes
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7855
diff changeset
   214
    rtype = title = None
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1498
diff changeset
   215
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   216
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   217
        rset = self.cw_rset.get_entity(row, col).related(self.rtype, role(self))
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   218
        self.w(u'<div class="mainInfo">')
982
ba5257deec7d rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents: 981
diff changeset
   219
        if self.title:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   220
            self.w(tags.h1(self._cw._(self.title)))
489
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   221
        self.wview(self.vid, rset, 'noresult')
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 487
diff changeset
   222
        self.w(u'</div>')
3570
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   223
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   224
3929
9f314411cd04 [web] rename TabedPrimary to TabbedPrimary with backward compat
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3849
diff changeset
   225
class TabbedPrimaryView(TabsMixin, primary.PrimaryView):
3570
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   226
    __abstract__ = True # don't register
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   227
6472
6e058f937126 i18n tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6466
diff changeset
   228
    tabs = [_('main_tab')]
3570
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   229
    default_tab = 'main_tab'
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   230
8531
e150b4bcbfaa [tabs] fix pb with non-lazy tabs: style isn't properly set due to missing jquery.ui activation. Closes #2465657
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8526
diff changeset
   231
    def render_entity(self, entity):
4601
0f65c40b56b5 missing call to toolbox in tabbed primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   232
        self.render_entity_toolbox(entity)
6193
a58097ee4f15 [views] do not underline h1 titles for tabbedprimary views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6083
diff changeset
   233
        self.w(u'<div class="tabbedprimary"></div>')
3570
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   234
        self.render_entity_title(entity)
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   235
        self.render_tabs(self.tabs, self.default_tab, entity)
4602
fe5aad04f08b proper deprecation of TabedPrimaryView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4601
diff changeset
   236
fe5aad04f08b proper deprecation of TabedPrimaryView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4601
diff changeset
   237
TabedPrimaryView = class_renamed('TabedPrimaryView', TabbedPrimaryView)
3570
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   238
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   239
class PrimaryTab(primary.PrimaryView):
3645
7272b793d7c9 3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589
diff changeset
   240
    __regid__ = 'main_tab'
6472
6e058f937126 i18n tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6466
diff changeset
   241
    title = None # should not appear in possible views
3570
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   242
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   243
    def is_primary(self):
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   244
        return True
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   245
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   246
    def render_entity_title(self, entity):
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   247
        pass
3845
596044fb7bc5 introduce render_entity_toolbox on default primary view to display components in the ctxtoolbar context, such as pdf icon, notification registration (nosylist)...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3844
diff changeset
   248
    def render_entity_toolbox(self, entity):
3570
c31de6ea6984 [tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3569
diff changeset
   249
        pass