   events:
     'click   .js-new-event' : 'onNewCommentClicked'
     'keydown .js-new-event' : 'newCommentKeyDown'
+    'input   .js-new-event' : 'newCommentKeyUp'
+    'change  .js-new-event' : 'newCommentKeyUp'
 
   keys:
     'enter': 13


  ownCommentsChanged: ->
    @children.welcomeBox.toggle !@model.hasOwnComments()

        @model.incrementUnreadCount()
        @pushNotification(event)

  wipStateChanged: ->
    switch @model.get('state')
      when 'open'      then @onWipOpen()
      when 'allocated' then @onWipAllocated()
      when 'reviewing' then @onWipReviewing()
      when 'resolved'  then @onWipResolved()

  onWipOpen: ->
    @$('[name=close]').show()
    @$('[name=reopen]').hide()
    @$('[name=unallocate]').hide()
    @$('[name=reject]').hide()

  onWipAllocated: ->
    @$('[name=close]').show()
    @$('[name=reopen]').hide()
    @$('[name=unallocate]').show()
    @$('[name=reject]').hide()

  onWipReviewing: ->
    @$('[name=close]').show()
    @$('[name=reopen]').hide()
    @$('[name=unallocate]').hide()
    @$('[name=reject]').show()

  onWipResolved: ->
    @$('[name=close]').hide()
    @$('[name=reopen]').show()
    @$('[name=unallocate]').hide()
    @$('[name=reject]').hide()

  newCommentKeyDown: (e)->
    cmdEnter = (e.which == @keys.enter)
    body = $('#event_comment_body').val()
    if cmdEnter && @validComment(body)
      e.preventDefault()
      @addComment(body)

  newCommentKeyUp: (e)->
    @validateComment $('#event_comment_body').val()

  resetCommentForm: ->
    @$('#event_comment_body').val('')
