<commit_before>class window.AddCommentView extends Backbone.Marionette.ItemView
  className: 'add-comment'
  events:
    'click .js-post': 'addModel'
    'click .js-switch': 'switchCheckboxClicked'
    'blur  .content': 'updateModel'
    'keyup input.content': 'parseKeyUp'

  template: 'comments/add_comment'

  initialize: ->
    @initializeModel()
    @bindTo @model, 'change', @render, @

  parseKeyUp: (e) ->
    code = e.keyCode || e.which
    switch e.keyCode
      when 13 then @addModel.call @

  initializeModel: ->
    @model = new Comment(content: '', created_by: currentUser)

  templateHelpers: =>
    type_of_action_text: @type_of_action_text()

  type_of_action_text: ->
    if @options.addToCollection.type == 'believes'
      'Agreeing'
    else
      'Disagreeing'

  updateModel: ->
    content = @$('.content').val()
    @model.set {content: content}, silent: true

  clearForm: -> @setFormContent ''

  setFormContent: (content) -> @model.set content: content

  showErrorMessage: -> @$('.js-comment-error-message').show()

  addModelSuccess: (model) ->
    @initializeModel()
    @clearForm()
    model.trigger 'change'

  addModelError: -> @showErrorMessage()

  switchCheckboxClicked: (e)->
    @trigger 'switch_to_fact_relation_view', @$('.content').val()
    e.preventDefault()
    e.stopPropagation()

_.extend AddCommentView.prototype, Backbone.Factlink.AddModelToCollectionMixin<commit_msg>Bugfixed adding of comments<commit_after>class window.AddCommentView extends Backbone.Marionette.ItemView
  className: 'add-comment'
  events:
    'click .js-post': 'addModel'
    'click .js-switch': 'switchCheckboxClicked'
    'blur  .content': 'updateModel'
    'keyup input.content': 'parseKeyUp'

  template: 'comments/add_comment'

  initialize: ->
    @initializeModel()

  parseKeyUp: (e) ->
    code = e.keyCode || e.which
    switch e.keyCode
      when 13 then @addModel.call @

  initializeModel: ->
    @model = new Comment(content: '', created_by: currentUser)
    @bindTo @model, 'change', @render, @

  templateHelpers: =>
    type_of_action_text: @type_of_action_text()

  type_of_action_text: ->
    if @options.addToCollection.type == 'believes'
      'Agreeing'
    else
      'Disagreeing'

  updateModel: ->
    content = @$('.content').val()
    @model.set {content: content}, silent: true

  setFormContent: (content) -> @model.set content: content

  showErrorMessage: -> @$('.js-comment-error-message').show()

  addModelSuccess: (model) ->
    @initializeModel()
    model.trigger 'change'

  addModelError: -> @showErrorMessage()

  switchCheckboxClicked: (e)->
    @trigger 'switch_to_fact_relation_view', @$('.content').val()
    e.preventDefault()
    e.stopPropagation()

_.extend AddCommentView.prototype, Backbone.Factlink.AddModelToCollectionMixin
{'fraction_non_alphanumeric': 0.14244912531238843, 'fraction_numerical': 0.0014280614066404856, 'mean_word_length': 3.7897435897435896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '3870982', 'n_tokens_mistral': 928, 'n_tokens_neox': 897, 'n_words': 177}