Sha256: 3da32ad6d89e45c4c4fd122549ef57fab2864e8c9288a6c01099abd855c3e93d

Contents?: true

Size: 1.59 KB

Versions: 17

Compression:

Stored size: 1.59 KB

Contents

errorHandler = (model, response, options) ->
  show_flash("error", response.responseText)

Spree.EditStockItemView = Backbone.View.extend
  tagName: 'tr'

  initialize: (options) ->
    @stockLocationName = options.stockLocationName
    @editing = false
    @render()

  events:
    "click .edit": "onEdit"
    "click .submit": "onSubmit"
    "click .cancel": "onCancel"

  template: HandlebarsTemplates['stock_items/stock_location_stock_item']

  render: ->
    renderAttr =
      stockLocationName: @stockLocationName
      editing: @editing
    _.extend(renderAttr, @model.attributes)

    @$el.attr("data-variant-id", @model.get('variant_id'))
    @$el.html(@template(renderAttr))

    return @

  onEdit: (ev) ->
    ev.preventDefault()
    @editing = true
    @render()

  onCancel: (ev) ->
    ev.preventDefault()
    @model.set(@model.previousAttributes())
    @editing = false
    @render()

  onSuccess: ->
    @editing = false
    @render()
    show_flash("success", Spree.translations.updated_successfully)

  onSubmit: (ev) ->
    ev.preventDefault()
    backorderable = @$('[name=backorderable]').prop("checked")
    countOnHand = parseInt($("input[name='count_on_hand']").val(), 10)

    @model.set
      count_on_hand: countOnHand
      backorderable: backorderable
    options =
      success: => @onSuccess()
      error: errorHandler
    @model.save(force: true, options)

$ ->
  $('.js-edit-stock-item').each ->
    $el = $(this)
    model = new Spree.StockItem($el.data('stock-item'))
    new Spree.EditStockItemView
      el: $el
      stockLocationName: $el.data('stock-location-name')
      model: model

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
solidus_backend-2.0.3 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.4.2 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.3.2 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.0.2 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.4.1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.0.1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.0.0 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.4.0 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.0.0.rc1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.4.0.rc1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.0.0.beta1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.4.0.beta1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.3.1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.3.0 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.3.0.rc2 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.3.0.rc1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-1.3.0.beta1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee