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">
${self.context_menu_items()} <tr>
</ul> <td rowspan="2" class="filters">
${search.render()|n}
<div class="left"> </td>
${search.render()|n} <td class="context-menu">
</div> <ul>
</div> ${self.context_menu_items()}
</ul>
</td>
</tr>
<tr>
<td class="tools">
${self.tools()}
</td>
</tr>
</table>
${grid|n} ${grid|n}

View file

@ -3,50 +3,52 @@
<table> <table>
<thead> <thead>
<tr> <tr>
% if checkboxes: % if checkboxes:
<th class="checkbox">${h.checkbox('check-all')}</th> <th class="checkbox">${h.checkbox('check-all')}</th>
% endif % endif
% 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>
% endif % endif
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
% for i, row in enumerate(grid.rows): % for i, row in enumerate(grid.rows):
<% grid._set_active(row) %> <% grid._set_active(row) %>
<tr ${grid.row_attrs(i)|n}> <tr ${grid.row_attrs(i)|n}>
% if checkboxes: % if checkboxes:
<td class="checkbox">${h.checkbox('check-'+grid.model.uuid, disabled=True)}</td> <td class="checkbox">${h.checkbox('check-'+grid.model.uuid, disabled=True)}</td>
% endif % endif
% 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:
% if grid.deletable: <td class="${col.name}">${col.callback(row)|n}</td>
<td class="delete">&nbsp;</td> % endfor
% endif % if grid.deletable:
</tr> <td class="delete">&nbsp;</td>
% endif
</tr>
% endfor % endfor
</tbody> </tbody>
</table> </table>
% if hasattr(grid, 'pager') and grid.pager: % if hasattr(grid, 'pager') and grid.pager:
<div class="pager"> <div class="pager">
<p class="showing"> <p class="showing">
showing showing
${grid.pager.first_item} thru ${grid.pager.last_item} of ${grid.pager.item_count} ${grid.pager.first_item} thru ${grid.pager.last_item} of ${grid.pager.item_count}
</p> </p>
<p class="page-links"> <p class="page-links">
${h.select('grid-page-count', grid.pager.items_per_page, (5, 10, 20, 50, 100))} ${h.select('grid-page-count', grid.pager.items_per_page, (5, 10, 20, 50, 100))}
per page:&nbsp; per page:&nbsp;
${grid.pager.pager('~3~', onclick='return grid_navigate_page($(this));')} ${grid.pager.pager('~3~', onclick='return grid_navigate_page($(this));')}
</p> </p>
</div> </div>
% endif % endif
</div> </div>