<commit_before>class window.AddCommentView extends Backbone.Marionette.Layout
  _.extend @prototype, Backbone.Factlink.AddModelToCollectionMixin

  className: 'add-comment'
  events:
    'click .js-post': 'addComment'

  template: 'comments/add_comment'

  ui:
    submit:  '.js-post'

  regions:
    inputRegion: '.js-input-region'
    shareFactSelectionRegion: '.js-share-fact-selection-region'

  initialize: ->
    @_textAreaView = new Backbone.Factlink.TextAreaView model: @_textModel()
    @listenTo @_textAreaView, 'return', @addComment
    @on 'region:focus', -> @_textAreaView.focusInput()

  onRender: ->
    @inputRegion.show @_textAreaView

    if Factlink.Global.can_haz.share_comment && Factlink.Global.signed_in
      @shareFactSelectionRegion.show @_shareFactSelectionView()

  addComment: ->
    return if @submitting

    content = $.trim(@_textModel().get('text'))
    @model = new Comment
      content: content
      formatted_comment_content: content
      created_by: currentUser.toJSON()
      type: @options.argumentTypeModel.get 'argument_type'

    return @addModelError() unless @model.isValid()

    @disableSubmit()
    @addDefaultModel()
    @_shareFactlink(@model)

  setFormContent: (content) -> @_textModel().set 'text', content

  addModelSuccess: (model) ->
    @enableSubmit()
    @setFormContent ''

    model.trigger 'change'

    mp_track "Factlink: Added comment",
      factlink_id: @options.addToCollection.fact.id
      type: @options.argumentTypeModel.get 'argument_type'

  _shareFactlink: (model) ->
    return unless Factlink.Global.can_haz.share_comment && Factlink.Global.signed_in

    @_shareFactSelectionView().submit model.get('content')

  addModelError: ->
    @enableSubmit()
    FactlinkApp.NotificationCenter.error 'Your comment could not be posted, please try again.'

  enableSubmit: ->
    @submitting = false
    @ui.submit.prop('disabled',false).text(Factlink.Global.t.post_argument)

  disableSubmit: ->
    @submitting = true
    @ui.submit.prop('disabled',true ).text('Posting...')

  _textModel: -> @__textModel ?= new Backbone.Factlink.SemiPersistentTextModel {},
    key: "add_comment_to_fact_#{@options.addToCollection.fact.id}"

  _shareFactSelectionView: ->
    @___shareFactSelectionView ?= new ShareFactSelectionView
      model: @options.addToCollection.fact
<commit_msg>Removed useless model event<commit_after>class window.AddCommentView extends Backbone.Marionette.Layout
  _.extend @prototype, Backbone.Factlink.AddModelToCollectionMixin

  className: 'add-comment'
  events:
    'click .js-post': 'addComment'

  template: 'comments/add_comment'

  ui:
    submit:  '.js-post'

  regions:
    inputRegion: '.js-input-region'
    shareFactSelectionRegion: '.js-share-fact-selection-region'

  initialize: ->
    @_textAreaView = new Backbone.Factlink.TextAreaView model: @_textModel()
    @listenTo @_textAreaView, 'return', @addComment
    @on 'region:focus', -> @_textAreaView.focusInput()

  onRender: ->
    @inputRegion.show @_textAreaView

    if Factlink.Global.can_haz.share_comment && Factlink.Global.signed_in
      @shareFactSelectionRegion.show @_shareFactSelectionView()

  addComment: ->
    return if @submitting

    content = $.trim(@_textModel().get('text'))
    @model = new Comment
      content: content
      formatted_comment_content: content
      created_by: currentUser.toJSON()
      type: @options.argumentTypeModel.get 'argument_type'

    return @addModelError() unless @model.isValid()

    @disableSubmit()
    @addDefaultModel()
    @_shareFactlink(@model)

  setFormContent: (content) -> @_textModel().set 'text', content

  addModelSuccess: (model) ->
    @enableSubmit()
    @setFormContent ''

    mp_track "Factlink: Added comment",
      factlink_id: @options.addToCollection.fact.id
      type: @options.argumentTypeModel.get 'argument_type'

  _shareFactlink: (model) ->
    return unless Factlink.Global.can_haz.share_comment && Factlink.Global.signed_in

    @_shareFactSelectionView().submit model.get('content')

  addModelError: ->
    @enableSubmit()
    FactlinkApp.NotificationCenter.error 'Your comment could not be posted, please try again.'

  enableSubmit: ->
    @submitting = false
    @ui.submit.prop('disabled',false).text(Factlink.Global.t.post_argument)

  disableSubmit: ->
    @submitting = true
    @ui.submit.prop('disabled',true ).text('Posting...')

  _textModel: -> @__textModel ?= new Backbone.Factlink.SemiPersistentTextModel {},
    key: "add_comment_to_fact_#{@options.addToCollection.fact.id}"

  _shareFactSelectionView: ->
    @___shareFactSelectionView ?= new ShareFactSelectionView
      model: @options.addToCollection.fact

{'fraction_non_alphanumeric': 0.12243589743589743, 'fraction_numerical': 0.0, 'mean_word_length': 4.08804347826087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '4331737', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1426, 'n_words': 261}