Author: eallen
Date: 2009-06-09 16:22:39 -0400 (Tue, 09 Jun 2009)
New Revision: 3438
Modified:
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/cumin/python/cumin/widgets.strings
Log:
Create a ClientTruncateColumn class and styles to automatically truncate long columns.
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2009-06-09 20:20:29 UTC (rev 3437)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2009-06-09 20:22:39 UTC (rev 3438)
@@ -707,17 +707,51 @@
return fmt_link("", title, class_, link_title=hover, bm=bm,
click=click)
+class ClientTruncateColumn(SqlTableColumn):
+ def __init__(self, app, name):
+ super(ClientTruncateColumn, self).__init__(app, name)
+
+ self.col_percent = 33
+
+ def get_class_list(self, session):
+ cls = super(ClientTruncateColumn, self).get_class_list(session)
+ cls.append("truncate")
+ return cls
+
+ def get_class_attr(self, session):
+ cls = super(ClientTruncateColumn, self).get_class_attr(session)
+ return "width=\"%i%%\" %s" % (self.col_percent, cls)
+
class TopTableColumn(SqlTableColumn):
def __init__(self, app, name):
super(TopTableColumn, self).__init__(app, name)
self.header_class = TopTableColumnHeader
+class TopTableCountColumn(TopTableColumn):
+ def get_class_list(self, session):
+ cls = super(TopTableCountColumn, self).get_class_list(session)
+ cls.append("top_count")
+ return cls
+
class TopTableColumnHeader(ItemTableColumnHeader):
pass
-class TopTable(SqlTable, FullPageNotify):
+class TopClientTruncateColumn(ClientTruncateColumn):
def __init__(self, app, name):
+ super(TopClientTruncateColumn, self).__init__(app, name)
+
+ self.header_class = TopTableColumnHeader
+ self.col_percent = 60
+
+class TruncatableTable(SqlTable):
+ def render_extra_class(self, session, *args):
+ """ if any columns are truncate, table needs a fixed layout
"""
+ return True in [True for x in self.columns
+ if isinstance(x, ClientTruncateColumn)] and " truncate"
or ""
+
+class TopTable(TruncatableTable):
+ def __init__(self, app, name):
super(TopTable, self).__init__(app, name)
col = self.CountColumn(app, "name")
@@ -733,13 +767,13 @@
def get_connection(self, session):
return sqlhub.getConnection().getConnection()
- class CountColumn(TopTableColumn):
+ class CountColumn(TopTableCountColumn):
def render_content(self, session, data):
count = self.parent.count.get(session)
self.parent.count.set(session, count + 1)
return count
-class CuminTable(SqlTable):
+class CuminTable(TruncatableTable):
def __init__(self, app, name):
super(CuminTable, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/widgets.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.strings 2009-06-09 20:20:29 UTC (rev 3437)
+++ mgmt/trunk/cumin/python/cumin/widgets.strings 2009-06-09 20:22:39 UTC (rev 3438)
@@ -556,6 +556,7 @@
width: 100%;
border-collapse: collapse;
margin: 0;
+ min-width: 100% !important;
}
table.TopTable tr {
@@ -565,6 +566,7 @@
table.TopTable td {
padding: 0.35em 0.5em;
+ text-overflow:ellipsis;
}
table.TopTable th {
@@ -580,8 +582,12 @@
text-align: right;
}
+table.TopTable th.top_count {
+ width: 1em;
+}
+
[TopTable.html]
-<table id="{id}" class="TopTable fullpage_notify">
+<table id="{id}" class="TopTable {extra_class}">
<thead><tr>{headers}</tr></thead>
<tbody>{items}</tbody>
</table>
@@ -594,14 +600,28 @@
font-size: 0.9em;
}
+table.mobjects td {
+ text-overflow:ellipsis;
+}
+
+table.truncate {
+ table-layout: fixed;
+ min-width: 600px;
+}
+
+table.truncate td.truncate {
+ white-space: nowrap;
+ overflow: hidden;
+}
+
[CuminTable.javascript]
wooly.addPageUpdateListener( cumin.restoreTableCheckboxes );
[CuminTable.html]
-<table id="{id}" class="mobjects">
+<table id="{id}" class="mobjects{extra_class}">
<thead>
<tr>
- <th class="setnav" colspan="{column_count}">
+ <th class="setnav">
<div class="rfloat">{page}</div>
{count}
</th>
@@ -647,6 +667,11 @@
[TableHeader.item_html]
<th class="{item_class}"><a
href="{item_href}">{item_content}</a></th>
+[CheckboxIdColumnHeader.css]
+th.chk_box {
+ width: 2em;
+}
+
[CheckboxIdColumnHeader.javascript]
function checkAll(control_id, form_id, elem_name) {
control = document.getElementById(control_id)
@@ -663,7 +688,7 @@
}
[CheckboxIdColumnHeader.html]
-<th><input id="{id}" type="checkbox" name="all"
+<th class="chk_box"><input id="{id}"
type="checkbox" name="all"
onclick="cumin.clickTableCheckbox(this, 'all'); checkAll('{id}',
'{form_id}', '{elem_name}')" value="all"/></th>
[TopN.html]
@@ -805,3 +830,4 @@
[Wait.html]
<div class="loading"
style="visibility:visible;"><span>Loading...</span></div>
+