2015-01-03 09:41:10 -08:00
|
|
|
$(document).on "keydown", "textarea#q-answer", (evt) ->
|
|
|
|
qid = $(this)[0].dataset.id
|
|
|
|
if evt.keyCode == 13 and evt.ctrlKey
|
|
|
|
# trigger warning:
|
|
|
|
$("button#q-answer[data-q-id=#{qid}]").trigger 'click'
|
|
|
|
|
|
|
|
|
|
|
|
$(document).on "click", "button#q-answer", ->
|
|
|
|
btn = $(this)
|
|
|
|
btn.button "loading"
|
|
|
|
qid = btn[0].dataset.qId
|
|
|
|
$("textarea#q-answer[data-q=#{qid}]").attr "readonly", "readonly"
|
|
|
|
|
|
|
|
shareTo = []
|
|
|
|
($ "input[type=checkbox][name=share][data-q-id=#{qid}]:checked").each (i, share) ->
|
|
|
|
shareTo.push share.dataset.service
|
|
|
|
|
|
|
|
$.ajax
|
|
|
|
url: '/ajax/answer'
|
|
|
|
type: 'POST'
|
2015-01-03 09:56:06 -08:00
|
|
|
dataType: 'json'
|
2015-01-03 09:41:10 -08:00
|
|
|
data:
|
|
|
|
id: qid
|
|
|
|
answer: $("textarea#q-answer[data-id=#{qid}]").val()
|
|
|
|
share: JSON.stringify shareTo
|
|
|
|
inbox: false
|
|
|
|
success: (data, status, jqxhr) ->
|
|
|
|
if data.success
|
|
|
|
$("div#q-answer-box").slideUp()
|
2015-01-03 10:14:26 -08:00
|
|
|
($ "div#answers").prepend data.render
|
2015-01-03 09:41:10 -08:00
|
|
|
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) ->
|
|
|
|
btn.button "reset"
|
|
|
|
$("textarea#q-answer[data-id=#{qid}]").removeAttr "readonly"
|