Add more customization hooks for making grid actions in master view

This commit is contained in:
Lance Edgar 2020-07-30 16:38:03 -05:00
parent dfeb14e7a8
commit 8ea379bbff

View file

@ -1139,7 +1139,7 @@ class MasterView(View):
self.request.session.flash("{} has been cloned: {}".format( self.request.session.flash("{} has been cloned: {}".format(
self.get_model_title(), self.get_instance_title(instance))) self.get_model_title(), self.get_instance_title(instance)))
self.request.session.flash("(NOTE, you are now viewing the clone!)") self.request.session.flash("(NOTE, you are now viewing the clone!)")
return self.redirect(self.get_action_url('view', cloned)) return self.redirect_after_clone(cloned)
return self.render_to_response('clone', { return self.render_to_response('clone', {
'instance': instance, 'instance': instance,
'instance_title': self.get_instance_title(instance), 'instance_title': self.get_instance_title(instance),
@ -1167,6 +1167,9 @@ class MasterView(View):
self.Session.flush() self.Session.flush()
return cloned return cloned
def redirect_after_clone(self, instance, mobile=False):
return self.redirect(self.get_action_url('view', instance, mobile=mobile))
def touch(self): def touch(self):
""" """
View for "touching" an object so as to trigger datasync logic for it. View for "touching" an object so as to trigger datasync logic for it.
@ -2522,13 +2525,16 @@ class MasterView(View):
Return a list of 'main' actions for the grid. Return a list of 'main' actions for the grid.
""" """
actions = [] actions = []
use_buefy = self.get_use_buefy()
if self.viewable and self.has_perm('view'): if self.viewable and self.has_perm('view'):
url = self.get_view_index_url if self.use_index_links else None actions.append(self.make_grid_action_view())
icon = 'eye' if use_buefy else 'zoomin'
actions.append(self.make_action('view', icon=icon, url=url))
return actions return actions
def make_grid_action_view(self):
use_buefy = self.get_use_buefy()
url = self.get_view_index_url if self.use_index_links else None
icon = 'eye' if use_buefy else 'zoomin'
return self.make_action('view', icon=icon, url=url)
def get_view_index_url(self, row, i): def get_view_index_url(self, row, i):
route = '{}.view_index'.format(self.get_route_prefix()) route = '{}.view_index'.format(self.get_route_prefix())
return '{}?index={}'.format(self.request.route_url(route), self.first_visible_grid_index + i - 1) return '{}?index={}'.format(self.request.route_url(route), self.first_visible_grid_index + i - 1)
@ -2538,27 +2544,42 @@ class MasterView(View):
Return a list of 'more' actions for the grid. Return a list of 'more' actions for the grid.
""" """
actions = [] actions = []
use_buefy = self.get_use_buefy()
# Edit # Edit
if self.editable and self.has_perm('edit'): if self.editable and self.has_perm('edit'):
icon = 'edit' if use_buefy else 'pencil' actions.append(self.make_grid_action_edit())
actions.append(self.make_action('edit', icon=icon, url=self.default_edit_url))
# Delete # Delete
if self.deletable and self.has_perm('delete'): if self.deletable and self.has_perm('delete'):
kwargs = {} actions.append(self.make_grid_action_delete())
if use_buefy and self.delete_confirm == 'simple':
kwargs['click_handler'] = 'deleteObject'
actions.append(self.make_action('delete', icon='trash', url=self.default_delete_url, **kwargs))
return actions return actions
def make_grid_action_edit(self):
use_buefy = self.get_use_buefy()
icon = 'edit' if use_buefy else 'pencil'
return self.make_action('edit', icon=icon, url=self.default_edit_url)
def make_grid_action_clone(self):
return self.make_action('clone', icon='object-ungroup',
url=self.default_clone_url)
def make_grid_action_delete(self):
use_buefy = self.get_use_buefy()
kwargs = {}
if use_buefy and self.delete_confirm == 'simple':
kwargs['click_handler'] = 'deleteObject'
return self.make_action('delete', icon='trash', url=self.default_delete_url, **kwargs)
def default_edit_url(self, row, i=None): def default_edit_url(self, row, i=None):
if self.editable_instance(row): if self.editable_instance(row):
return self.request.route_url('{}.edit'.format(self.get_route_prefix()), return self.request.route_url('{}.edit'.format(self.get_route_prefix()),
**self.get_action_route_kwargs(row)) **self.get_action_route_kwargs(row))
def default_clone_url(self, row, i=None):
return self.request.route_url('{}.clone'.format(self.get_route_prefix()),
**self.get_action_route_kwargs(row))
def default_delete_url(self, row, i=None): def default_delete_url(self, row, i=None):
if self.deletable_instance(row): if self.deletable_instance(row):
return self.request.route_url('{}.delete'.format(self.get_route_prefix()), return self.request.route_url('{}.delete'.format(self.get_route_prefix()),