diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index a0f354b2..61f73cef 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -30,6 +30,12 @@ class Finance::BalancingController < Finance::BaseController render layout: false if request.xhr? 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. @order_article = OrderArticle.find(params[:order_article_id]) diff --git a/app/views/finance/balancing/new.html.haml b/app/views/finance/balancing/new.html.haml index 52828947..f98840d1 100644 --- a/app/views/finance/balancing/new.html.haml +++ b/app/views/finance/balancing/new.html.haml @@ -11,6 +11,15 @@ 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) diff --git a/app/views/finance/balancing/new_on_order_article_create.js.erb b/app/views/finance/balancing/new_on_order_article_create.js.erb new file mode 100644 index 00000000..98dc223e --- /dev/null +++ b/app/views/finance/balancing/new_on_order_article_create.js.erb @@ -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); + diff --git a/app/views/order_articles/create.js.erb b/app/views/order_articles/create.js.erb new file mode 100644 index 00000000..ff77ce89 --- /dev/null +++ b/app/views/order_articles/create.js.erb @@ -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'); + diff --git a/app/views/order_articles/create.js.haml b/app/views/order_articles/create.js.haml deleted file mode 100644 index cc43206e..00000000 --- a/app/views/order_articles/create.js.haml +++ /dev/null @@ -1,3 +0,0 @@ -$('#modalContainer').modal('hide'); -$('#result_table').prepend('#{j(render('finance/balancing/order_article_result', order_article: @order_article))}'); -$('#summaryChangedWarning').show(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 46b4a12b..f395252b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -150,6 +150,7 @@ Foodsoft::Application.routes.draw do put :close put :close_direct + get :new_on_order_article_create get :new_on_order_article_update end end