From dbb037a35dff0caf3a735798751208cfa1f63d10 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 16 Jan 2024 15:44:02 +0100 Subject: [PATCH] Handle clicks to remove buttons more generically in certificate view This allows placing more than one button in a form. --- .../static/certificates/details.js | 34 +++++++++++-------- .../templates/certificates/details.html | 4 +-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/strongMan/apps/certificates/static/certificates/details.js b/strongMan/apps/certificates/static/certificates/details.js index 1de7778e..536c4778 100644 --- a/strongMan/apps/certificates/static/certificates/details.js +++ b/strongMan/apps/certificates/static/certificates/details.js @@ -1,15 +1,21 @@ -/** - * Created by root on 18/04/16. - */ +jQuery(function($) { + var $remove_btns = $('button.remove-btn'); + $remove_btns.each(function () { + var $btn = $(this); + var $form = $btn.closest('form'); -function removeBtnClicked(form) { - jform = $(form); - btn = jform.find('.remove-btn'); - if (btn.hasClass('btn-default')) { - btn.removeClass('btn-default').addClass('btn-danger'); - btn.find('.removebtn-text').text('Are you sure?'); - return false; - } else { - return true; - } -} + var $submitter = null; + $form.submit(function (form) { + if ($submitter && $submitter[0] == $btn[0] && $btn.hasClass('btn-default')) { + $btn.removeClass('btn-default').addClass('btn-danger'); + $btn.find('.removebtn-text').text('Are you sure?'); + return false; + } else { + return true; + } + }); + $form.find('button[type=submit]').click(function () { + $submitter = $(this); + }); + }); +}); diff --git a/strongMan/apps/certificates/templates/certificates/details.html b/strongMan/apps/certificates/templates/certificates/details.html index 4c0c1afa..108ce35e 100644 --- a/strongMan/apps/certificates/templates/certificates/details.html +++ b/strongMan/apps/certificates/templates/certificates/details.html @@ -172,7 +172,7 @@

{% if not readonly %}
-
+ {% csrf_token %}