<commit_before>class Middleware.Component.JsonForm extends Middleware.System.Base
  constructor: (@container) ->
    super(@container)
    @initForm()

  initForm: =>
    if @container.propName("tagName") == "FORM"
      @form = @container
    else
      @form = @container.find("form")

    @setCompletedStatusName()

    @form.on "ajax:success",      @createResponse
    @form.on "request:completed", @completeForm
    @form.on "request:failed",    @updateForm
    @form.on "request:cancel",    @cancelForm

    @submitButton = @form.find("*[data-action='submit']")
    @submitButton.on "click", =>
      @form.trigger("submit.rails")

    @form.find("input").keypress (e) ->
      if e.which == 13
        @form.trigger("submit.rails")
        e.preventDefault()

    @cancelButoon = @form.find("*[data-action='cancel']")
    @cancelButton.on "click", =>
      @form.trigger("request:cancel")

  setCompletedStatusName: (status_name = "completed") =>
    @completedStatusName = status_name

  createResponse: (event, json) =>
    if json[@completedStatusName] == true
      @form.trigger("request:completed", json)
    else
      @form.trigger("request:failed", json)

  completeForm: (event, json) =>
<commit_msg>Update json_form.js.coffee<commit_after>class Middleware.Component.JsonForm extends Middleware.System.Base
  constructor: (@container) ->
    super(@container)
    @initForm()

  initForm: =>
    if @container.propName("tagName") == "FORM"
      @form = @container
    else
      @form = @container.find("form")

    @setCompletedStatusName()

    @form.on "ajax:success",      @createResponse
    @form.on "request:completed", @completeForm
    @form.on "request:failed",    @updateForm
    @form.on "request:cancel",    @cancelForm

    @submitButton = @form.find("*[data-action='submit']")
    @submitButton.on "click", =>
      @form.trigger("submit.rails")

    @form.find("input").keypress (e) =>
      if e.which == 13
        @form.trigger("submit.rails")
        e.preventDefault()

    @cancelButoon = @form.find("*[data-action='cancel']")
    @cancelButton.on "click", =>
      @form.trigger("request:cancel")

  setCompletedStatusName: (status_name = "completed") =>
    @completedStatusName = status_name

  createResponse: (event, json) =>
    if json[@completedStatusName] == true
      @form.trigger("request:completed", json)
    else
      @form.trigger("request:failed", json)

  completeForm: (event, json) =>

{'fraction_non_alphanumeric': 0.1634654679199019, 'fraction_numerical': 0.0016346546791990192, 'mean_word_length': 3.541743970315399, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '2143519', 'n_tokens_mistral': 782, 'n_tokens_neox': 746, 'n_words': 133}