From 4b7896f7d1cccec8ccdc95dc7a5fb47d0ae0a708 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 19 May 2021 12:58:21 +0200 Subject: [PATCH] auto open/close shopping list when checked --- cookbook/templates/shopping_list.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html index 246a5369..ad3a8479 100644 --- a/cookbook/templates/shopping_list.html +++ b/cookbook/templates/shopping_list.html @@ -412,6 +412,7 @@ amount: undefined, food: undefined, }, + unchecked_entries: 0, foods: [], foods_loading: false, units: [], @@ -449,6 +450,7 @@ return cache }, display_categories() { + this.unchecked_entries = 0 let categories = { no_category: { name: gettext('Uncategorized'), @@ -514,6 +516,9 @@ categories['no_category'].entries.push(item) } } + if (!item.checked) { + this.unchecked_entries += 1 + } }); let ordered_categories = [] @@ -772,6 +777,27 @@ Promise.allSettled(updates).then(() => { this.auto_sync_blocked = false + if (this.unchecked_entries < 1) { + this.shopping_list.finished = true + + this.$http.put("{% url 'api:shoppinglist-detail' 123456 %}".replace('123456', this.shopping_list.id), this.shopping_list, {}).then((response) => { + this.makeToast(gettext('Finished'), gettext('Shopping list finished!'), 'success') + }).catch((err) => { + console.log(err) + this.makeToast(gettext('Error'), gettext("There was an error updating a resource!") + err.bodyText, 'danger') + }) + } else { + if (this.unchecked_entries > 0 && this.shopping_list.finished) { + this.shopping_list.finished = false + + this.$http.put("{% url 'api:shoppinglist-detail' 123456 %}".replace('123456', this.shopping_list.id), this.shopping_list, {}).then((response) => { + this.makeToast(gettext('Open'), gettext('Shopping list reopened!'), 'success') + }).catch((err) => { + console.log(err) + this.makeToast(gettext('Error'), gettext("There was an error updating a resource!") + err.bodyText, 'danger') + }) + } + } }) }, addEntry: function () {