Retrospring/app/assets/javascripts/question.coffee

38 lines
1.1 KiB
CoffeeScript
Raw Normal View History

$(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'
$(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"
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'
dataType: 'json'
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
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
complete: (jqxhr, status) ->
btn.button "reset"
2015-01-03 13:36:51 -08:00
$("textarea#q-answer").removeAttr "readonly"