Add generic support for "delete w/ simple confirm" in master index template

jquery only, for now
This commit is contained in:
Lance Edgar 2019-06-09 21:34:47 -05:00
parent e715794f04
commit 3775c53df3

View file

@ -16,12 +16,24 @@
${parent.extra_javascript()}
% if use_buefy:
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.buefy.grid.js') + '?ver={}'.format(tailbone.__version__))}
% endif
% else:
<script type="text/javascript">
$(function() {
% if not use_buefy:
$('.grid-wrapper').gridwrapper();
% if master.deletable and request.has_perm('{}.delete'.format(permission_prefix)) and master.delete_confirm == 'simple':
$('.grid-wrapper').on('click', '.grid .actions a.delete', function() {
if (confirm("Are you sure you wish to delete this ${model_title}?")) {
var link = $(this).get(0);
var form = $('#delete-object-form').get(0);
form.action = link.href;
form.submit();
}
return false;
});
% endif
% if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)):
@ -45,7 +57,7 @@
% endif
% if not use_buefy and master.bulk_deletable and request.has_perm('{}.bulk_delete'.format(permission_prefix)):
% if master.bulk_deletable and request.has_perm('{}.bulk_delete'.format(permission_prefix)):
$('form[name="bulk-delete"] button').click(function() {
var count = $('.grid-wrapper').gridwrapper('results_count', true);
@ -112,6 +124,7 @@
% endif
});
</script>
% endif
</%def>
<%def name="context_menu_items()">
@ -228,4 +241,9 @@
## no buefy, so do the traditional thing
${grid.render_complete(tools=capture(self.grid_tools).strip(), context_menu=capture(self.context_menu_items).strip())|n}
% if master.deletable and request.has_perm('{}.delete'.format(permission_prefix)) and master.delete_confirm == 'simple':
${h.form('#', id='delete-object-form')}
${h.csrf_token(request)}
${h.end_form()}
% endif
% endif