Apply publish/subscribe for OrderArticle#update

This commit is contained in:
Julius 2013-12-30 13:09:49 +01:00 committed by wvengen
parent 27a73be68f
commit 81dfe8110c
6 changed files with 46 additions and 4 deletions

View file

@ -29,6 +29,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_update # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
end
def update_summary def update_summary
@order = Order.find(params[:id]) @order = Order.find(params[:id])

View file

@ -1,3 +1,18 @@
- content_for :javascript do
:javascript
$(function() {
// Subscribe to database changes.
// See publish/subscribe design pattern in /doc.
$(document).on('OrderArticle#update', function(e) {
$.ajax({
url: '#{new_on_order_article_update_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)
- content_for :sidebar do - content_for :sidebar do

View file

@ -0,0 +1,14 @@
// Handle more advanced DOM update after AJAX database manipulation.
// See publish/subscribe design pattern in /doc.
(function(w) {
$('#order_article_<%= @order_article.id %>').html(
'<%= j render('finance/balancing/order_article', order_article: @order_article) %>'
);
$('#group_order_articles_<%= @order_article.id %>').html(
'<%= j render('finance/balancing/group_order_articles', 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#update',
order_article_id: <%= @order_article.id %>
});
$('#modalContainer').modal('hide');

View file

@ -1,4 +0,0 @@
$('#modalContainer').modal('hide');
$('#order_article_#{@order_article.id}').html('#{j(render('finance/balancing/order_article', order_article: @order_article))}');
$('#group_order_articles_#{@order_article.id}').html('#{j(render('finance/balancing/group_order_articles', order_article: @order_article))}');
$('#summaryChangedWarning').show();

View file

@ -145,6 +145,8 @@ Foodsoft::Application.routes.draw do
get :confirm get :confirm
put :close put :close
put :close_direct put :close_direct
get :new_on_order_article_update
end end
resources :order_articles resources :order_articles