Improve delivery validation: StockArticles must not be associated more than once

This commit is contained in:
Julius 2013-06-26 17:56:20 +02:00
parent 5df4c8f8a6
commit 2ee7f716ae
7 changed files with 55 additions and 25 deletions

View file

@ -1,13 +1,5 @@
(function(w) {
if(is_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>)) {
return false;
}
mark_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>);
var quantity = w.prompt('<%= j(t('.how_many_units', :unit => @stock_change.stock_article.unit, :name => @stock_change.stock_article.name)) %>'); <%# how to properly escape here? %>
if(null === quantity) {
unmark_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>); // think wisely before changing this: What about double clicks on "deliver" button?
if(!is_article_available_for_delivery(<%= @stock_change.stock_article.id %>)) {
return false;
}
@ -17,8 +9,16 @@
'<%= j(render(:partial => 'stock_change', :locals => {:stock_change => @stock_change})) %>'
).addClass('success');
$('#stock_changes').append(stock_change);
mark_article_for_delivery(<%= @stock_change.stock_article.id %>);
updateSort('#stock_changes');
var quantity = w.prompt('<%= j(t('.how_many_units', :unit => @stock_change.stock_article.unit, :name => @stock_change.stock_article.name)) %>'); <%# how to properly escape here? %>
if(null === quantity) {
stock_change.remove();
mark_article_for_delivery(<%= @stock_change.stock_article.id %>);
return false;
}
$('input.stock-change-quantity', stock_change).val(quantity);
$('#stock_changes').append(stock_change);
updateSort('#stock_changes');
})(window);