2014-11-10 09:19:04 -08:00
|
|
|
#= require jquery
|
|
|
|
#= require jquery_ujs
|
2014-11-11 09:16:09 -08:00
|
|
|
#= require jquery.turbolinks
|
2014-11-10 09:19:04 -08:00
|
|
|
#= require turbolinks
|
|
|
|
#= require bootstrap
|
|
|
|
#= require nprogress
|
|
|
|
#= require nprogress-turbolinks
|
|
|
|
#= require_tree .
|
|
|
|
|
|
|
|
NProgress.configure
|
|
|
|
showSpinner: false
|
|
|
|
|
2014-11-11 09:02:59 -08:00
|
|
|
showSnackbar = (text) ->
|
|
|
|
$.snackbar # allahu snackbar
|
2014-11-11 10:52:52 -08:00
|
|
|
content: text
|
2014-11-11 09:02:59 -08:00
|
|
|
style: "snackbar"
|
|
|
|
timeout: 5000
|
|
|
|
|
2014-11-10 09:19:04 -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
|
2014-11-10 09:25:46 -08:00
|
|
|
type: 'POST'
|
2014-11-10 09:19:04 -08:00
|
|
|
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()
|
2014-11-11 09:02:59 -08:00
|
|
|
showSnackbar data.message
|
2014-11-11 07:19:20 -08:00
|
|
|
else
|
|
|
|
console.log data, status, jqxhr
|
2014-11-11 09:02:59 -08:00
|
|
|
showSnackbar "An error occurred, a developer should check the console for details"
|
2014-11-11 07:19:20 -08:00
|
|
|
error: (jqxhr, status, error) ->
|
|
|
|
console.log jqxhr, status, error
|
2014-11-11 09:02:59 -08:00
|
|
|
showSnackbar "An error occurred, a developer should check the console for details"
|
2014-11-11 07:19:20 -08:00
|
|
|
complete: (jqxhr, status) ->
|
|
|
|
btn.button "reset"
|
|
|
|
$("textarea[name=qb-question]").removeAttr "readonly"
|
|
|
|
|
|
|
|
$(document).on "click", "button[name=ib-answer]", ->
|
|
|
|
btn = $(this)
|
|
|
|
btn.button "loading"
|
2014-11-11 09:02:59 -08:00
|
|
|
iid = btn[0].dataset.ibId
|
|
|
|
$("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly"
|
2014-11-11 07:19:20 -08:00
|
|
|
$.ajax
|
2014-11-11 09:02:59 -08:00
|
|
|
url: '/ajax/answer' # TODO: find a way to use rake routes instead of hardcoding them here
|
2014-11-11 07:19:20 -08:00
|
|
|
type: 'POST'
|
|
|
|
data:
|
|
|
|
id: iid
|
2014-11-11 09:02:59 -08:00
|
|
|
answer: $("textarea[name=ib-answer][data-id=#{iid}]").val()
|
2014-11-11 07:19:20 -08:00
|
|
|
success: (data, status, jqxhr) ->
|
|
|
|
if data.success
|
2014-11-11 09:02:59 -08:00
|
|
|
$("div.inbox-box[data-id=#{iid}]").slideUp()
|
|
|
|
showSnackbar data.message
|
2014-11-10 09:19:04 -08:00
|
|
|
else
|
|
|
|
console.log data, status, jqxhr
|
2014-11-11 09:02:59 -08:00
|
|
|
showSnackbar "An error occurred, a developer should check the console for details"
|
2014-11-10 09:19:04 -08:00
|
|
|
error: (jqxhr, status, error) ->
|
|
|
|
console.log jqxhr, status, error
|
2014-11-11 09:02:59 -08:00
|
|
|
showSnackbar "An error occurred, a developer should check the console for details"
|
2014-11-10 09:19:04 -08:00
|
|
|
complete: (jqxhr, status) ->
|
|
|
|
btn.button "reset"
|
2014-11-11 09:02:59 -08:00
|
|
|
$("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly"
|
2014-11-10 09:19:04 -08:00
|
|
|
|
2014-11-27 02:50:41 -08:00
|
|
|
# TODO
|
|
|
|
$(document).on "click", "button[name=ab-destroy]", ->
|
|
|
|
btn = $(this)
|
|
|
|
btn.button "loading"
|
|
|
|
aid = btn[0].dataset.aId
|
|
|
|
$.ajax
|
|
|
|
url: '/ajax/destroy_answer' # TODO: find a way to use rake routes instead of hardcoding them here
|
|
|
|
type: 'POST'
|
|
|
|
data:
|
|
|
|
answer: aid
|
|
|
|
success: (data, status, jqxhr) ->
|
|
|
|
if data.success
|
|
|
|
$("div.answer-box[data-id=#{aid}]").slideUp()
|
|
|
|
showSnackbar data.message
|
|
|
|
error: (jqxhr, status, error) ->
|
|
|
|
console.log jqxhr, status, error
|
|
|
|
showSnackbar "An error occurred, a developer should check the console for details"
|
|
|
|
complete: (jqxhr, status) ->
|
|
|
|
btn.button "reset"
|
|
|
|
|
2014-11-10 09:19:04 -08:00
|
|
|
$(document).on "click", "button#create-account", ->
|
|
|
|
Turbolinks.visit "/sign_up"
|
|
|
|
|
|
|
|
$(document).on "click", "button#new-question", ->
|
|
|
|
$("div#question-box").show()
|
|
|
|
$("div#question-box-promote").hide()
|