BigW Consortium Gitlab

gl_form.js.coffee 1.2 KB
Newer Older
Phil Hughes committed
1 2
class @GLForm
  constructor: (@form) ->
3
    @textarea = @form.find('textarea.js-gfm-input')
Phil Hughes committed
4

5 6 7 8
    # Before we start, we should clean up any previous data for this form
    @destroy()

    # Setup the form
Phil Hughes committed
9 10
    @setupForm()

Phil Hughes committed
11 12 13 14 15 16 17
    @form.data 'gl-form', @

  destroy: ->
    # Clean form listeners
    @clearEventListeners()
    @form.data 'gl-form', null

Phil Hughes committed
18 19 20
  setupForm: ->
    isNewForm = @form.is(':not(.gfm-form)')

Phil Hughes committed
21
    @form.removeClass 'js-new-note-form'
Phil Hughes committed
22 23 24 25

    if isNewForm
      @form.find('.div-dropzone').remove()
      @form.addClass('gfm-form')
Phil Hughes committed
26
      disableButtonIfEmptyField @form.find('.js-note-text'), @form.find('.js-comment-button')
Phil Hughes committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

      # remove notify commit author checkbox for non-commit notes
      GitLab.GfmAutoComplete.setup()
      new DropzoneInput(@form)

      autosize(@textarea)

      # form and textarea event listeners
      @addEventListeners()

    # hide discard button
    @form.find('.js-note-discard').hide()

    @form.show()

Phil Hughes committed
42 43 44 45
  clearEventListeners: ->
    @textarea.off 'focus'
    @textarea.off 'blur'

Phil Hughes committed
46 47 48 49 50 51
  addEventListeners: ->
    @textarea.on 'focus', ->
      $(@).closest('.md-area').addClass 'is-focused'

    @textarea.on 'blur', ->
      $(@).closest('.md-area').removeClass 'is-focused'