improve clickable grid url stuff
This commit is contained in:
parent
f678d10187
commit
b6d48d692f
4 changed files with 22 additions and 24 deletions
|
@ -99,8 +99,8 @@ class AlchemyGrid(Grid):
|
|||
return field.render_readonly()
|
||||
return field.render()
|
||||
|
||||
def _row_attrs(self, row, i):
|
||||
attrs = super(AlchemyGrid, self)._row_attrs(row, i)
|
||||
def row_attrs(self, row, i):
|
||||
attrs = super(AlchemyGrid, self).row_attrs(row, i)
|
||||
if hasattr(row, 'uuid'):
|
||||
attrs['uuid'] = row.uuid
|
||||
return attrs
|
||||
|
|
|
@ -49,7 +49,8 @@ class Grid(edbob.Object):
|
|||
checkboxes = False
|
||||
deletable = False
|
||||
partial_only = False
|
||||
row_attrs = None
|
||||
row_route_name = None
|
||||
row_route_kwargs = None
|
||||
|
||||
def __init__(self, request, **kwargs):
|
||||
kwargs.setdefault('fields', OrderedDict())
|
||||
|
@ -95,12 +96,18 @@ class Grid(edbob.Object):
|
|||
def render_field(self, field):
|
||||
raise NotImplementedError
|
||||
|
||||
def _row_attrs(self, row, i):
|
||||
def row_attrs(self, row, i):
|
||||
attrs = {'class_': 'odd' if i % 2 else 'even'}
|
||||
return attrs
|
||||
|
||||
def get_row_attrs(self, row, i):
|
||||
attrs = self._row_attrs(row, i)
|
||||
if self.row_attrs:
|
||||
attrs.update(self.row_attrs(row, i))
|
||||
attrs = self.row_attrs(row, i)
|
||||
if self.row_route_name:
|
||||
kwargs = {}
|
||||
if self.row_route_kwargs:
|
||||
if callable(self.row_route_kwargs):
|
||||
kwargs = self.row_route_kwargs(row)
|
||||
else:
|
||||
kwargs = self.row_route_kwargs
|
||||
attrs['url'] = self.request.route_url(self.row_route_name, **kwargs)
|
||||
return format_attrs(**attrs)
|
||||
|
|
|
@ -250,22 +250,13 @@ $(function() {
|
|||
$(this).removeClass('hovering');
|
||||
});
|
||||
|
||||
$('div.grid.clickable table tbody tr').live('click', function() {
|
||||
var div = $(this).parents('div.grid:first');
|
||||
if (div.attr('usedlg') == 'True') {
|
||||
var dlg = get_dialog('grid-object');
|
||||
var data = {
|
||||
'uuid': get_uuid(this),
|
||||
'partial': true,
|
||||
};
|
||||
dlg.load(div.attr('objurl'), data, function() {
|
||||
dlg.dialog({
|
||||
width: 500,
|
||||
height: 450,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
location.href = div.attr('objurl').replace(/%7Buuid%7D/, get_uuid(this));
|
||||
$('div.grid.clickable table tbody td').live('click', function() {
|
||||
if (! $(this).hasClass('noclick')) {
|
||||
var row = $(this).parents('tr:first');
|
||||
var url = row.attr('url');
|
||||
if (url) {
|
||||
location.href = url;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<td class="${field.name}">${grid.render_field(field)}</td>
|
||||
% endfor
|
||||
% for col in grid.extra_columns:
|
||||
<td class="${col.name}">${col.callback(row)}</td>
|
||||
<td class="noclick ${col.name}">${col.callback(row)}</td>
|
||||
% endfor
|
||||
% if grid.deletable:
|
||||
<td class="delete"> </td>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue