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

25 lines
848 B
CoffeeScript
Raw Normal View History

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-10 00:38:48 +01:00
increment($(this), 1)
2014-12-04 17:02:08 +01:00
$('.btn-dec').on 'click', ->
2014-12-10 00:38:48 +01:00
increment($(this), -1)
2014-12-09 09:43:21 +01:00
increment = (button, n) ->
2014-12-10 00:38:48 +01:00
# Fix the counter
2014-12-09 09:43:21 +01:00
counter = $(button).closest('.form_row').find('.row_counter')
2014-12-10 00:38:48 +01:00
counter.val(parseInt(counter.val()) + n)
# Enable or disable the dec button
counter.parent().find('.btn-dec').prop("disabled", counter.val() == '0');
2014-12-09 09:43:21 +01:00
2014-12-10 00:38:48 +01:00
# Update the price
oldVal = parseFloat($('#order_total_price').val())
$('#order_total_price').val(parseFloat(oldVal + counter.parent().find('.price').val() * n).toFixed(2))
2014-12-04 17:02:08 +01:00
$(document).ready(ready)
$(document).on('page:load', ready)