+
Non Edit
-
+
@@ -136,12 +192,12 @@
delimiters: ['[[', ']]'],
el: '#id_base_container',
data: {
- shopping_list_id: {{ shopping_list_id }},
+ shopping_list_id: {% if shopping_list_id %}{{ shopping_list_id }}{% else %}null{% endif %},
+ loading: true,
edit_mode: true,
recipe_query: '',
recipes: [],
shopping_list: undefined,
- //multiplier_cache: {},
new_entry: {
unit: undefined,
amount: undefined,
@@ -199,8 +255,6 @@
},
*/
mounted: function () {
-
-
if (this.shopping_list_id) {
this.loadShoppingList()
} else {
@@ -212,9 +266,8 @@
"shared": [],
"created_by": 1
}
-
+ this.loading = false
}
-
},
methods: {
@@ -239,12 +292,14 @@
this.$http.get("{% url 'api:shoppinglist-detail' shopping_list_id %}").then((response) => {
this.shopping_list = response.body
+ this.loading = false
}).catch((err) => {
console.log(err)
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
})
},
updateShoppingList: function () {
+ this.loading = true
let recipe_promises = []
for (let i in this.shopping_list.recipes) {
@@ -268,14 +323,30 @@
Promise.allSettled(recipe_promises).then(() => {
console.log("proceeding to update shopping list", this.shopping_list)
- this.$http.put("{% url 'api:shoppinglist-detail' shopping_list_id %}", this.shopping_list, {}).then((response) => {
- console.log(response)
- this.makeToast('{% trans 'Updated' %}', '{% trans 'Changes saved successfully!' %}', 'success')
+ if (this.shopping_list_id === null) {
+ this.$http.post("{% url 'api:shoppinglist-list' %}", this.shopping_list, {}).then((response) => {
+ console.log(response)
+ this.makeToast('{% trans 'Updated' %}', '{% trans 'Object created successfully!' %}', 'success')
+ this.loading = false
+ this.shopping_list = response.body
+ }).catch((err) => {
+ console.log(err)
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error creating a resource!' %}' + err.bodyText, 'danger')
+ this.loading = false
+ })
+ } else {
+ this.$http.put("{% url 'api:shoppinglist-detail' shopping_list_id %}", this.shopping_list, {}).then((response) => {
+ console.log(response)
+ this.makeToast('{% trans 'Updated' %}', '{% trans 'Changes saved successfully!' %}', 'success')
+ this.loading = false
+ }).catch((err) => {
+ console.log(err)
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating a resource!' %}' + err.bodyText, 'danger')
+ this.loading = false
+ })
+ }
+
- }).catch((err) => {
- console.log(err)
- this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating a resource!' %}' + err.bodyText, 'danger')
- })
})
},
addEntry: function () {