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 formalchemy
import edbob
from edbob.util import prettify from edbob.util import prettify
@ -75,6 +76,11 @@ class AlchemyGrid(formalchemy.Grid):
self.clickable = config.get('clickable', False) self.clickable = config.get('clickable', False)
self.deletable = config.get('deletable', False) self.deletable = config.get('deletable', False)
self.pager = instances if isinstance(instances, paginate.Page) else None 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): def field_name(self, field):
return field.name return field.name

View file

@ -12,12 +12,11 @@
div.object-index { div.object-index {
font-size: 10pt; font-size: 10pt;
margin: auto;
} }
div.object-index div.wrapper { div.object-index table.header {
overflow: auto; padding-bottom: 5px;
padding-bottom: 10px; width: 100%;
} }
@ -25,8 +24,11 @@ div.object-index div.wrapper {
* Context Menu * Context Menu
******************************/ ******************************/
div.object-index #context-menu { div.object-index table.header td.context-menu {
float: right; vertical-align: top;
}
div.object-index table.header td.context-menu ul {
list-style-type: none; list-style-type: none;
text-align: right; 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 * Grids
******************************/ ******************************/

View file

@ -6,18 +6,27 @@
</%def> </%def>
<%def name="context_menu_items()"></%def> <%def name="context_menu_items()"></%def>
<%def name="tools()"></%def>
<div class="object-index"> <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()} ${self.context_menu_items()}
</ul> </ul>
</td>
<div class="left"> </tr>
${search.render()|n} <tr>
</div> <td class="tools">
</div> ${self.tools()}
</td>
</tr>
</table>
${grid|n} ${grid|n}

View file

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