<commit_before>storeBackorderableState = (stockItemId) ->
  backorderableCheckbox = $("#backorderable-#{stockItemId}")
  backorderableCheckbox.parent('td').attr('was-checked', backorderableCheckbox.prop('checked'))

restoreBackorderableState = (stockItemId) ->
  backorderableCheckbox = $("#backorderable-#{stockItemId}")
  checked = backorderableCheckbox.parent('td').attr('was-checked') is "true"
  backorderableCheckbox.prop('checked', checked)

successHandler = (model, response, options) =>
  toggleBackorderable(model.get('id'), false)
  Spree.NumberFieldUpdater.successHandler(model.id, model.get('count_on_hand'))
  show_flash("success", Spree.translations.updated_successfully)

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

EditStockItemView = Backbone.View.extend
  events:
    "click .fa-edit":  "onEdit"
    "click .fa-check": "onSubmit"
    "click .fa-void":  "onCancel"

  onEdit: (ev) ->
    ev.preventDefault()
    @$('[name=backorderable]').prop('disabled', false)
    stockItemId = @model.id
    storeBackorderableState(stockItemId)
    Spree.NumberFieldUpdater.hideReadOnly(stockItemId)
    Spree.NumberFieldUpdater.showForm(stockItemId)

  onCancel: (ev) ->
    ev.preventDefault()
    @$('[name=backorderable]').prop('disabled', true)
    stockItemId = @model.id
    restoreBackorderableState(stockItemId)
    Spree.NumberFieldUpdater.hideForm(stockItemId)
    Spree.NumberFieldUpdater.showReadOnly(stockItemId)

  onSubmit: (ev) ->
    ev.preventDefault()
    stockItemId = @model.id
    stockLocationId = $(ev.currentTarget).data('location-id')
    backorderable = $("#backorderable-#{stockItemId}").prop("checked")
    countOnHand = parseInt($("#number-update-#{stockItemId} input[type='number']").val(), 10)

    @model.set
      count_on_hand: countOnHand
      backorderable: backorderable
    options =
      success: successHandler
      error: errorHandler
    @model.save(force: true, options)
<commit_msg>Move onSuccess into view<commit_after>storeBackorderableState = (stockItemId) ->
  backorderableCheckbox = $("#backorderable-#{stockItemId}")
  backorderableCheckbox.parent('td').attr('was-checked', backorderableCheckbox.prop('checked'))

restoreBackorderableState = (stockItemId) ->
  backorderableCheckbox = $("#backorderable-#{stockItemId}")
  checked = backorderableCheckbox.parent('td').attr('was-checked') is "true"
  backorderableCheckbox.prop('checked', checked)

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

EditStockItemView = Backbone.View.extend
  events:
    "click .fa-edit":  "onEdit"
    "click .fa-check": "onSubmit"
    "click .fa-void":  "onCancel"

  onEdit: (ev) ->
    ev.preventDefault()
    @$('[name=backorderable]').prop('disabled', false)
    stockItemId = @model.id
    storeBackorderableState(stockItemId)
    Spree.NumberFieldUpdater.hideReadOnly(stockItemId)
    Spree.NumberFieldUpdater.showForm(stockItemId)

  onCancel: (ev) ->
    ev.preventDefault()
    @$('[name=backorderable]').prop('disabled', true)
    stockItemId = @model.id
    restoreBackorderableState(stockItemId)
    Spree.NumberFieldUpdater.hideForm(stockItemId)
    Spree.NumberFieldUpdater.showReadOnly(stockItemId)

  onSuccess: ->
    @$('[name=backorderable]').prop('disabled', true)
    Spree.NumberFieldUpdater.successHandler(@model.id, @model.get('count_on_hand'))
    show_flash("success", Spree.translations.updated_successfully)

  onSubmit: (ev) ->
    ev.preventDefault()
    stockItemId = @model.id
    stockLocationId = $(ev.currentTarget).data('location-id')
    backorderable = $("#backorderable-#{stockItemId}").prop("checked")
    countOnHand = parseInt($("#number-update-#{stockItemId} input[type='number']").val(), 10)

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

{'fraction_non_alphanumeric': 0.14844736177732895, 'fraction_numerical': 0.001009845998485231, 'mean_word_length': 5.058103975535168, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3407317', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1285, 'n_words': 180}