Sha256: 98682d5631f099823329a5b3433d2671980bb22c72499956d661bc891590317d

Contents?: true

Size: 1.5 KB

Versions: 49

Compression:

Stored size: 1.5 KB

Contents

editing = (e) ->
  e.preventDefault()
  $(e.delegateTarget).addClass('editing')

editingDone = (e) ->
  e.preventDefault()
  $(e.delegateTarget).removeClass('editing')

onSaveLineItem = (e) ->
  e.preventDefault()
  line_item = $(this).closest('.line-item')
  line_item_id = line_item.data('line-item-id')
  quantity = parseInt(line_item.find('input.line_item_quantity').val())
  adjustLineItem(line_item_id, quantity)
  editingDone(e)

onDeleteLineItem = (e) ->
  e.preventDefault()
  return unless confirm(Spree.translations.are_you_sure_delete)
  line_item = $(this).closest('.line-item')
  line_item_id = line_item.data('line-item-id');
  deleteLineItem(line_item_id)
  editingDone(e)

$(document).ready ->
  $('.line-item')
    .on('click', '.edit-line-item',   editing)
    .on('click', '.cancel-line-item', editingDone)
    .on('click', '.save-line-item',   onSaveLineItem)
    .on('click', '.delete-line-item', onDeleteLineItem)

lineItemURL = (id) ->
  "#{Spree.routes.line_items_api(order_number)}/#{id}.json"

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

deleteLineItem = (line_item_id) ->
  url = lineItemURL(line_item_id)
  Spree.ajax(
    type: "DELETE"
    url: url
  ).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

49 entries across 49 versions & 1 rubygems

Version Path
solidus_backend-2.1.1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.0.3 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.4.2 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.3.2 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.2.3 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.1.4 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.0.7 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.0.2 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.4.1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.1.0 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.1.0.rc1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.0.1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.1.0.beta1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.0.0 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.4.0 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.0.0.rc1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.4.0.rc1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-2.0.0.beta1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.4.0.beta1 app/assets/javascripts/spree/backend/line_items.js.coffee
solidus_backend-1.3.1 app/assets/javascripts/spree/backend/line_items.js.coffee