2016-04-05 05:17:00 -04:00
|
|
|
class @GLForm
|
|
|
|
constructor: (@form) ->
|
2016-04-05 05:34:02 -04:00
|
|
|
@textarea = @form.find('textarea.js-gfm-input')
|
2016-04-05 05:17:00 -04:00
|
|
|
|
2016-04-05 05:34:02 -04:00
|
|
|
# Before we start, we should clean up any previous data for this form
|
|
|
|
@destroy()
|
|
|
|
|
|
|
|
# Setup the form
|
2016-04-05 05:17:00 -04:00
|
|
|
@setupForm()
|
|
|
|
|
2016-04-05 05:28:10 -04:00
|
|
|
@form.data 'gl-form', @
|
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
# Clean form listeners
|
|
|
|
@clearEventListeners()
|
|
|
|
@form.data 'gl-form', null
|
|
|
|
|
2016-04-05 05:17:00 -04:00
|
|
|
setupForm: ->
|
|
|
|
isNewForm = @form.is(':not(.gfm-form)')
|
|
|
|
|
2016-04-05 05:28:10 -04:00
|
|
|
@form.removeClass 'js-new-note-form'
|
2016-04-05 05:17:00 -04:00
|
|
|
|
|
|
|
if isNewForm
|
|
|
|
@form.find('.div-dropzone').remove()
|
|
|
|
@form.addClass('gfm-form')
|
2016-04-05 05:28:10 -04:00
|
|
|
disableButtonIfEmptyField @form.find('.js-note-text'), @form.find('.js-comment-button')
|
2016-04-05 05:17:00 -04:00
|
|
|
|
|
|
|
# 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()
|
|
|
|
|
2016-04-05 05:28:10 -04:00
|
|
|
clearEventListeners: ->
|
|
|
|
@textarea.off 'focus'
|
|
|
|
@textarea.off 'blur'
|
|
|
|
|
2016-04-05 05:17:00 -04:00
|
|
|
addEventListeners: ->
|
|
|
|
@textarea.on 'focus', ->
|
|
|
|
$(@).closest('.md-area').addClass 'is-focused'
|
|
|
|
|
|
|
|
@textarea.on 'blur', ->
|
|
|
|
$(@).closest('.md-area').removeClass 'is-focused'
|