Sha256: c0bd690c64bd9790a202e411369ea7789d4a33845db7f1ae5ce5dd16bd50dc96

Contents?: true

Size: 1.76 KB

Versions: 44

Compression:

Stored size: 1.76 KB

Contents

$(document).ready ->
  #handle edit click
  $('a.edit-line-item').click toggleLineItemEdit

  #handle cancel click
  $('a.cancel-line-item').click toggleLineItemEdit

  #handle save click
  $('a.save-line-item').click ->
    save = $ this
    line_item_id = save.data('line-item-id')
    quantity = parseInt(save.parents('tr').find('input.line_item_quantity').val())

    toggleItemEdit()
    adjustLineItem(line_item_id, quantity)
    false

  # handle delete click
  $('a.delete-line-item').click ->
    if confirm(Spree.translations.are_you_sure_delete)
      del = $(this);
      line_item_id = del.data('line-item-id');

      toggleItemEdit()
      deleteLineItem(line_item_id)

toggleLineItemEdit = ->
  link = $(this);
  link.parent().find('a.edit-line-item').toggle();
  link.parent().find('a.cancel-line-item').toggle();
  link.parent().find('a.save-line-item').toggle();
  link.parent().find('a.delete-line-item').toggle();
  link.parents('tr').find('td.line-item-qty-show').toggle();
  link.parents('tr').find('td.line-item-qty-edit').toggle();

  false

lineItemURL = (line_item_id) ->
  url = Spree.routes.orders_api + "/" + order_number + "/line_items/" + line_item_id + ".json"

adjustLineItem = (line_item_id, quantity) ->
  url = lineItemURL(line_item_id)
  $.ajax(
    type: "PUT",
    url: Spree.url(url),
    data:
      line_item:
        quantity: quantity
      token: Spree.api_key
  ).done (msg) ->
    window.Spree.advanceOrder()

deleteLineItem = (line_item_id) ->
  url = lineItemURL(line_item_id)
  $.ajax(
    type: "DELETE"
    url: Spree.url(url)
    headers:
      'X-Spree-Token': Spree.api_key
  ).done (msg) ->
    $('#line-item-' + line_item_id).remove()
    if $('.line-items tr.line-item').length == 0
      $('.line-items').remove()
    window.Spree.advanceOrder()

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
spree_backend-3.4.6 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.2.9 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.6.6 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.6.5 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.6.4 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.6.3 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.6.2 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.6.1 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.6.0 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.5.0 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.3.6 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.2.8 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.6.0.rc1 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.5.0.rc2 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.5.0.rc1 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.4.5 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.3.5 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.4.4 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.4.3 app/assets/javascripts/spree/backend/line_items.js.coffee
spree_backend-3.3.4 app/assets/javascripts/spree/backend/line_items.js.coffee