Skip to content
Snippets Groups Projects
Commit ba27ff55 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add confirmation dialog to delete

Create macro to add delete button with modal dialog
to cancel or confirm deletion.
parent 7327009c
No related branches found
No related tags found
No related merge requests found
...@@ -43,3 +43,26 @@ ...@@ -43,3 +43,26 @@
{% macro format_datetime(dt) -%} {% macro format_datetime(dt) -%}
{{ dt.strftime("%Y-%m-%d %H:%M") }} {{ dt.strftime("%Y-%m-%d %H:%M") }}
{%- endmacro %} {%- endmacro %}
{% macro delete_button_with_confirmation(title, modal_id, message) -%}
<button type="button" class="btn btn-light" data-toggle="modal" data-target={{ "#%s" | format(modal_id) }}>
<span class="oi oi-trash" title="{{ title }}" aria-hidden="true"></span>
</button>
<!-- Modal -->
<div class="modal fade" id="{{ modal_id }}" tabindex="-1" role="dialog" aria-labelledby="delete-confirmation" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title">{{ message }}</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">OK</button>
</div>
</div>
</div>
</div>
{%- endmacro %}
{% extends "network/hosts.html" %} {% extends "network/hosts.html" %}
{% from "_helpers.html" import link_to_item %} {% from "_helpers.html" import link_to_item, delete_button_with_confirmation %}
{% block title %}View Host - CSEntry{% endblock %} {% block title %}View Host - CSEntry{% endblock %}
...@@ -50,9 +50,8 @@ ...@@ -50,9 +50,8 @@
</a> </a>
<form method="POST" action="/network/interfaces/delete"> <form method="POST" action="/network/interfaces/delete">
<input id="interface_id" name="interface_id" type="hidden" value="{{ interface.id }}"> <input id="interface_id" name="interface_id" type="hidden" value="{{ interface.id }}">
<button type="submit" class="btn btn-light"> {{ delete_button_with_confirmation("Delete interface", "deleteConfirmation-%s" | format(interface.id),
<span class="oi oi-trash" title="Delete interface" aria-hidden="true"></span> "Are you sure you want to delete interface %s?" | format(interface.name)) }}
</button>
</form> </form>
</td> </td>
<td>{{ interface.name }}</td> <td>{{ interface.name }}</td>
......
{% extends "base.html" %} {% extends "base.html" %}
{% from "_helpers.html" import render_field %} {% from "_helpers.html" import render_field, delete_button_with_confirmation %}
{% block title %}Profile - CSEntry{% endblock %} {% block title %}Profile - CSEntry{% endblock %}
...@@ -50,9 +50,8 @@ ...@@ -50,9 +50,8 @@
<form method="POST" action="/users/tokens/revoke"> <form method="POST" action="/users/tokens/revoke">
<input id="token_id" name="token_id" type="hidden" value="{{ token.id }}"> <input id="token_id" name="token_id" type="hidden" value="{{ token.id }}">
<input id="jti" name="jti" type="hidden" value="{{ token.jti }}"> <input id="jti" name="jti" type="hidden" value="{{ token.jti }}">
<button type="submit" class="btn btn-danger"> {{ delete_button_with_confirmation("Revoke token", "revokeConfirmation-%s" | format(token.id),
<span class="oi oi-trash" title="Revoke token" aria-hidden="true"></span> "Are you sure you want to revoke token %s?" | format(token.jti)) }}
</button>
</form> </form>
</td> </td>
<td>{{ token.jti }}</td> <td>{{ token.jti }}</td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment