Retrospring/app/javascript/legacy/questionbox/user.coffee

42 lines
1.4 KiB
CoffeeScript
Raw Normal View History

2014-12-08 06:42:34 -08:00
$(document).on "click", "button[name=qb-ask]", ->
btn = $(this)
btn.button "loading"
promote = btn[0].dataset.promote == "true"
$("textarea[name=qb-question]").attr "readonly", "readonly"
anonymousQuestion = if $("input[name=qb-anonymous]")[0] != undefined
$("input[name=qb-anonymous]")[0].checked
else
true
$.ajax
url: '/ajax/ask' # TODO: find a way to use rake routes instead of hardcoding them here
type: 'POST'
data:
rcpt: $("input[name=qb-to]").val()
question: $("textarea[name=qb-question]").val()
anonymousQuestion: anonymousQuestion
success: (data, status, jqxhr) ->
if data.success
$("textarea[name=qb-question]").val ''
if promote
$("div#question-box").hide()
$("div#question-box-promote").show()
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
2014-12-08 06:42:34 -08:00
complete: (jqxhr, status) ->
btn.button "reset"
$("textarea[name=qb-question]").removeAttr "readonly"
2014-12-10 11:54:12 -08:00
# for that promotional thing
$(document).on "click", "button#new-question", ->
$("div#question-box").show()
$("div#question-box-promote").hide()
# see GitHub issue #2
($ document).on "keydown", "textarea[name=qb-question]", (evt) ->
if evt.keyCode == 13 and evt.ctrlKey
2015-06-08 11:35:16 -07:00
($ "button[name=qb-ask]").trigger 'click'