Sha256: 6af5a46a61a266bb841d0401c0f67bbeb35c2ed7c9c82cdc51dd5f26e03bca37

Contents?: true

Size: 1.59 KB

Versions: 20

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

20 entries across 20 versions & 1 rubygems

Version Path
solidus_backend-2.4.2 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.4.1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.3.1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.2.2 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.1.1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.4.0 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.4.0.rc1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.4.0.beta1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.3.0 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.3.0.rc3 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.3.0.rc2 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.3.0.rc1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.3.0.beta1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.2.1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.2.0 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.2.0.rc1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.2.0.beta1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.1.0 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.1.0.rc1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee
solidus_backend-2.1.0.beta1 app/assets/javascripts/spree/backend/stock_management/index_update_forms.coffee