Skip to content

Commit

Permalink
Handle clicks to remove buttons more generically in certificate view
Browse files Browse the repository at this point in the history
This allows placing more than one button in a form.
  • Loading branch information
tobiasbrunner committed Jan 16, 2024
1 parent 81c135b commit dbb037a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
34 changes: 20 additions & 14 deletions strongMan/apps/certificates/static/certificates/details.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ <h2 class="text-center">
<div class="col-xs-12">
{% if not readonly %}
<div class="row text-center">
<form action="" method="POST" onsubmit="return removeBtnClicked(this)">
<form action="" method="POST">
{% csrf_token %}
<span title="Remove">
<button type="submit" class="btn btn-default remove-btn" name="remove_cert"
Expand Down Expand Up @@ -215,7 +215,7 @@ <h3 class="text-center"><span class="glyphicon glyphicon-lock" aria-hidden="fals
</div>
<div class="row">
<div class="text-center">
<form action="" method="POST" onsubmit="return removeBtnClicked(this)">
<form action="" method="POST">
{% csrf_token %}
<span title="Remove private key">
<button type="submit" class="btn btn-default remove-btn" name="remove_privatekey"
Expand Down

0 comments on commit dbb037a

Please sign in to comment.