diff --git a/app/assets/javascripts/orders.js.coffee b/app/assets/javascripts/orders.js.coffee index 1a92dfe..c881b24 100644 --- a/app/assets/javascripts/orders.js.coffee +++ b/app/assets/javascripts/orders.js.coffee @@ -3,23 +3,23 @@ # You can use CoffeeScript in this file: http://coffeescript.org/ ready = -> $('.btn-inc').on 'click', -> - increment(this, 1) + increment($(this), 1) $('.btn-dec').on 'click', -> - increment(this, -1) + increment($(this), -1) + increment = (button, n) -> + # Fix the counter counter = $(button).closest('.form_row').find('.row_counter') - newCount = parseInt(counter.val()) + n - counter.val(Math.max(newCount, 0)) - calculatePrice() + counter.val(parseInt(counter.val()) + n) -calculatePrice = -> - price = 0 - $('#form_products').children().each(-> - price += parseInt($(this).find('.price').html()) * parseInt($(this).find('.row_counter').val()) - ) - $('#order_total_price').val(price) + # Enable or disable the dec button + counter.parent().find('.btn-dec').prop("disabled", counter.val() == '0'); + + # Update the price + oldVal = parseFloat($('#order_total_price').val()) + $('#order_total_price').val(parseFloat(oldVal + counter.parent().find('.price').val() * n).toFixed(2)) $(document).ready(ready) $(document).on('page:load', ready) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index c67ef86..fbd81aa 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -28,11 +28,6 @@ $gray-medium-light: #eaeaea; box-sizing: border-box; } - -.thumbnail { - height: 150px; -} - /* miscellaneous */ .nowrap { white-space: nowrap; diff --git a/app/assets/stylesheets/orders.css.scss b/app/assets/stylesheets/orders.css.scss index 7150136..7415069 100644 --- a/app/assets/stylesheets/orders.css.scss +++ b/app/assets/stylesheets/orders.css.scss @@ -1,16 +1,3 @@ // Place all the styles related to the Orders controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ - -.form_products { - border-width: 1px; - border-color: #000; - border-style: solid; - margin-bottom: 2px; -} - -.form_total { - border-width: 1px; - border-color: #000; - border-style: solid; -} diff --git a/app/views/order_products/_form_row.html.erb b/app/views/order_products/_form_row.html.erb index d70f60c..33ddf71 100644 --- a/app/views/order_products/_form_row.html.erb +++ b/app/views/order_products/_form_row.html.erb @@ -1,10 +1,19 @@ -