Apply publish/subscribe for OrderArticle#create

This commit is contained in:
Julius 2013-12-31 13:25:29 +01:00 committed by wvengen
parent 5349ee142e
commit 59c118a171
6 changed files with 35 additions and 3 deletions

View file

@ -30,6 +30,12 @@ class Finance::BalancingController < Finance::BaseController
render layout: false if request.xhr? render layout: false if request.xhr?
end end
def new_on_order_article_create # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
end
def new_on_order_article_update # See publish/subscribe design pattern in /doc. def new_on_order_article_update # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id]) @order_article = OrderArticle.find(params[:order_article_id])

View file

@ -11,6 +11,15 @@
contentType: 'application/json; charset=UTF-8' contentType: 'application/json; charset=UTF-8'
}); });
}); });
$(document).on('OrderArticle#create', function(e) {
$.ajax({
url: '#{new_on_order_article_create_finance_order_path(@order)}',
type: 'get',
data: {order_article_id: e.order_article_id},
contentType: 'application/json; charset=UTF-8'
});
});
}); });
- title t('.title', name: @order.name) - title t('.title', name: @order.name)

View file

@ -0,0 +1,10 @@
// Handle more advanced DOM update after AJAX database manipulation.
// See publish/subscribe design pattern in /doc.
(function(w) {
$('#result_table').prepend(
'<%= j render('finance/balancing/order_article_result', order_article: @order_article) %>'
);
$('#summaryChangedWarning').show();
})(window);

View file

@ -0,0 +1,9 @@
// Publish database changes.
// See publish/subscribe design pattern in /doc.
$(document).trigger({
type: 'OrderArticle#create',
order_article_id: <%= @order_article.id %>
});
$('#modalContainer').modal('hide');

View file

@ -1,3 +0,0 @@
$('#modalContainer').modal('hide');
$('#result_table').prepend('#{j(render('finance/balancing/order_article_result', order_article: @order_article))}');
$('#summaryChangedWarning').show();

View file

@ -150,6 +150,7 @@ Foodsoft::Application.routes.draw do
put :close put :close
put :close_direct put :close_direct
get :new_on_order_article_create
get :new_on_order_article_update get :new_on_order_article_update
end end
end end