Sha256: 70ebf8149d892cb2ebc8ed6ee14d1537dab7a49b3463cb789932fe177ed6920e

Contents?: true

Size: 1.82 KB

Versions: 20

Compression:

Stored size: 1.82 KB

Contents

$(document).ready(function() {
  var formFields = $("[data-hook='admin_customer_return_form_fields'], \
                     [data-hook='admin_return_authorization_form_fields']");

  if(formFields.length > 0) {
    function checkAddItemBox() {
      $(this).closest('tr').find('input.add-item').attr('checked', 'checked');
      updateSuggestedAmount();
    }

    function updateSuggestedAmount() {
      var totalPretaxRefund = 0;
      var checkedItems = formFields.find('input.add-item:checked');
      $.each(checkedItems, function(i, checkbox) {
        var returnItemRow  = $(checkbox).parents('tr'), returnQuantity, amount, purchasedQuantity;
        returnQuantity = parseInt(returnItemRow.find('.refund-quantity-input').val(), 10);
        purchasedQuantity = parseInt(returnItemRow.find('.purchased-quantity').text(), 10);
        amount = (returnQuantity / purchasedQuantity) * parseFloat(returnItemRow.find('.charged-amount').data('chargedAmount'));
        returnItemRow.find('.refund-amount-input').val(amount.toFixed(2));
        totalPretaxRefund += amount;
      });

      var displayTotal = isNaN(totalPretaxRefund) ? '' : totalPretaxRefund.toFixed(2);
      formFields.find('span#total_pre_tax_refund').html(displayTotal);
    }

    updateSuggestedAmount();

    formFields.find('input#select-all').on('change', function(ev) {
      var checkBoxes = $(ev.currentTarget).parents('table:first').find('input.add-item');
      checkBoxes.prop('checked', this.checked);
      updateSuggestedAmount();
    });

    formFields.find('input.add-item').on('change', updateSuggestedAmount);
    formFields.find('.refund-amount-input').on('keyup', updateSuggestedAmount);
    formFields.find('.refund-quantity-input').on('keyup mouseup', updateSuggestedAmount);

    formFields.find('input, select').not('.add-item').on('change', checkAddItemBox);
  }
});

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
spree_backend-3.4.6 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.6.6 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.6.5 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.6.4 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.6.3 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.6.2 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.6.1 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.6.0 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.5.0 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.6.0.rc1 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.5.0.rc2 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.5.0.rc1 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.4.5 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.4.4 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.4.3 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.4.2 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.4.1 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.4.0 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.4.0.rc2 app/assets/javascripts/spree/backend/returns/return_item_selection.js
spree_backend-3.4.0.rc1 app/assets/javascripts/spree/backend/returns/return_item_selection.js