Add a delete button.
This commit is contained in:
parent
93438ecbd8
commit
b00631bd3e
|
@ -4,6 +4,9 @@
|
|||
|
||||
{% block content %}
|
||||
|
||||
{% set subject_count = doc.subjects.count() %}
|
||||
{% set can_delete = subject_count == 0 %}
|
||||
|
||||
{% if current_user.is_authenticated and doc.user == current_user %}
|
||||
{% set title = doc.title_from_link() %}
|
||||
<div class="modal fade" id="title-modal" tabindex="-1" role="dialog">
|
||||
|
@ -32,6 +35,31 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if can_delete %}
|
||||
<div class="modal fade" id="delete-modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">delete</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form method="POST" action="{{ doc.view_url('delete_item') }}">
|
||||
<div class="modal-body">
|
||||
are you sure?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-danger">delete</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if doc.type != 'sourcedoc' %}
|
||||
|
@ -64,6 +92,9 @@
|
|||
<h1 class="mt-3">{{ self.title() }}
|
||||
{% if current_user.is_authenticated and doc.user == current_user %}
|
||||
<button class="btn btn-primary" data-toggle="modal" data-target="#title-modal">{{ 'edit' if title else 'add' }} title</button>
|
||||
{% if can_delete %}
|
||||
<button class="btn btn-danger" data-toggle="modal" data-target="#delete-modal">delete item</button>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</h1>
|
||||
{% if version %}
|
||||
|
@ -132,7 +163,6 @@
|
|||
</div>
|
||||
<div class="col-md-6">
|
||||
<h4>References</h4>
|
||||
{% set subject_count = doc.subjects.count() %}
|
||||
{% if subject_count %}
|
||||
<p>There are {{ subject_count }} documents that refer to this {{ doc.type }}.</p>
|
||||
<ul>
|
||||
|
|
|
@ -250,6 +250,14 @@ def set_title(username, hashid):
|
|||
flash('title change saved' if has_title else 'title added')
|
||||
return redirect(item.url)
|
||||
|
||||
@bp.route('/<username>/<hashid>/delete', methods=['POST'])
|
||||
def delete_item(username, hashid):
|
||||
item = get_item(username, hashid)
|
||||
session.delete(item)
|
||||
session.commit()
|
||||
flash('item deleted')
|
||||
return redirect_to_home()
|
||||
|
||||
@bp.route('/<username>/<hashid>')
|
||||
def view_item(username, hashid, raw=False):
|
||||
if ',' in hashid:
|
||||
|
|
Loading…
Reference in a new issue