diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index d555b4c3..36254f10 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -33,10 +33,11 @@ class StockitController < ApplicationController def destroy StockArticle.find(params[:id]).destroy - redirect_to stock_articles_path + render :layout => false, + :locals => { :destroyed_article_id => params[:id] } rescue => error - flash[:error] = "Ein Fehler ist aufgetreten: " + error.message - redirect_to stock_articles_path + render :partial => "destroy_fail", :layout => false, + :locals => { :fail_msg => "Ein Fehler ist aufgetreten: " + error.message } end #TODO: Fix this!! diff --git a/app/views/stockit/_destroy_fail.js.haml b/app/views/stockit/_destroy_fail.js.haml new file mode 100644 index 00000000..60b03d87 --- /dev/null +++ b/app/views/stockit/_destroy_fail.js.haml @@ -0,0 +1,7 @@ +-# please polish the following line if you know how +var errorDiv = $('
'); + +-# next line, createTextNode called by .text(textString) helps escaping for html, but what about ' signs? +errorDiv.text('#{fail_msg}'); + +$('div.container-fluid').prepend(errorDiv); diff --git a/app/views/stockit/destroy.js.haml b/app/views/stockit/destroy.js.haml new file mode 100644 index 00000000..39602dfb --- /dev/null +++ b/app/views/stockit/destroy.js.haml @@ -0,0 +1 @@ +console.log('#{destroyed_article_id}'); diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index 89063bd7..b84b4f4f 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -64,8 +64,7 @@ %td= article.article_category.name %td = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' - = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", - class: 'btn btn-mini btn-danger' + = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", class: 'btn btn-mini btn-danger', :remote => true .form-actions.unavailable = submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } %p