diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index b3c765e..68f2aea 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -74,12 +74,9 @@ class RecipesController < ApplicationController def destroy ensure_owner(@recipe) do @recipe.deleted = true + @recipe.save!(validate: false) - if @recipe.save(validate: false) - redirect_to recipes_url, notice: 'Recipe was successfully destroyed.' - else - redirect_to recipes_url, error: 'Recipe could not be destroyed.' - end + render json: { success: true } end end diff --git a/app/javascript/components/AppConfirm.vue b/app/javascript/components/AppConfirm.vue new file mode 100644 index 0000000..5ddca85 --- /dev/null +++ b/app/javascript/components/AppConfirm.vue @@ -0,0 +1,47 @@ + + + \ No newline at end of file diff --git a/app/javascript/components/AppModal.vue b/app/javascript/components/AppModal.vue index 426f742..f015190 100644 --- a/app/javascript/components/AppModal.vue +++ b/app/javascript/components/AppModal.vue @@ -1,6 +1,6 @@ @@ -80,6 +82,7 @@ data() { return { recipeData: null, + recipeForDeletion: null, search: { sortColumn: 'created_at', sortDirection: 'desc', @@ -123,6 +126,18 @@ return this.recipeData.current_page; } return 0; + }, + + showConfirmRecipeDelete() { + return this.recipeForDeletion !== null; + }, + + confirmRecipeDeleteMessage() { + if (this.showConfirmRecipeDelete) { + return `Are you sure you want to delete ${this.recipeForDeletion.name}?`; + } else { + return "??"; + } } }, @@ -140,8 +155,27 @@ } }, + deleteRecipe(recipe) { + this.recipeForDeletion = recipe; + }, + + recipeDeleteConfirm() { + if (this.recipeForDeletion !== null) { + this.loadResource( + api.deleteRecipe(this.recipeForDeletion.id).then(() => { + this.recipeForDeletion = null; + return this.getList(); + }) + ); + } + }, + + recipeDeleteCancel() { + this.recipeForDeletion = null; + }, + getList: debounce(function() { - this.loadResource( + return this.loadResource( api.getRecipeList(this.search.page, this.search.per, this.search.sortColumn, this.search.sortDirection, this.search.name, this.search.tags, data => this.recipeData = data) ); }, 500, {leading: true, trailing: true}), diff --git a/app/javascript/components/UserLogin.vue b/app/javascript/components/UserLogin.vue index e1add90..12bf320 100644 --- a/app/javascript/components/UserLogin.vue +++ b/app/javascript/components/UserLogin.vue @@ -1,7 +1,7 @@