Retrospring/app/assets/javascripts/questionbox/all.coffee

41 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2014-12-08 06:42:34 -08:00
$(document).on "click", "button[name=qb-all-ask]", ->
btn = $(this)
btn.button "loading"
$("textarea[name=qb-all-question]").attr "readonly", "readonly"
rcptSelect = ($ 'select[name=qb-all-rcpt]')
rcpt = if rcptSelect.length > 0
rcptSelect.first().val()
else
'followers'
2014-12-08 06:42:34 -08:00
$.ajax
url: '/ajax/ask'
type: 'POST'
data:
rcpt: rcpt
2014-12-08 06:42:34 -08:00
question: $("textarea[name=qb-all-question]").val()
anonymousQuestion: false
success: (data, status, jqxhr) ->
if data.success
$("textarea[name=qb-all-question]").val ''
$('#modal-ask-followers').modal('hide')
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-all-question]").removeAttr "readonly"
# hotkey for accessing this quickly
$(document).on "keydown", (evt) ->
if evt.keyCode == 77 and (evt.ctrlKey or evt.metaKey)
2015-01-07 10:59:42 -08:00
$('.btn[name=toggle-all-ask]').trigger 'click'
2014-12-10 11:54:12 -08:00
# see GitHub issue #2
($ document).on "keydown", "textarea[name=qb-all-question]", (evt) ->
if evt.keyCode == 13 and (evt.ctrlKey or evt.metaKey)
($ "button[name=qb-all-ask]").trigger 'click'