diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index fb32f2d..93601a5 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -1,6 +1,6 @@
- +
📋 Gewohnheiten @@ -11,7 +11,7 @@
- + +
{% for habit_list in habit_lists %} @@ -32,7 +65,7 @@ id="simple-tabpanel-{{habit_list.id}}" role="tabpanel" aria-labelledby="simple-tab-{{habit_list.id}}">
- +
@@ -42,7 +75,7 @@
- +
- + - +
{ - var el = document.querySelector('.task-list'); - Sortable.create(el, { - handle: '.drag-handle', - animation: 150, - onEnd: function (evt) { - var habitId = el.children[evt.newIndex].id.split('-')[1]; - var oldIndex = evt.oldIndex; - var newIndex = evt.newIndex; + var elements = document.querySelectorAll('.task-list').values() - axios.post('/reorder', {habitId: habitId, oldIndex: oldIndex, newIndex: newIndex}, { - headers: { - 'Content-Type': 'application/json' - } - }).then(function (response) { - // Handle the success response if needed - }).catch(function (error) { - // Handle the error if needed - console.error('Error:', error); - }); - } - }); + // loop through the elements + for (let el of elements) { + Sortable.create(el, { + handle: '.drag-handle', + animation: 150, + onEnd: function (evt) { + var habitId = el.children[evt.newIndex].id.split('-')[1]; + var oldIndex = evt.oldIndex; + var newIndex = evt.newIndex; + + axios.post('/reorder', {habitId: habitId, oldIndex: oldIndex, newIndex: newIndex}, { + headers: { + 'Content-Type': 'application/json' + } + }).then(function (response) { + // Handle the success response if needed + }).catch(function (error) { + // Handle the error if needed + console.error('Error:', error); + }); + } + }); + } });