2016-06-02 11:05:42 +05:30
|
|
|
class @GLForm
|
|
|
|
constructor: (@form) ->
|
|
|
|
@textarea = @form.find('textarea.js-gfm-input')
|
|
|
|
|
|
|
|
# Before we start, we should clean up any previous data for this form
|
|
|
|
@destroy()
|
|
|
|
|
|
|
|
# Setup the form
|
|
|
|
@setupForm()
|
|
|
|
|
|
|
|
@form.data 'gl-form', @
|
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
# Clean form listeners
|
|
|
|
@clearEventListeners()
|
|
|
|
@form.data 'gl-form', null
|
|
|
|
|
|
|
|
setupForm: ->
|
|
|
|
isNewForm = @form.is(':not(.gfm-form)')
|
|
|
|
|
|
|
|
@form.removeClass 'js-new-note-form'
|
|
|
|
|
|
|
|
if isNewForm
|
|
|
|
@form.find('.div-dropzone').remove()
|
|
|
|
@form.addClass('gfm-form')
|
|
|
|
disableButtonIfEmptyField @form.find('.js-note-text'), @form.find('.js-comment-button')
|
|
|
|
|
|
|
|
# remove notify commit author checkbox for non-commit notes
|
|
|
|
GitLab.GfmAutoComplete.setup()
|
|
|
|
new DropzoneInput(@form)
|
|
|
|
|
|
|
|
autosize(@textarea)
|
|
|
|
|
|
|
|
# form and textarea event listeners
|
|
|
|
@addEventListeners()
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
gl.text.init(@form)
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
# hide discard button
|
|
|
|
@form.find('.js-note-discard').hide()
|
|
|
|
|
|
|
|
@form.show()
|
|
|
|
|
|
|
|
clearEventListeners: ->
|
|
|
|
@textarea.off 'focus'
|
|
|
|
@textarea.off 'blur'
|
2016-08-24 12:49:21 +05:30
|
|
|
gl.text.removeListeners(@form)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
addEventListeners: ->
|
|
|
|
@textarea.on 'focus', ->
|
|
|
|
$(@).closest('.md-area').addClass 'is-focused'
|
|
|
|
|
|
|
|
@textarea.on 'blur', ->
|
|
|
|
$(@).closest('.md-area').removeClass 'is-focused'
|