Apply AJAX for deleting a StockArticle

This commit is contained in:
Julius 2013-02-25 10:02:21 +01:00
parent a511da9ae3
commit ccf0d010b4
4 changed files with 13 additions and 5 deletions

View file

@ -33,10 +33,11 @@ class StockitController < ApplicationController
def destroy def destroy
StockArticle.find(params[:id]).destroy StockArticle.find(params[:id]).destroy
redirect_to stock_articles_path render :layout => false,
:locals => { :destroyed_article_id => params[:id] }
rescue => error rescue => error
flash[:error] = "Ein Fehler ist aufgetreten: " + error.message render :partial => "destroy_fail", :layout => false,
redirect_to stock_articles_path :locals => { :fail_msg => "Ein Fehler ist aufgetreten: " + error.message }
end end
#TODO: Fix this!! #TODO: Fix this!!

View file

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

View file

@ -0,0 +1 @@
console.log('#{destroyed_article_id}');

View file

@ -64,8 +64,7 @@
%td= article.article_category.name %td= article.article_category.name
%td %td
= link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini'
= link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", class: 'btn btn-mini btn-danger', :remote => true
class: 'btn btn-mini btn-danger'
.form-actions.unavailable .form-actions.unavailable
= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } = submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' }
%p %p