copy to new recipe

This commit is contained in:
smilerz 2022-02-16 09:16:51 -06:00
parent 3db55cd82b
commit 501f56ffd5
No known key found for this signature in database
GPG Key ID: 39444C7606D47126
2 changed files with 22 additions and 1 deletions

View File

@ -31,6 +31,9 @@
{{ $t("Print") }}
</button>
</a>
<a href="javascript:void(0);">
<button class="dropdown-item" @click="copyToNew"><i class="fas fa-copy fa-fw"></i> {{ $t("copy_to_new") }}</button>
</a>
<a class="dropdown-item" :href="resolveDjangoUrl('view_export') + '?r=' + recipe.id" target="_blank" rel="noopener noreferrer"><i class="fas fa-file-export fa-fw"></i> {{ $t("Export") }}</a>
@ -202,6 +205,22 @@ export default {
addToShopping() {
this.$bvModal.show(`shopping_${this.modal_id}`)
},
copyToNew: function () {
let recipename = window.prompt(this.$t("copy_to_new"), this.$t("recipe_name"))
let apiClient = new ApiApiFactory()
apiClient.retrieveRecipe(this.recipe.id).then((results) => {
apiClient
.createRecipe({ ...results.data, ...{ id: undefined, name: recipename } })
.then((newrecipe) => {
console.log(newrecipe.data, this.resolveDjangoUrl("view_recipe", newrecipe.data.id))
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_CREATE)
window.open(this.resolveDjangoUrl("view_recipe", newrecipe.data.id))
})
.catch((error) => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_CREATE)
})
})
},
},
}
</script>

View File

@ -296,5 +296,7 @@
"food_recipe_help": "Linking a recipe here will include the linked recipe in any other recipe that use this food",
"Foods": "Foods",
"review_shopping": "Review shopping entries before saving",
"view_recipe": "View Recipe"
"view_recipe": "View Recipe",
"copy_to_new": "Copy To New Recipe",
"recipe_name": "Recipe Name"
}