Commit 8e744605 authored by Jacob Schatz's avatar Jacob Schatz

adds ajax to bottom discussion buttons. Now submits issue and closes via ajax.

parent 3a227b5a
...@@ -16,12 +16,16 @@ class @Issue ...@@ -16,12 +16,16 @@ class @Issue
$(document).on 'tasklist:changed', '.detail-page-description .js-task-list-container', @updateTaskList $(document).on 'tasklist:changed', '.detail-page-description .js-task-list-container', @updateTaskList
initIssueBtnEventListeners: -> initIssueBtnEventListeners: ->
_this = @
issueFailMessage = 'Unable to update this issue at this time.' issueFailMessage = 'Unable to update this issue at this time.'
$('a.btn-close, a.btn-reopen').on 'click', (e) -> $('a.btn-close, a.btn-reopen').on 'click', (e) ->
e.preventDefault() e.preventDefault()
e.stopImmediatePropagation() e.stopImmediatePropagation()
$this = $(this) $this = $(this)
isClose = $this.hasClass('btn-close') isClose = $this.hasClass('btn-close')
shouldSubmit = $this.hasClass('btn-comment')
if shouldSubmit
_this.submitNoteForm($this.closest('form'))
$this.prop('disabled', true) $this.prop('disabled', true)
url = $this.attr('href') url = $this.attr('href')
$.ajax $.ajax
...@@ -32,12 +36,13 @@ class @Issue ...@@ -32,12 +36,13 @@ class @Issue
new Flash(issueFailMessage, 'alert') new Flash(issueFailMessage, 'alert')
success: (data, textStatus, jqXHR) -> success: (data, textStatus, jqXHR) ->
if data.saved if data.saved
$this.addClass('hidden')
if isClose if isClose
$('a.btn-close').addClass('hidden')
$('a.btn-reopen').removeClass('hidden') $('a.btn-reopen').removeClass('hidden')
$('div.status-box-closed').removeClass('hidden') $('div.status-box-closed').removeClass('hidden')
$('div.status-box-open').addClass('hidden') $('div.status-box-open').addClass('hidden')
else else
$('a.btn-reopen').addClass('hidden')
$('a.btn-close').removeClass('hidden') $('a.btn-close').removeClass('hidden')
$('div.status-box-closed').addClass('hidden') $('div.status-box-closed').addClass('hidden')
$('div.status-box-open').removeClass('hidden') $('div.status-box-open').removeClass('hidden')
...@@ -45,6 +50,11 @@ class @Issue ...@@ -45,6 +50,11 @@ class @Issue
new Flash(issueFailMessage, 'alert') new Flash(issueFailMessage, 'alert')
$this.prop('disabled', false) $this.prop('disabled', false)
submitNoteForm: (form) =>
noteText = form.find("textarea.js-note-text").val()
if noteText.trim().length > 0
form.submit()
disableTaskList: -> disableTaskList: ->
$('.detail-page-description .js-task-list-container').taskList('disable') $('.detail-page-description .js-task-list-container').taskList('disable')
$(document).off 'tasklist:changed', '.detail-page-description .js-task-list-container' $(document).off 'tasklist:changed', '.detail-page-description .js-task-list-container'
......
...@@ -19,6 +19,8 @@ class @Notes ...@@ -19,6 +19,8 @@ class @Notes
@cleanBinding() @cleanBinding()
@addBinding() @addBinding()
@initTaskList() @initTaskList()
# for updating the comment disscussion buttons once that issue #5534 is approved.
# @updateTargetButtons({target:$("#note_note")})
addBinding: -> addBinding: ->
# add note to UI after creation # add note to UI after creation
...@@ -33,8 +35,6 @@ class @Notes ...@@ -33,8 +35,6 @@ class @Notes
$(document).on "click", ".note-edit-cancel", @cancelEdit $(document).on "click", ".note-edit-cancel", @cancelEdit
# Reopen and close actions for Issue/MR combined with note form submit # Reopen and close actions for Issue/MR combined with note form submit
$(document).on "click", ".js-note-target-reopen", @targetReopen
$(document).on "click", ".js-note-target-close", @targetClose
$(document).on "click", ".js-comment-button", @updateCloseButton $(document).on "click", ".js-comment-button", @updateCloseButton
$(document).on "keyup", ".js-note-text", @updateTargetButtons $(document).on "keyup", ".js-note-text", @updateTargetButtons
...@@ -512,17 +512,6 @@ class @Notes ...@@ -512,17 +512,6 @@ class @Notes
visibilityChange: => visibilityChange: =>
@refresh() @refresh()
targetReopen: (e) =>
@submitNoteForm($(e.target).parents('form'))
targetClose: (e) =>
@submitNoteForm($(e.target).parents('form'))
submitNoteForm: (form) =>
noteText = form.find(".js-note-text").val()
if noteText.trim().length > 0
form.submit()
updateCloseButton: (e) => updateCloseButton: (e) =>
textarea = $(e.target) textarea = $(e.target)
form = textarea.parents('form') form = textarea.parents('form')
...@@ -531,7 +520,6 @@ class @Notes ...@@ -531,7 +520,6 @@ class @Notes
updateTargetButtons: (e) => updateTargetButtons: (e) =>
textarea = $(e.target) textarea = $(e.target)
form = textarea.parents('form') form = textarea.parents('form')
if textarea.val().trim().length > 0 if textarea.val().trim().length > 0
form.find('.js-note-target-reopen').text('Comment & reopen') form.find('.js-note-target-reopen').text('Comment & reopen')
form.find('.js-note-target-close').text('Comment & close') form.find('.js-note-target-close').text('Comment & close')
......
- content_for :note_actions do - content_for :note_actions do
- if can?(current_user, :update_issue, @issue) - if can?(current_user, :update_issue, @issue)
- if @issue.closed? = link_to 'Reopen Issue', issue_path(@issue, issue: {state_event: :reopen}, status_only: true, format: 'json'), data: {no_turbolink: true}, class: "btn btn-nr btn-grouped btn-reopen btn-comment js-note-target-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen Issue'
= link_to 'Reopen Issue', issue_path(@issue, issue: {state_event: :reopen}, status_only: true), method: :put, class: 'btn btn-nr btn-grouped btn-reopen js-note-target-reopen', title: 'Reopen Issue' = link_to 'Close Issue', issue_path(@issue, issue: {state_event: :close}, status_only: true, format: 'json'), data: {no_turbolink: true}, class: "btn btn-nr btn-grouped btn-close btn-comment js-note-target-close #{issue_button_visibility(@issue, true)}", title: 'Close Issue'
- else
= link_to 'Close Issue', issue_path(@issue, issue: {state_event: :close}, status_only: true), method: :put, class: 'btn btn-nr btn-grouped btn-close js-note-target-close', title: 'Close Issue'
#notes #notes
= render 'projects/notes/notes_with_form' = render 'projects/notes/notes_with_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