diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index f70bec27..2a232a31 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -32,9 +32,9 @@ class StockitController < ApplicationController end def destroy - StockArticle.find(params[:id]).destroy - render :layout => false, - :locals => { :destroyed_article_id => params[:id] } + @article = StockArticle.find(params[:id]) + @article.destroy + render :layout => false rescue => error render :partial => "destroy_fail", :layout => false, :locals => { :fail_msg => "Ein Fehler ist aufgetreten: " + error.message } diff --git a/app/views/stockit/_destroy_fail.js.haml b/app/views/stockit/_destroy_fail.js.haml index 60b03d87..a9601900 100644 --- a/app/views/stockit/_destroy_fail.js.haml +++ b/app/views/stockit/_destroy_fail.js.haml @@ -1,7 +1,5 @@ --# 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}'); +-# please polish the following line if you know how, same in view destroy +var errorDiv = $('
x
'); +errorDiv.append(document.createTextNode('#{j(fail_msg)}')); $('div.container-fluid').prepend(errorDiv); diff --git a/app/views/stockit/destroy.js.haml b/app/views/stockit/destroy.js.haml index 39602dfb..66d6d70d 100644 --- a/app/views/stockit/destroy.js.haml +++ b/app/views/stockit/destroy.js.haml @@ -1 +1,14 @@ -console.log('#{destroyed_article_id}'); +-# please polish the following line if you know how, same in partial _destroy_fail +var successDiv = $('
x
'); + +successDiv.append(document.createTextNode('Artikel #{j(@article.name)} gelöscht.')); +$('div.container-fluid').prepend(successDiv); + +-# WARNING: If you try to use the escape j(...) here, an error occurs: +-# Ein Fehler ist aufgetreten: undefined method `gsub' for 50:Fixnum +-# However, it should work without without escaping. +-# Note that article names which are purely numeric, e.g. 12345, are escaped correctly (see above). + +$('#stockArticle-#{@article.id}').remove(); + +-# WARNING: Do not use a simple .fadeOut() above, because it conflicts with the show/hide function of unavailable articles. diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index 6ceb0e91..c69c1689 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -44,7 +44,7 @@ %th %tbody - for article in @stock_articles - %tr{:class => stock_article_classes(article)} + %tr{:class => stock_article_classes(article), :id => "stockArticle-#{article.id}"} %td=h article.name %td= article.quantity %td= article.quantity - article.quantity_available