tap/app/assets/javascripts/orders.js.coffee

26 lines
797 B
CoffeeScript
Raw Normal View History

2014-11-06 17:56:00 +00:00
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
2014-12-04 16:02:08 +00:00
ready = ->
$('.btn-inc').on 'click', ->
2014-12-09 08:43:21 +00:00
increment(this, 1)
2014-12-04 16:02:08 +00:00
$('.btn-dec').on 'click', ->
2014-12-09 08:43:21 +00:00
increment(this, -1)
increment = (button, n) ->
counter = $(button).closest('.form_row').find('.row_counter')
newCount = parseInt(counter.val()) + n
counter.val(Math.max(newCount, 0))
calculatePrice()
calculatePrice = ->
price = 0
$('#form_products').children().each(->
price += parseInt($(this).find('.price').html()) * parseInt($(this).find('.row_counter').val())
)
$('#order_total_price').val(price)
2014-12-04 16:02:08 +00:00
$(document).ready(ready)
$(document).on('page:load', ready)