Add basic support for deletion speedbump for row data

This commit is contained in:
Lance Edgar 2017-05-04 16:35:21 -05:00
parent 72ae1191a0
commit 9107a26b63
3 changed files with 15 additions and 2 deletions

View file

@ -47,7 +47,7 @@ class Grid(object):
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc', sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
pageable=False, default_pagesize=20, default_page=1, pageable=False, default_pagesize=20, default_page=1,
width='auto', checkboxes=False, row_attrs={}, cell_attrs={}, width='auto', checkboxes=False, row_attrs={}, cell_attrs={},
**kwargs): delete_speedbump=False, **kwargs):
self.key = key self.key = key
self.request = request self.request = request
self.columns = columns self.columns = columns
@ -55,6 +55,7 @@ class Grid(object):
self.main_actions = main_actions self.main_actions = main_actions
self.more_actions = more_actions self.more_actions = more_actions
self.joiners = joiners or {} # use new/different empty dict for each instance 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 # Set extra attributes first, in case other init logic depends on any
# of them (i.e. in subclasses). # of them (i.e. in subclasses).
@ -560,9 +561,12 @@ class Grid(object):
classes.append('full') classes.append('full')
if self.checkboxes: if self.checkboxes:
classes.append('selectable') classes.append('selectable')
return {'class_': ' '.join(classes), attrs = {'class_': ' '.join(classes),
'data-url': self.request.current_route_url(_query=None), 'data-url': self.request.current_route_url(_query=None),
'data-permalink': self.request.current_route_url()} 'data-permalink': self.request.current_route_url()}
if self.delete_speedbump:
attrs['data-delete-speedbump'] = 'true'
return attrs
def iter_visible_columns(self): def iter_visible_columns(self):
""" """

View file

@ -185,6 +185,13 @@
this.element.on('mouseleave', '.actions div.more', function() { this.element.on('mouseleave', '.actions div.more', function() {
$(this).hide(); $(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. // Refreshes the visible data within the grid, according to the given settings.

View file

@ -84,6 +84,7 @@ class MasterView(View):
rows_creatable = False rows_creatable = False
rows_editable = False rows_editable = False
rows_deletable = False rows_deletable = False
rows_deletable_speedbump = False
rows_bulk_deletable = False rows_bulk_deletable = False
@property @property
@ -445,6 +446,7 @@ class MasterView(View):
# delete action # delete action
if self.rows_deletable and self.request.has_perm('{}.delete_row'.format(permission_prefix)): 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)) actions.append(grids.GridAction('delete', icon='trash', url=self.row_delete_action_url))
defaults['delete_speedbump'] = self.rows_deletable_speedbump
defaults['main_actions'] = actions defaults['main_actions'] = actions