2014-11-06 18:56:00 +01: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 17:02:08 +01:00
|
|
|
ready = ->
|
|
|
|
$('.btn-inc').on 'click', ->
|
2014-12-09 09:43:21 +01:00
|
|
|
increment(this, 1)
|
2014-12-04 17:02:08 +01:00
|
|
|
|
|
|
|
$('.btn-dec').on 'click', ->
|
2014-12-09 09:43:21 +01: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 17:02:08 +01:00
|
|
|
|
|
|
|
$(document).ready(ready)
|
|
|
|
$(document).on('page:load', ready)
|