diff --git a/app/assets/javascripts/orders.js.coffee b/app/assets/javascripts/orders.js.coffee index 64c204f..f901168 100644 --- a/app/assets/javascripts/orders.js.coffee +++ b/app/assets/javascripts/orders.js.coffee @@ -41,8 +41,8 @@ disIfNec = (row) -> $(row).find('.btn-inc').prop('disabled', counter == parseInt($(row).find('.row_counter').attr('max'))) recalculate = () -> - value = ($(row).find('.row_counter').val() * $(row).find('.price').val() for row in $('.form_row')).reduce (a, b) -> a+b - $('#order_price').val((value / 100.0).toFixed(2)) + value = ($(row).val() * $(row).data('price') for row in $('.row_counter')).reduce(((a, b) -> a+b), 0) + $('#order_price').html((value / 100.0).toFixed(2)) increment = (button, n) -> row = $(button).closest('.form_row') diff --git a/app/assets/stylesheets/orders.css.scss b/app/assets/stylesheets/orders.css.scss index 65c20d9..2583efa 100644 --- a/app/assets/stylesheets/orders.css.scss +++ b/app/assets/stylesheets/orders.css.scss @@ -55,3 +55,7 @@ } } } + +#order_price { + width: 50px; +} diff --git a/app/views/order_items/_order_item.html.erb b/app/views/order_items/_order_item.html.erb index 3f0fa03..cb417a5 100644 --- a/app/views/order_items/_order_item.html.erb +++ b/app/views/order_items/_order_item.html.erb @@ -12,10 +12,8 @@ <%= content_tag :span, product.name %> <%= content_tag :small, euro(product.price) %> - <%= f.counter :count, min: 0, max: product.stock, skip_label: true, wrapper_class: "input-group", class: "row_counter" %> + <%= f.counter :count, min: 0, max: product.stock, skip_label: true, wrapper_class: "input-group", class: "row_counter", data: { price: f.object.product.price_cents } %> <%= f.fields_for :product do |product| %> - <%= product.hidden_field :price_cents, class: :price %> - <%= product.hidden_field :stock, class: :stock %> <% end %> diff --git a/app/views/orders/_price.html.erb b/app/views/orders/_price.html.erb index 1c52486..9e59aaa 100644 --- a/app/views/orders/_price.html.erb +++ b/app/views/orders/_price.html.erb @@ -1,8 +1,8 @@
- <%= f.label :total_price %> + Total price
- <%= f.number_field :price, disabled: true, skip_label: true, step: :any, class: 'form-control big-form-field' %> + <%= content_tag :span, "", id: "order_price", class: "input-group-addon" %> <%= f.submit "Order!", class: "btn btn-primary big-form-button", skip_wrapper: true %>