Commit 5dd01f57 authored by Phil Hughes's avatar Phil Hughes

Destroy discussion form

parent 82164a9f
class @GLForm class @GLForm
constructor: (@form) -> constructor: (@form) ->
@textarea = @form.find(".js-note-text") @textarea = @form.find('.js-note-text')
@setupForm() @setupForm()
@form.data 'gl-form', @
destroy: ->
# Destroy actions
actions = @form.data 'form-actions'
actions.clearEventListeners()
@form.data 'form-actions', null
# Clean form listeners
@clearEventListeners()
@form.data 'gl-form', null
setupForm: -> setupForm: ->
isNewForm = @form.is(':not(.gfm-form)') isNewForm = @form.is(':not(.gfm-form)')
@form.removeClass "js-new-note-form" @form.removeClass 'js-new-note-form'
if isNewForm if isNewForm
@form.find('.div-dropzone').remove() @form.find('.div-dropzone').remove()
@form.addClass('gfm-form') @form.addClass('gfm-form')
disableButtonIfEmptyField @form.find(".js-note-text"), @form.find(".js-comment-button") disableButtonIfEmptyField @form.find('.js-note-text'), @form.find('.js-comment-button')
# remove notify commit author checkbox for non-commit notes # remove notify commit author checkbox for non-commit notes
GitLab.GfmAutoComplete.setup() GitLab.GfmAutoComplete.setup()
...@@ -32,6 +44,10 @@ class @GLForm ...@@ -32,6 +44,10 @@ class @GLForm
@form.show() @form.show()
clearEventListeners: ->
@textarea.off 'focus'
@textarea.off 'blur'
addEventListeners: -> addEventListeners: ->
@textarea.on 'focus', -> @textarea.on 'focus', ->
$(@).closest('.md-area').addClass 'is-focused' $(@).closest('.md-area').addClass 'is-focused'
......
...@@ -513,6 +513,9 @@ class @Notes ...@@ -513,6 +513,9 @@ class @Notes
removeDiscussionNoteForm: (form)-> removeDiscussionNoteForm: (form)->
row = form.closest("tr") row = form.closest("tr")
glForm = form.data 'gl-form'
glForm.destroy()
form.find(".js-note-text").data("autosave").reset() form.find(".js-note-text").data("autosave").reset()
# show the reply button (will only work for replies) # show the reply button (will only work for replies)
...@@ -524,11 +527,6 @@ class @Notes ...@@ -524,11 +527,6 @@ class @Notes
# only remove the form # only remove the form
form.remove() form.remove()
# Remove the note actions
actions = form.data('form-actions')
actions.clearEventListeners()
form.data('form-actions', null)
cancelDiscussionForm: (e) => cancelDiscussionForm: (e) =>
e.preventDefault() e.preventDefault()
form = $(e.target).closest(".js-discussion-note-form") form = $(e.target).closest(".js-discussion-note-form")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment