From 796170100ff34deec828f7279ac1d70eef80e940 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 8 Jun 2019 18:39:52 -0500 Subject: [PATCH] Add support for "simple confirm" of object deletion i.e. can just use `window.confirm()` instead of showing full confirm page note, this is jquery-only for now --- tailbone/templates/master/edit.mako | 6 ++---- tailbone/templates/master/form.mako | 22 ++++++++++++++++++++++ tailbone/templates/master/view.mako | 24 ++++++++++++++++++++---- tailbone/views/master.py | 1 + 4 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 tailbone/templates/master/form.mako diff --git a/tailbone/templates/master/edit.mako b/tailbone/templates/master/edit.mako index b0aa8b60..385e1fb3 100644 --- a/tailbone/templates/master/edit.mako +++ b/tailbone/templates/master/edit.mako @@ -1,5 +1,5 @@ ## -*- coding: utf-8; -*- -<%inherit file="/form.mako" /> +<%inherit file="/master/form.mako" /> <%def name="title()">Edit: ${instance_title} @@ -24,9 +24,7 @@ % if master.viewable and request.has_perm('{}.view'.format(permission_prefix)):
  • ${h.link_to("View this {}".format(model_title), action_url('view', instance))}
  • % endif - % if master.deletable and instance_deletable and request.has_perm('{}.delete'.format(permission_prefix)): -
  • ${h.link_to("Delete this {}".format(model_title), action_url('delete', instance))}
  • - % endif + ${self.context_menu_item_delete()} % if master.creatable and master.show_create_link and request.has_perm('{}.create'.format(permission_prefix)): % if master.creates_multiple:
  • ${h.link_to("Create new {}".format(model_title_plural), url('{}.create'.format(route_prefix)))}
  • diff --git a/tailbone/templates/master/form.mako b/tailbone/templates/master/form.mako new file mode 100644 index 00000000..81f1171e --- /dev/null +++ b/tailbone/templates/master/form.mako @@ -0,0 +1,22 @@ +## -*- coding: utf-8; -*- +<%inherit file="/form.mako" /> + +<%def name="context_menu_item_delete()"> + % if master.deletable and instance_deletable and request.has_perm('{}.delete'.format(permission_prefix)): + % if master.delete_confirm == 'simple': +
  • + ${h.form(action_url('delete', instance))} + ${h.csrf_token(request)} + + Delete this ${model_title} + + ${h.end_form()} +
  • + % else: + ## assuming here that: delete_confirm == 'full' +
  • ${h.link_to("Delete this {}".format(model_title), action_url('delete', instance))}
  • + % endif + % endif + + +${parent.body()} diff --git a/tailbone/templates/master/view.mako b/tailbone/templates/master/view.mako index 7d395de9..c5473c23 100644 --- a/tailbone/templates/master/view.mako +++ b/tailbone/templates/master/view.mako @@ -1,10 +1,28 @@ ## -*- coding: utf-8; -*- -<%inherit file="/form.mako" /> +<%inherit file="/master/form.mako" /> <%def name="title()">${index_title} » ${instance_title} <%def name="extra_javascript()"> ${parent.extra_javascript()} + % if master.deletable and instance_deletable and request.has_perm('{}.delete'.format(permission_prefix)) and master.delete_confirm == 'simple': + % if not use_buefy: + + % endif + % endif % if master.has_rows: % if use_buefy: ${h.javascript_link(request.static_url('tailbone:static/js/tailbone.buefy.grid.js') + '?ver={}'.format(tailbone.__version__))} @@ -41,9 +59,7 @@ % if master.editable and instance_editable and request.has_perm('{}.edit'.format(permission_prefix)):
  • ${h.link_to("Edit this {}".format(model_title), action_url('edit', instance))}
  • % endif - % if master.deletable and instance_deletable and request.has_perm('{}.delete'.format(permission_prefix)): -
  • ${h.link_to("Delete this {}".format(model_title), action_url('delete', instance), class_='delete-instance')}
  • - % endif + ${self.context_menu_item_delete()} % if master.creatable and master.show_create_link and request.has_perm('{}.create'.format(permission_prefix)): % if master.creates_multiple:
  • ${h.link_to("Create new {}".format(model_title_plural), url('{}.create'.format(route_prefix)))}
  • diff --git a/tailbone/views/master.py b/tailbone/views/master.py index a52ae4b4..fd3985d6 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -83,6 +83,7 @@ class MasterView(View): viewable = True editable = True deletable = True + delete_confirm = 'full' bulk_deletable = False set_deletable = False supports_set_enabled_toggle = False