Sha256: 7aa38f676d005217a9e0184200b29be74d0f943091685cf06fcf39351356a7c3
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
class @DynamicOrder @refresh_trigger_attributes = ['price', 'quantity', 'payment_fee', 'shipment_fee'] constructor: (@options = {}) -> @options['order_item_selector'] = '.comable-order-items' unless @options['order_item_selector'] @listen_events() listen_events: -> self = this $(document).on('change', 'input', -> attribute_name = $(this).attr('data-name') return unless jQuery.inArray(attribute_name, self.refresh_trigger_attributes) self.refresh_order_item_prices_for(this) ) refresh_order_item_prices_for: (element) -> $group = $(element).closest(@options['order_item_selector']) $price = $group.find('[data-name="price"]') $quantity = $group.find('[data-name="quantity"]') $subtotal_price = $group.find('[data-name="subtotal-price"]') price = Number($price.val()) quantity = Number($quantity.val()) $subtotal_price.val(price * quantity) @refresh_order_prices() refresh_order_prices: -> item_total_price = 0 $('[data-name="subtotal-price"]').each( -> item_total_price += Number($(this).val()) ) $item_total_price = $('[data-name="item-total-price"]') $payment_fee = $('[data-name="payment-fee"]') $shipment_fee = $('[data-name="shipment-fee"]') $total_price = $('[data-name="total-price"]') payment_fee = Number($payment_fee.val()) shipment_fee = Number($shipment_fee.val()) $item_total_price.val(item_total_price) $total_price.val(item_total_price + payment_fee + shipment_fee)
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
comable-backend-0.7.1 | app/assets/javascripts/comable/admin/dynamic_order.coffee |
comable-backend-0.7.0 | app/assets/javascripts/comable/admin/dynamic_order.coffee |