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:
|
2015-01-03 13:36:51 -08:00
|
|
|
$("button#q-answer").trigger 'click'
|
2015-01-03 09:41:10 -08:00
|
|
|
|
|
|
|
|
|
|
|
$(document).on "click", "button#q-answer", ->
|
|
|
|
btn = $(this)
|
|
|
|
btn.button "loading"
|
|
|
|
qid = btn[0].dataset.qId
|
2015-01-03 13:36:51 -08:00
|
|
|
$("textarea#q-answer").attr "readonly", "readonly"
|
2015-01-03 09:41:10 -08:00
|
|
|
|
|
|
|
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
|
2015-06-08 11:35:16 -07:00
|
|
|
showNotification translate('frontend.error.message'), false
|
2015-01-03 09:41:10 -08:00
|
|
|
complete: (jqxhr, status) ->
|
|
|
|
btn.button "reset"
|
2015-01-03 13:36:51 -08:00
|
|
|
$("textarea#q-answer").removeAttr "readonly"
|