21 from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
21 from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
22 PopupBoxMenu, BoxLink) |
22 PopupBoxMenu, BoxLink) |
23 from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens |
23 from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens |
24 |
24 |
25 class TableView(AnyRsetView): |
25 class TableView(AnyRsetView): |
|
26 """The table view accepts any non-empty rset. It uses |
|
27 introspection on the result set to compute column names and the |
|
28 proper way to display the cells. |
|
29 It is however highly configurable and accepts a wealth of options. |
|
30 """ |
26 __regid__ = 'table' |
31 __regid__ = 'table' |
27 title = _('table') |
32 title = _('table') |
28 finalview = 'final' |
33 finalview = 'final' |
29 |
34 |
30 def form_filter(self, divid, displaycols, displayactions, displayfilter, |
35 def form_filter(self, divid, displaycols, displayactions, displayfilter, |
48 return self.show_hide_actions(divid, not hidden) |
53 return self.show_hide_actions(divid, not hidden) |
49 return () |
54 return () |
50 |
55 |
51 def _generate_form(self, divid, baserql, fwidgets, hidden=True, vidargs={}): |
56 def _generate_form(self, divid, baserql, fwidgets, hidden=True, vidargs={}): |
52 """display a form to filter table's content. This should only |
57 """display a form to filter table's content. This should only |
53 occurs when a context eid is given |
58 occur when a context eid is given |
54 """ |
59 """ |
|
60 w = self.w |
55 self._cw.add_css('cubicweb.facets.css') |
61 self._cw.add_css('cubicweb.facets.css') |
56 self._cw.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js')) |
62 self._cw.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js')) |
57 # drop False / None values from vidargs |
63 # drop False / None values from vidargs |
58 vidargs = dict((k, v) for k, v in vidargs.iteritems() if v) |
64 vidargs = dict((k, v) for k, v in vidargs.iteritems() if v) |
59 self.w(u'<form method="post" cubicweb:facetargs="%s" action="">' % |
65 w(u'<form method="post" cubicweb:facetargs="%s" action="">' % |
60 xml_escape(dumps([divid, 'table', False, vidargs]))) |
66 xml_escape(dumps([divid, 'table', False, vidargs]))) |
61 self.w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or '')) |
67 w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or '')) |
62 self.w(u'<input type="hidden" name="divid" value="%s" />' % divid) |
68 w(u'<input type="hidden" name="divid" value="%s" />' % divid) |
63 self.w(u'<input type="hidden" name="fromformfilter" value="1" />') |
69 w(u'<input type="hidden" name="fromformfilter" value="1" />') |
64 filter_hiddens(self.w, facets=','.join(wdg.facet.__regid__ for wdg in fwidgets), |
70 filter_hiddens(w, facets=','.join(wdg.facet.__regid__ for wdg in fwidgets), |
65 baserql=baserql) |
71 baserql=baserql) |
66 self.w(u'<table class="filter">\n') |
72 w(u'<table class="filter">\n') |
67 self.w(u'<tr>\n') |
73 w(u'<tr>\n') |
68 for wdg in fwidgets: |
74 for wdg in fwidgets: |
69 self.w(u'<td>') |
75 w(u'<td>') |
70 wdg.render(w=self.w) |
76 wdg.render(w=w) |
71 self.w(u'</td>\n') |
77 w(u'</td>\n') |
72 self.w(u'</tr>\n') |
78 w(u'</tr>\n') |
73 self.w(u'</table>\n') |
79 w(u'</table>\n') |
74 self.w(u'</fieldset>\n') |
80 w(u'</fieldset>\n') |
75 self.w(u'</form>\n') |
81 w(u'</form>\n') |
76 |
82 |
77 def main_var_index(self): |
83 def main_var_index(self): |
78 """returns the index of the first non-attribute variable among the RQL |
84 """returns the index of the first non-attribute variable among the RQL |
79 selected variables |
85 selected variables |
80 """ |
86 """ |
96 return displaycols |
102 return displaycols |
97 |
103 |
98 def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
104 def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
99 displaycols=None, displayactions=None, actions=(), divid=None, |
105 displaycols=None, displayactions=None, actions=(), divid=None, |
100 cellvids=None, cellattrs=None, mainindex=None): |
106 cellvids=None, cellattrs=None, mainindex=None): |
101 """Dumps a table displaying a composite query |
107 """Produces a table displaying a composite query |
102 |
108 |
103 :param title: title added before table |
109 :param title: title added before table |
104 :param subvid: cell view |
110 :param subvid: cell view |
105 :param displayfilter: filter that selects rows to display |
111 :param displayfilter: filter that selects rows to display |
106 :param headers: columns' titles |
112 :param headers: columns' titles |