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?
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
@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)
- 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
put :close
put :close_direct
get :new_on_order_article_update
end
resources :order_articles