Skip to content

Commit

Permalink
Fix issue #13: Ability to delete a term from reading screen
Browse files Browse the repository at this point in the history
Added Delete button in term form, visible in both /read and /term/edit:
 Button in /read reloads the page
 Button in /term/edit redirects to /term/index

Removed old delete button in /term/edit
  • Loading branch information
dgc08 committed Dec 28, 2023
1 parent ddea88a commit 4f0687c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
28 changes: 28 additions & 0 deletions lute/templates/term/_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
<a href="" onclick="show_term_sentences(); return false;">Sentences</a>
<button id="submit" type="submit" class="btn btn-primary">Save</button>
</td>
{% if term.id %}
<tr>
<td align="right">
<button id="delete" type="button" class="btn" onclick="deleteTerm()">Delete</button>
</td>
</tr>
{% endif %}
</tr>

</tbody>
Expand Down Expand Up @@ -398,4 +405,25 @@
top.frames.dictframe.location.href = url;
}

function deleteTerm() {
// Ask for confirmation
var isConfirmed = confirm('Are you sure you want to delete this term?\n\nThis action cannot be undone, and if this term has children, they will be orphaned.');

// Check if the user confirmed
if (isConfirmed) {
// Delete term
fetch("/term/delete/{{ term.id }}")

if ("{{ embedded_in_reading_frame }}" == "True") {
// If on reading page, reload page
parent.location.reload();
}
else {
// If on term page, go to term listing
window.location.href = '/term/index';
}
}
}


</script>
11 changes: 1 addition & 10 deletions lute/templates/term/formframes.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@
{% block body %}
<div id="term_form_left">
{% include('term/_form.html') %}
<a href="/term/index">back to list</a>

{% if term.id %}
<form
method="post"
action="/term/delete/{{ term.id }}"
onsubmit="return confirm('Are you sure you want to delete this item?');">
<button class="btn">Delete</button>
</form>
{% endif %}
<a href="/term/index">Back to all terms</a>
</div>


Expand Down
2 changes: 1 addition & 1 deletion lute/term/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def bulk_set_parent():
return jsonify("ok")


@bp.route("/delete/<int:termid>", methods=["POST"])
@bp.route("/delete/<int:termid>", methods=["GET"])
def delete(termid):
"""
Delete a term.
Expand Down

0 comments on commit 4f0687c

Please sign in to comment.