From f230d390554ccd875d0f410b34f993600730849a Mon Sep 17 00:00:00 2001 From: Julius Date: Thu, 2 Jan 2014 21:59:08 +0100 Subject: [PATCH] Merge price columns in receive form into one Conflicts: app/views/orders/_edit_amount.html.haml --- app/helpers/orders_helper.rb | 5 +++ app/views/orders/_edit_amount.html.haml | 6 ++-- .../receive_on_order_article_update.js.erb | 35 ++++++++----------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 2d2a78fa..46f9b079 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -35,6 +35,11 @@ module OrdersHelper end end + def article_price_change_hint(order_article) + return nil if order_article.article.price == order_article.article_price.price + "".html_safe + end + def receive_input_field(form) order_article = form.object units_expected = (order_article.units_billed or order_article.units_to_order) diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 6aee7ed4..218316e6 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -7,7 +7,9 @@ %td= order_article.article.order_number %td.name{title: order_title.join("\n")}= order_article.article.name %td.unit= order_article.article.unit - %td.article_price= number_to_currency order_article.article.price + %td.article_price + = number_to_currency order_article.article.price + = article_price_change_hint(order_article) %td #{order_article.quantity} + #{order_article.tolerance} %td = order_article.units_to_order @@ -16,7 +18,7 @@ - unless order_article.units_billed.nil? = order_article.units_billed = pkg_helper order_article.article - %td + %td.units_received_cell = receive_input_field(form) = pkg_helper order_article.article_price, false - if order_article.result_manually_changed? diff --git a/app/views/orders/receive_on_order_article_update.js.erb b/app/views/orders/receive_on_order_article_update.js.erb index be58e641..003c79df 100644 --- a/app/views/orders/receive_on_order_article_update.js.erb +++ b/app/views/orders/receive_on_order_article_update.js.erb @@ -1,30 +1,25 @@ // Handle more advanced DOM update after AJAX database manipulation. // See publish/subscribe design pattern in /doc. (function(w) { - var order_article_entry = $('#order_article_<%= @order_article.id %>'); + // get old element and update the cell which is reused + var old_order_article_entry = $('#order_article_<%= @order_article.id %>'); - $('.name', order_article_entry).text( - '<%= j @order_article.article.name %>' - ); - - $('.unit', order_article_entry).text( - '<%= j @order_article.article.unit %>' - ); - - $('.article_unit_quantity', order_article_entry).text( - '(× <%= @order_article.article.unit_quantity %>)' - ); - - $('.article_price', order_article_entry).text( - '<%= j number_to_currency @order_article.article.price %>' - ); - - $('.article_price_unit_quantity', order_article_entry).text( + $('.article_price_unit_quantity', old_order_article_entry).text( '(× <%= @order_article.article_price.unit_quantity %>)' ); - $('.article_price_price', order_article_entry).text( - '<%= j number_to_currency @order_article.article_price.price %>' + // render new element and inject dynamic cell + var new_order_article_entry = $( + '<%= j render(partial: 'edit_amount', locals: {order_article: @order_article}) %>' ); + + $('td.units_received_cell', new_order_article_entry).replaceWith( + $('td.units_received_cell', old_order_article_entry) + ); + + // finally replace the OrderArticle entry + old_order_article_entry.replaceWith(new_order_article_entry); + + update_delta($('input.units_received', new_order_article_entry)); })(window);