Sha256: 068e6af8eb96d901804b1ad5dab240f0f6c44048480460a1130c05a28e339ae1

Contents?: true

Size: 1.81 KB

Versions: 60

Compression:

Stored size: 1.81 KB

Contents

class CountUpdateForms
  @beginListening: (isReceiving) ->
    # Edit
    $('body').on 'click', '#listing_transfer_items .fa-edit', (ev) =>
      ev.preventDefault()
      transferItemId = $(ev.currentTarget).data('id')
      Spree.NumberFieldUpdater.hideReadOnly(transferItemId)
      Spree.NumberFieldUpdater.showForm(transferItemId)

    # Cancel
    $('body').on 'click', '#listing_transfer_items .fa-void', (ev) =>
      ev.preventDefault()
      transferItemId = $(ev.currentTarget).data('id')
      Spree.NumberFieldUpdater.hideForm(transferItemId)
      Spree.NumberFieldUpdater.showReadOnly(transferItemId)

    # Submit
    $('body').on 'click', '#listing_transfer_items .fa-check', (ev) =>
      ev.preventDefault()
      transferItemId = $(ev.currentTarget).data('id')
      stockTransferNumber = $("#stock_transfer_number").val()
      quantity = parseInt($("#number-update-#{transferItemId} input[type='number']").val(), 10)

      itemAttributes =
        id: transferItemId
        stockTransferNumber: stockTransferNumber
      quantityKey = if isReceiving then 'receivedQuantity' else 'expectedQuantity'
      itemAttributes[quantityKey] = quantity
      transferItem = new Spree.TransferItem(itemAttributes)
      transferItem.update(successHandler, errorHandler)

  successHandler = (transferItem) =>
    if $('#received-transfer-items').length > 0
      Spree.NumberFieldUpdater.successHandler(transferItem.id, transferItem.received_quantity)
      Spree.StockTransfers.ReceivedCounter.updateTotal()
    else
      Spree.NumberFieldUpdater.successHandler(transferItem.id, transferItem.expected_quantity)
    show_flash("success", Spree.translations.updated_successfully)

  errorHandler = (errorData) =>
    show_flash("error", errorData.responseText)

Spree.StockTransfers ?= {}
Spree.StockTransfers.CountUpdateForms = CountUpdateForms

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
solidus_backend-2.3.1 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.2.2 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.1.1 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.0.3 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-1.4.2 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-1.3.2 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-1.2.3 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-1.1.4 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-1.0.7 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.3.0 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.3.0.rc3 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.3.0.rc2 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.3.0.rc1 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.3.0.beta1 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.0.2 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-1.4.1 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.2.1 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.2.0 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.2.0.rc1 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
solidus_backend-2.2.0.beta1 app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee