Improve (AJAX) deletion of StockArticles

This commit is contained in:
Julius 2013-02-25 11:12:28 +01:00
parent 5dc3fc30ad
commit 0e1bd5c75e
4 changed files with 21 additions and 10 deletions

View file

@ -32,9 +32,9 @@ class StockitController < ApplicationController
end end
def destroy def destroy
StockArticle.find(params[:id]).destroy @article = StockArticle.find(params[:id])
render :layout => false, @article.destroy
:locals => { :destroyed_article_id => params[:id] } render :layout => false
rescue => error rescue => error
render :partial => "destroy_fail", :layout => false, render :partial => "destroy_fail", :layout => false,
:locals => { :fail_msg => "Ein Fehler ist aufgetreten: " + error.message } :locals => { :fail_msg => "Ein Fehler ist aufgetreten: " + error.message }

View file

@ -1,7 +1,5 @@
-# please polish the following line if you know how -# please polish the following line if you know how, same in view destroy
var errorDiv = $('<div class="alert fade in alert-error"><a class="close" data-dismiss="alert" href="#">×</a></div>'); var errorDiv = $('<div class="alert fade in alert-error"><a class="close" data-dismiss="alert" href="#">x</a></div>');
-# next line, createTextNode called by .text(textString) helps escaping for html, but what about ' signs?
errorDiv.text('#{fail_msg}');
errorDiv.append(document.createTextNode('#{j(fail_msg)}'));
$('div.container-fluid').prepend(errorDiv); $('div.container-fluid').prepend(errorDiv);

View file

@ -1 +1,14 @@
console.log('#{destroyed_article_id}'); -# please polish the following line if you know how, same in partial _destroy_fail
var successDiv = $('<div class="alert fade in alert-success"><a class="close" data-dismiss="alert" href="#">x</a></div>');
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.

View file

@ -44,7 +44,7 @@
%th %th
%tbody %tbody
- for article in @stock_articles - 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=h article.name
%td= article.quantity %td= article.quantity
%td= article.quantity - article.quantity_available %td= article.quantity - article.quantity_available