1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
20 __docformat__ = "restructuredtext en" |
20 __docformat__ = "restructuredtext en" |
21 _ = unicode |
21 _ = unicode |
22 |
22 |
23 from logilab.mtconverter import xml_escape |
23 from logilab.mtconverter import xml_escape |
24 |
24 |
25 from cubicweb.selectors import nonempty_rset, match_form_params |
25 from cubicweb.selectors import nonempty_rset |
26 from cubicweb.utils import make_uid, json_dumps |
26 from cubicweb.utils import make_uid, json_dumps |
27 from cubicweb.view import EntityView, AnyRsetView |
27 from cubicweb.view import EntityView, AnyRsetView |
28 from cubicweb import tags |
28 from cubicweb import tags |
29 from cubicweb.uilib import toggle_action, limitsize, htmlescape |
29 from cubicweb.uilib import toggle_action, limitsize, htmlescape |
30 from cubicweb.web import jsonize |
30 from cubicweb.web import jsonize |
31 from cubicweb.web.component import Link |
31 from cubicweb.web.component import Link |
32 from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
32 from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
33 PopupBoxMenu) |
33 PopupBoxMenu) |
|
34 from cubicweb.web import facet |
34 from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens |
35 from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens |
35 |
36 |
36 class TableView(AnyRsetView): |
37 class TableView(AnyRsetView): |
37 """The table view accepts any non-empty rset. It uses |
38 """The table view accepts any non-empty rset. It uses |
38 introspection on the result set to compute column names and the |
39 introspection on the result set to compute column names and the |
40 It is however highly configurable and accepts a wealth of options. |
41 It is however highly configurable and accepts a wealth of options. |
41 """ |
42 """ |
42 __regid__ = 'table' |
43 __regid__ = 'table' |
43 title = _('table') |
44 title = _('table') |
44 finalview = 'final' |
45 finalview = 'final' |
|
46 wdg_stack_size = 8 |
45 |
47 |
46 def form_filter(self, divid, displaycols, displayactions, displayfilter, |
48 def form_filter(self, divid, displaycols, displayactions, displayfilter, |
47 paginate, hidden=True): |
49 paginate, hidden=True): |
48 rqlst = self.cw_rset.syntax_tree() |
50 rqlst = self.cw_rset.syntax_tree() |
49 # union not yet supported |
51 # union not yet supported |
79 w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or '')) |
81 w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or '')) |
80 w(u'<input type="hidden" name="divid" value="%s" />' % divid) |
82 w(u'<input type="hidden" name="divid" value="%s" />' % divid) |
81 w(u'<input type="hidden" name="fromformfilter" value="1" />') |
83 w(u'<input type="hidden" name="fromformfilter" value="1" />') |
82 filter_hiddens(w, facets=','.join(wdg.facet.__regid__ for wdg in fwidgets), |
84 filter_hiddens(w, facets=','.join(wdg.facet.__regid__ for wdg in fwidgets), |
83 baserql=baserql) |
85 baserql=baserql) |
|
86 # sort by vocab size |
|
87 fwidgets.sort(key=lambda x: x.height()) |
84 w(u'<table class="filter">\n') |
88 w(u'<table class="filter">\n') |
|
89 widget_queue = [] |
|
90 queue_size = 0 |
|
91 widget_qty = len(fwidgets) |
85 w(u'<tr>\n') |
92 w(u'<tr>\n') |
86 for wdg in fwidgets: |
93 for wdg in fwidgets: |
|
94 height = wdg.height() |
|
95 if queue_size + height <= self.wdg_stack_size: |
|
96 widget_queue.append(wdg) |
|
97 queue_size += height |
|
98 continue |
87 w(u'<td>') |
99 w(u'<td>') |
88 wdg.render(w=w) |
100 for queued in widget_queue: |
89 w(u'</td>\n') |
101 queued.render(w=w) |
|
102 w(u'</td>') |
|
103 widget_queue = [wdg] |
|
104 queue_size = height |
|
105 if widget_queue: |
|
106 w(u'<td>') |
|
107 for queued in widget_queue: |
|
108 queued.render(w=w) |
|
109 w(u'</td>') |
90 w(u'</tr>\n') |
110 w(u'</tr>\n') |
91 w(u'</table>\n') |
111 w(u'</table>\n') |
92 w(u'</fieldset>\n') |
112 w(u'</fieldset>\n') |
93 w(u'</form>\n') |
113 w(u'</form>\n') |
94 |
114 |