<commit_before>class NewCommentForm extends KDView

  constructor:(options = {}, data)->

    options.type           or= "new-comment"
    options.cssClass       or= "item-add-comment-box"
    options.itemTypeString or= 'comment'

    super options, data

  viewAppended:->

    @addSubView commenterAvatar = new AvatarStaticView
      size    :
        width : 35
        height: 35
    , KD.whoami()

    @addSubView commentFormWrapper = new KDView
      cssClass    : "item-add-comment-form"

    {itemTypeString} = @getOptions()

    commentFormWrapper.addSubView @commentInput = new KDHitEnterInputView
      type          : "textarea"
      delegate      : this
      placeholder   : "Type your #{itemTypeString} and hit enter..."
      autogrow      : yes
      validate      :
        rules       :
          required  : yes
          maxLength : 2000
        messages    :
          required  : "Please type a #{itemTypeString}..."
      callback      : @bound "commentInputReceivedEnter"

    @attachListeners()

  attachListeners:->
    @commentInput.on "blur", @bound "commentInputReceivedBlur"
    @commentInput.on "focus", =>
      @getDelegate().emit "commentInputReceivedFocus"

  makeCommentFieldActive:->
    @getDelegate().emit "commentInputReceivedFocus"
    (KD.getSingleton "windowController").setKeyView @commentInput

  resetCommentField:->
    @getDelegate().emit "CommentViewShouldReset"

  otherCommentInputReceivedFocus:(instance)->
    if instance isnt @commentInput
      commentForm = @commentInput.getDelegate()
      commentForm.resetCommentField() if $.trim(@commentInput.getValue()) is ""

  commentInputReceivedBlur:->
    @resetCommentField()  if @commentInput.getValue() is ""

  commentInputReceivedEnter:(instance,event)->
    KD.requireMembership
      callback  : =>
        reply = @commentInput.getValue()
        @commentInput.setValue ''
        @commentInput.resize()
        @commentInput.blur()
        @commentInput.$().blur()
        @getDelegate().emit 'CommentSubmitted', reply

        KD.mixpanel "Comment activity, click", reply.length
      onFailMsg : "Login required to post a comment!"
      tryAgain  : yes
      groupName : @getDelegate().getData().group<commit_msg>EditComment: EditCommenfForm class is added<commit_after>class NewCommentForm extends KDView

  constructor:(options = {}, data)->

    options.type           or= "new-comment"
    options.cssClass       or= "item-add-comment-box"
    options.itemTypeString or= 'comment'
    options.editable       or= no

    super options, data

    {itemTypeString} = @getOptions()
    data = @getData()

    @commentInput = new KDHitEnterInputView
      type          : "textarea"
      delegate      : this
      placeholder   : "Type your #{itemTypeString} and hit enter..."
      autogrow      : yes
      validate      :
        rules       :
          required  : yes
          maxLength : 2000
        messages    :
          required  : "Please type a #{itemTypeString}..."
      callback      : @bound "commentInputReceivedEnter"

    @commentFormWrapper = new KDView
      cssClass    : "item-add-comment-form"

    @commentFormWrapper.addSubView @commentInput

  viewAppended:->
    {editable} = @getOptions()
    unless editable
      @addSubView commenterAvatar = new AvatarStaticView
        size    :
          width : 35
          height: 35
      , KD.whoami()

    @addSubView @commentFormWrapper

    @attachListeners()

  attachListeners:->
    @commentInput.on "blur", @bound "commentInputReceivedBlur"
    @commentInput.on "focus", =>
      @getDelegate().emit "commentInputReceivedFocus"

  makeCommentFieldActive:->
    @getDelegate().emit "commentInputReceivedFocus"
    (KD.getSingleton "windowController").setKeyView @commentInput

  resetCommentField:->
    @getDelegate().emit "CommentViewShouldReset"

  otherCommentInputReceivedFocus:(instance)->
    if instance isnt @commentInput
      commentForm = @commentInput.getDelegate()
      commentForm.resetCommentField() if $.trim(@commentInput.getValue()) is ""

  commentInputReceivedBlur:->
    @resetCommentField()  if @commentInput.getValue() is ""

  commentInputReceivedEnter:(instance,event)->
    KD.requireMembership
      callback  : =>
        {editable} = @getOptions()
        reply = @commentInput.getValue()
        @commentInput.setValue ''
        @commentInput.resize()
        @commentInput.blur()
        @commentInput.$().blur()
        unless editable then @getDelegate().emit 'CommentSubmitted', reply
        else @getDelegate().emit 'CommentUpdated', reply


        KD.mixpanel "Comment activity, click", reply.length
      onFailMsg : "Login required to post a comment!"
      tryAgain  : yes
      groupName : @getDelegate().getData().group

class EditCommentForm extends NewCommentForm

  constructor:(options = {}, data)->
    options.editable = yes
    super options, data

    @commentFormWrapper.addSubView new KDCustomHTMLView
      pistachio: "Press Esc to cancel"

    @commentInput.setValue data.body
    @commentInput.on "EscapePerformed", @bound "cancel"
    @commentInput.setFocus()

  cancel: ->
    @getDelegate().emit "CommentUpdateCancelled"
{'fraction_non_alphanumeric': 0.10600502027418421, 'fraction_numerical': 0.0030893994979725816, 'mean_word_length': 2.817243920412675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '135331', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1394, 'n_words': 316}