22 |
22 |
23 from logilab.mtconverter import xml_escape |
23 from logilab.mtconverter import xml_escape |
24 |
24 |
25 from cubicweb import NoSelectableObject, tags |
25 from cubicweb import NoSelectableObject, tags |
26 from cubicweb.selectors import nonempty_rset |
26 from cubicweb.selectors import nonempty_rset |
27 from cubicweb.utils import make_uid, json_dumps |
27 from cubicweb.utils import make_uid, js_dumps, JSString |
28 from cubicweb.view import EntityView, AnyRsetView |
28 from cubicweb.view import EntityView, AnyRsetView |
29 from cubicweb.uilib import toggle_action, limitsize, htmlescape |
29 from cubicweb.uilib import toggle_action, limitsize, htmlescape |
30 from cubicweb.web import jsonize, component, facet |
30 from cubicweb.web import jsonize, component, facet |
31 from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
31 from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
32 PopupBoxMenu) |
32 PopupBoxMenu) |
42 title = _('table') |
42 title = _('table') |
43 finalview = 'final' |
43 finalview = 'final' |
44 |
44 |
45 table_widget_class = TableWidget |
45 table_widget_class = TableWidget |
46 table_column_class = TableColumn |
46 table_column_class = TableColumn |
|
47 |
|
48 tablesorter_settings = { |
|
49 'textExtraction': JSString('cw.sortValueExtraction'), |
|
50 'selectorHeaders: "thead tr:first th"' # only plug on the first row |
|
51 } |
47 |
52 |
48 def form_filter(self, divid, displaycols, displayactions, displayfilter, |
53 def form_filter(self, divid, displaycols, displayactions, displayfilter, |
49 paginate, hidden=True): |
54 paginate, hidden=True): |
50 try: |
55 try: |
51 filterform = self._cw.vreg['views'].select( |
56 filterform = self._cw.vreg['views'].select( |
82 displaycols = range(len(headers)) |
87 displaycols = range(len(headers)) |
83 else: |
88 else: |
84 displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection)) |
89 displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection)) |
85 return displaycols |
90 return displaycols |
86 |
91 |
|
92 def _setup_tablesorter(self, divid): |
|
93 req = self._cw |
|
94 req.add_js('jquery.tablesorter.js') |
|
95 req.add_onload('''$(document).ready(function() { |
|
96 $("#%s table.listing").tablesorter(%s); |
|
97 });''' % (divid, js_dumps(self.tablesorter_settings))) |
|
98 req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css')) |
|
99 |
|
100 |
87 def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
101 def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
88 displaycols=None, displayactions=None, actions=(), divid=None, |
102 displaycols=None, displayactions=None, actions=(), divid=None, |
89 cellvids=None, cellattrs=None, mainindex=None, |
103 cellvids=None, cellattrs=None, mainindex=None, |
90 paginate=False, page_size=None): |
104 paginate=False, page_size=None): |
91 """Produces a table displaying a composite query |
105 """Produces a table displaying a composite query |
96 :param headers: columns' titles |
110 :param headers: columns' titles |
97 :param displaycols: indexes of columns to display (first column is 0) |
111 :param displaycols: indexes of columns to display (first column is 0) |
98 :param displayactions: if True, display action menu |
112 :param displayactions: if True, display action menu |
99 """ |
113 """ |
100 req = self._cw |
114 req = self._cw |
101 req.add_js('jquery.tablesorter.js') |
115 divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset)) |
102 req.add_onload('jQuery("table.listing").tablesorter({' |
116 self._setup_tablesorter(divid) |
103 'textExtraction: cubicwebSortValueExtraction,' # use our own function |
|
104 'selectorHeaders: "thead tr:first th"' # only plug on the first row |
|
105 '});') |
|
106 req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css')) |
|
107 # compute label first since the filter form may remove some necessary |
117 # compute label first since the filter form may remove some necessary |
108 # information from the rql syntax tree |
118 # information from the rql syntax tree |
109 if mainindex is None: |
119 if mainindex is None: |
110 mainindex = self.main_var_index() |
120 mainindex = self.main_var_index() |
111 computed_labels = self.columns_labels(mainindex) |
121 computed_labels = self.columns_labels(mainindex) |
112 hidden = True |
122 hidden = True |
113 if not subvid and 'subvid' in req.form: |
123 if not subvid and 'subvid' in req.form: |
114 subvid = req.form.pop('subvid') |
124 subvid = req.form.pop('subvid') |
115 divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset)) |
|
116 actions = list(actions) |
125 actions = list(actions) |
117 if mainindex is None: |
126 if mainindex is None: |
118 displayfilter, displayactions = False, False |
127 displayfilter, displayactions = False, False |
119 else: |
128 else: |
120 if displayfilter is None and req.form.get('displayfilter'): |
129 if displayfilter is None and req.form.get('displayfilter'): |