Compare commits

...

5 Commits

5 changed files with 86 additions and 2 deletions

18
app.py
View File

@ -568,6 +568,24 @@ def delete_habit():
return {}
@app.route('/delete-list', methods=['POST'])
@login_required
def delete_list():
list_id = request.get_json()["listId"]
habit_list = HabitList.get(list_id)
if habit_list is None:
return {"error": "List not found"}
# Check if habit belongs to user
if current_user not in habit_list.get_users():
return {"error": "List does not belong to user"}
habit_list.delete()
return {}
@app.route('/reorder', methods=['POST'])
@login_required
def reorder_habits():

View File

@ -0,0 +1,20 @@
<div class="modal fade" id="listenModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Bestätige</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Möchtest du diese Liste wirklich löschen?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">abbrechen</button>
<button type="button" class="btn btn-primary btn-danger" data-bs-dismiss="modal"
onclick="deleteList(selectedListId)">Löschen
</button>
</div>
</div>
</div>
</div>

View File

@ -15,7 +15,7 @@
<ul class="nav nav-tabs card-header-tabs" role="tablist">
{% for habit_list in habit_lists %}
<li class="nav-item" role="presentation">
<li class="nav-item" role="presentation" id="tab-{{ habit_list.id }}">
<a class="nav-link {% if habit_list == habit_lists[0] %} active {% endif %}"
id="simple-tab-{{habit_list.id}}"
data-bs-toggle="tab" href="#simple-tabpanel-{{habit_list.id}}" role="tab"
@ -63,6 +63,22 @@
{% for habit_list in habit_lists %}
<div class="tab-pane {% if habit_list == habit_lists[0] %} active {% endif %}"
id="simple-tabpanel-{{habit_list.id}}" role="tabpanel" aria-labelledby="simple-tab-{{habit_list.id}}">
<!-- Beschreibung und Löschen von der Liste -->
<div class="row mb-3">
<div class="col">
{{ habit_list.description }}
</div>
<div class="col-2">
<button type="button" class="btn btn-xs me-3" data-bs-toggle="modal"
data-bs-target="#listenModal" style="width: 40px; height: 40px"
onclick="setSelectedListId({{ habit_list.id }})">
<i class="bi bi-trash3"></i>
</button>
</div>
</div>
<div class="row mb-3 align-items-center">
<!-- Personen die zur Liste gehören -->
@ -103,7 +119,7 @@
{% for habit in habit_list.habits %}
<li class="row d-flex align-items-center mb-2" id="habit-{{ habit.id }}">
<!-- Handle zum verschieben -->
<!-- Handle zum Verschieben -->
<div class="col-auto drag-handle" style="cursor: grab;">
<i class="bi bi-grip-vertical"></i>
</div>
@ -172,5 +188,9 @@
selectedHabitId = habitId;
}
var selectedListId = null;
function setSelectedListId(listId) {
selectedlistId = listId;
}
</script>

View File

@ -76,6 +76,28 @@
});
}
function deleteList(listId) {
// Make a POST request to /delete with the habit id
axios.post('/delete-list', {listId: listId}, {
headers: {
'Content-Type': 'application/json'
}
}).then(function (response) {
// Handle the success response if needed
console.log(response.data);
// Remove the habit from the DOM
var habitElement = document.getElementById("simple-tabpanel-" + listId);
habitElement.remove();
var habitElement = document.getElementById("tab-" + listId);
habitElement.remove();
}).catch(function (error) {
// Handle the error if needed
console.error('Error:', error);
});
}
document.addEventListener('DOMContentLoaded', (event) => {
var elements = document.querySelectorAll('.task-list').values()

View File

@ -47,6 +47,10 @@
{% include 'components/delete_button.html' %}
{% endif %}
{% if current_user.is_authenticated %}
{% include 'components/delete_list.html' %}
{% endif %}
</div>
{% include 'components/scripts.html' %}