posting comments is now possible.
This commit is contained in:
parent
50151453d8
commit
8ab5458b1b
|
@ -168,6 +168,53 @@ $(document).on "click", "button[name=ab-comments]", ->
|
||||||
commentBox.slideUp()
|
commentBox.slideUp()
|
||||||
btn[0].dataset.state = 'hidden'
|
btn[0].dataset.state = 'hidden'
|
||||||
|
|
||||||
|
$(document).on "keyup", "input[name=ab-comment-new]", (evt) ->
|
||||||
|
input = $(this)
|
||||||
|
aid = input[0].dataset.aId
|
||||||
|
ctr = $("span#ab-comment-charcount-#{aid}")
|
||||||
|
cbox = $("div[name=ab-comment-new-group][data-a-id=#{aid}]")
|
||||||
|
|
||||||
|
if evt.which == 13 # return key
|
||||||
|
evt.preventDefault()
|
||||||
|
return cbox.addClass "has-error" if input.val().length > 160 || input.val().trim().length == 0
|
||||||
|
input.attr 'disabled', 'disabled'
|
||||||
|
|
||||||
|
$.ajax
|
||||||
|
url: '/ajax/create_comment'
|
||||||
|
type: 'POST'
|
||||||
|
data:
|
||||||
|
answer: aid
|
||||||
|
comment: input.val()
|
||||||
|
dataType: 'json' # jQuery can't guess the datatype correctly here...
|
||||||
|
success: (data, status, jqxhr) ->
|
||||||
|
console.log data
|
||||||
|
if data.success
|
||||||
|
$(".panel-footer#ab-comments-#{aid}").html data.render
|
||||||
|
input.val ''
|
||||||
|
ctr.html 160
|
||||||
|
$("span#ab-comment-count-#{aid}").html data.count
|
||||||
|
showNotification data.message, data.success
|
||||||
|
error: (jqxhr, status, error) ->
|
||||||
|
console.log jqxhr, status, error
|
||||||
|
showNotification "An error occurred, a developer should check the console for details", false
|
||||||
|
complete: (jqxhr, status) ->
|
||||||
|
input.removeAttr 'disabled'
|
||||||
|
|
||||||
|
$(document).on "input", "input[name=ab-comment-new]", (evt) ->
|
||||||
|
input = $(this)
|
||||||
|
aid = input[0].dataset.aId
|
||||||
|
ctr = $("span#ab-comment-charcount-#{aid}")
|
||||||
|
|
||||||
|
cbox = $("div[name=ab-comment-new-group][data-a-id=#{aid}]")
|
||||||
|
cbox.removeClass "has-error" if cbox.hasClass "has-error"
|
||||||
|
|
||||||
|
ctr.html 160 - input.val().length
|
||||||
|
if Number(ctr.html()) < 0
|
||||||
|
ctr.removeClass 'text-muted'
|
||||||
|
ctr.addClass 'text-danger'
|
||||||
|
else
|
||||||
|
ctr.removeClass 'text-danger'
|
||||||
|
ctr.addClass 'text-muted'
|
||||||
|
|
||||||
$(document).on "click", "button[name=user-action]", ->
|
$(document).on "click", "button[name=user-action]", ->
|
||||||
btn = $(this)
|
btn = $(this)
|
||||||
|
|
|
@ -18,5 +18,6 @@ class Ajax::CommentController < ApplicationController
|
||||||
@message = "Comment posted successfully."
|
@message = "Comment posted successfully."
|
||||||
@success = true
|
@success = true
|
||||||
@render = render_to_string(partial: 'shared/comments', locals: { a: answer })
|
@render = render_to_string(partial: 'shared/comments', locals: { a: answer })
|
||||||
|
@count = answer.comment_count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
json.partial! 'ajax/shared/status'
|
json.partial! 'ajax/shared/status'
|
||||||
json.render @render if @render
|
json.render @render if @render
|
||||||
|
json.count @count if @count
|
|
@ -7,6 +7,6 @@
|
||||||
#{user_screen_name comment.user}:
|
#{user_screen_name comment.user}:
|
||||||
= comment.content
|
= comment.content
|
||||||
- if user_signed_in?
|
- if user_signed_in?
|
||||||
.form-group.has-feedback
|
.form-group.has-feedback{name: 'ab-comment-new-group', 'data-a-id' => a.id}
|
||||||
%input.form-control{type: :text, placeholder: 'Comment...', id: "ab-comments-#{a.id}-new"}
|
%input.form-control{type: :text, placeholder: 'Comment...', name: 'ab-comment-new', 'data-a-id' => a.id}
|
||||||
%span.text-muted.form-control-feedback.comment-count{id: "ab-comments-#{a.id}-charcount"} 160
|
%span.text-muted.form-control-feedback.comment-count{id: "ab-comment-charcount-#{a.id}"} 160
|
Loading…
Reference in New Issue