Add basic support for deletion speedbump for row data
This commit is contained in:
parent
72ae1191a0
commit
9107a26b63
|
@ -47,7 +47,7 @@ class Grid(object):
|
|||
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
|
||||
pageable=False, default_pagesize=20, default_page=1,
|
||||
width='auto', checkboxes=False, row_attrs={}, cell_attrs={},
|
||||
**kwargs):
|
||||
delete_speedbump=False, **kwargs):
|
||||
self.key = key
|
||||
self.request = request
|
||||
self.columns = columns
|
||||
|
@ -55,6 +55,7 @@ class Grid(object):
|
|||
self.main_actions = main_actions
|
||||
self.more_actions = more_actions
|
||||
self.joiners = joiners or {} # use new/different empty dict for each instance
|
||||
self.delete_speedbump = delete_speedbump
|
||||
|
||||
# Set extra attributes first, in case other init logic depends on any
|
||||
# of them (i.e. in subclasses).
|
||||
|
@ -560,9 +561,12 @@ class Grid(object):
|
|||
classes.append('full')
|
||||
if self.checkboxes:
|
||||
classes.append('selectable')
|
||||
return {'class_': ' '.join(classes),
|
||||
attrs = {'class_': ' '.join(classes),
|
||||
'data-url': self.request.current_route_url(_query=None),
|
||||
'data-permalink': self.request.current_route_url()}
|
||||
if self.delete_speedbump:
|
||||
attrs['data-delete-speedbump'] = 'true'
|
||||
return attrs
|
||||
|
||||
def iter_visible_columns(self):
|
||||
"""
|
||||
|
|
7
tailbone/static/js/jquery.ui.tailbone.js
vendored
7
tailbone/static/js/jquery.ui.tailbone.js
vendored
|
@ -185,6 +185,13 @@
|
|||
this.element.on('mouseleave', '.actions div.more', function() {
|
||||
$(this).hide();
|
||||
});
|
||||
|
||||
// Add speed bump for "Delete Row" action, if grid is so configured.
|
||||
if (this.grid.data('delete-speedbump')) {
|
||||
this.element.on('click', 'tbody td.actions a.delete', function() {
|
||||
return confirm("Are you sure you wish to delete this object?");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Refreshes the visible data within the grid, according to the given settings.
|
||||
|
|
|
@ -84,6 +84,7 @@ class MasterView(View):
|
|||
rows_creatable = False
|
||||
rows_editable = False
|
||||
rows_deletable = False
|
||||
rows_deletable_speedbump = False
|
||||
rows_bulk_deletable = False
|
||||
|
||||
@property
|
||||
|
@ -445,6 +446,7 @@ class MasterView(View):
|
|||
# delete action
|
||||
if self.rows_deletable and self.request.has_perm('{}.delete_row'.format(permission_prefix)):
|
||||
actions.append(grids.GridAction('delete', icon='trash', url=self.row_delete_action_url))
|
||||
defaults['delete_speedbump'] = self.rows_deletable_speedbump
|
||||
|
||||
defaults['main_actions'] = actions
|
||||
|
||||
|
|
Loading…
Reference in a new issue