<commit_before>
namespace "Bixby.view.monitoring", (exports, top) ->

  class exports.CheckEditor extends Stark.View

    tagName: "div"
    className: "modal check_editor"
    template: "monitoring/_check_editor"

    events:
      # save
      "click button.save": (e) ->
        @save_edits()

      # delete
      "click button.delete": (e) ->
        @hide_editor()
        v = @
        v.check.destroy()
        v.hide_editor()
        v.parent.parent.redraw()

      # save (on enter)
      "keyup input.alias": (e) ->
        if e.keyCode == 13
          e.preventDefault()
          @save_edits()

    show: ->
      @$el.modal("show")

    hide_editor: ->
      @$el.modal("hide")

    save_edits: ->
      command = @commands.get(@check.get("command_id"))

      args = {}

      _.each command.get("options"), (opt_hash, opt_key) ->
        args[opt_key] = @$("input##{opt_key}").val()

      # set runhost if exists
      if @$("#runhost").length > 0
        @check.set { agent_id: @$("#runhost").val() }
        # this is a workaround because the .set below clears the change event, see here: http://stackoverflow.com/questions/5072435/backbone-js-not-registering-model-haschanged-event
        if @check.hasChanged()
          @check.save()

      @check.set {
          args: args
      }
<commit_msg>for checks that have runhost field added some logic that will only get run if its needed and won't screw up the save when the runhost field doesn't exist and/or doesn't change value<commit_after>
namespace "Bixby.view.monitoring", (exports, top) ->

  class exports.CheckEditor extends Stark.View

    tagName: "div"
    className: "modal check_editor"
    template: "monitoring/_check_editor"

    events:
      # save
      "click button.save": (e) ->
        @save_edits()

      # delete
      "click button.delete": (e) ->
        @hide_editor()
        v = @
        v.check.destroy()
        v.hide_editor()
        v.parent.parent.redraw()

      # save (on enter)
      "keyup input.alias": (e) ->
        if e.keyCode == 13
          e.preventDefault()
          @save_edits()

    show: ->
      @$el.modal("show")

    hide_editor: ->
      @$el.modal("hide")

    save_edits: ->
      command = @commands.get(@check.get("command_id"))

      args = {}

      _.each command.get("options"), (opt_hash, opt_key) ->
        args[opt_key] = @$("input##{opt_key}").val()

      @check.set {
          args: args
      }

      # set runhost if exists
      if @$("#runhost").length > 0

        if @check.get("agent_id") != parseInt(@$("#runhost").val())
          @check.set { agent_id: @$("#runhost").val() }
          # this is a workaround because the .set below clears the change event, see here:
          # http://stackoverflow.com/questions/5072435/backbone-js-not-registering-model-haschanged-event
          if @check.hasChanged()
            @check.save()
            @hide_editor()
            @parent.parent.redraw()
        if @check.hasChanged()
          @check.save()
          @hide_editor()
          @parent.parent.redraw()
{'fraction_non_alphanumeric': 0.14890843923101987, 'fraction_numerical': 0.006516780710329097, 'mean_word_length': 2.1135902636916835, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 21, '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': '1891254', 'n_tokens_mistral': 997, 'n_tokens_neox': 956, 'n_words': 216}