add tools to object index, extra columns to grid

This commit is contained in:
Lance Edgar 2012-08-01 05:44:00 -07:00
parent 448835d480
commit 3f0dc2ad9a
4 changed files with 75 additions and 46 deletions

View file

@ -32,6 +32,7 @@ from webhelpers.html.tags import literal
import formalchemy
import edbob
from edbob.util import prettify
@ -75,6 +76,11 @@ class AlchemyGrid(formalchemy.Grid):
self.clickable = config.get('clickable', False)
self.deletable = config.get('deletable', False)
self.pager = instances if isinstance(instances, paginate.Page) else None
self.extra_columns = []
def add_column(self, name, label, callback):
self.extra_columns.append(
edbob.Object(name=name, label=label, callback=callback))
def field_name(self, field):
return field.name

View file

@ -12,12 +12,11 @@
div.object-index {
font-size: 10pt;
margin: auto;
}
div.object-index div.wrapper {
overflow: auto;
padding-bottom: 10px;
div.object-index table.header {
padding-bottom: 5px;
width: 100%;
}
@ -25,8 +24,11 @@ div.object-index div.wrapper {
* Context Menu
******************************/
div.object-index #context-menu {
float: right;
div.object-index table.header td.context-menu {
vertical-align: top;
}
div.object-index table.header td.context-menu ul {
list-style-type: none;
text-align: right;
}
@ -50,6 +52,16 @@ div.object-index div.filterset div.buttons * {
}
/******************************
* Tools
******************************/
div.object-index table.header td.tools {
text-align: right;
vertical-align: bottom;
}
/******************************
* Grids
******************************/

View file

@ -6,18 +6,27 @@
</%def>
<%def name="context_menu_items()"></%def>
<%def name="tools()"></%def>
<div class="object-index">
<div class="wrapper">
<ul id="context-menu">
<table class="header">
<tr>
<td rowspan="2" class="filters">
${search.render()|n}
</td>
<td class="context-menu">
<ul>
${self.context_menu_items()}
</ul>
<div class="left">
${search.render()|n}
</div>
</div>
</td>
</tr>
<tr>
<td class="tools">
${self.tools()}
</td>
</tr>
</table>
${grid|n}

View file

@ -9,8 +9,8 @@
% for field in grid.iter_fields():
${grid.th_sortable(field)|n}
% endfor
% for i in range(len(grid.config['actions'])):
<th>&nbsp;</th>
% for col in grid.extra_columns:
<th>${col.label}</td>
% endfor
% if grid.deletable:
<th>&nbsp;</th>
@ -28,7 +28,9 @@
% for field in grid.iter_fields():
<td class="${grid.field_name(field)}">${grid.render_field(field, True)|n}</td>
% endfor
${grid.get_actions()}
% for col in grid.extra_columns:
<td class="${col.name}">${col.callback(row)|n}</td>
% endfor
% if grid.deletable:
<td class="delete">&nbsp;</td>
% endif