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

25 lines
848 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 23:38:48 +00:00
increment($(this), 1)
2014-12-04 16:02:08 +00:00
$('.btn-dec').on 'click', ->
2014-12-09 23:38:48 +00:00
increment($(this), -1)
2014-12-09 08:43:21 +00:00
increment = (button, n) ->
2014-12-09 23:38:48 +00:00
# Fix the counter
2014-12-09 08:43:21 +00:00
counter = $(button).closest('.form_row').find('.row_counter')
2014-12-09 23:38:48 +00: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 08:43:21 +00:00
2014-12-09 23:38:48 +00: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 16:02:08 +00:00
$(document).ready(ready)
$(document).on('page:load', ready)