answering works now.
This commit is contained in:
parent
1702c2fca4
commit
ba7bd2239b
|
@ -10,6 +10,12 @@
|
|||
NProgress.configure
|
||||
showSpinner: false
|
||||
|
||||
showSnackbar = (text) ->
|
||||
$.snackbar # allahu snackbar
|
||||
content: data.message
|
||||
style: "snackbar"
|
||||
timeout: 5000
|
||||
|
||||
$(document).on "click", "button[name=qb-ask]", ->
|
||||
btn = $(this)
|
||||
btn.button "loading"
|
||||
|
@ -32,22 +38,13 @@ $(document).on "click", "button[name=qb-ask]", ->
|
|||
if promote
|
||||
$("div#question-box").hide()
|
||||
$("div#question-box-promote").show()
|
||||
$.snackbar # allahu snackbar
|
||||
content: data.message
|
||||
style: "snackbar"
|
||||
timeout: 5000
|
||||
showSnackbar data.message
|
||||
else
|
||||
console.log data, status, jqxhr
|
||||
$.snackbar # allahu snackbar
|
||||
content: "An error occurred, a developer should check the console for details"
|
||||
style: "snackbar"
|
||||
timeout: 5000
|
||||
showSnackbar "An error occurred, a developer should check the console for details"
|
||||
error: (jqxhr, status, error) ->
|
||||
console.log jqxhr, status, error
|
||||
$.snackbar # allahu snackbar
|
||||
content: "An error occurred, a developer should check the console for details"
|
||||
style: "snackbar"
|
||||
timeout: 5000
|
||||
showSnackbar "An error occurred, a developer should check the console for details"
|
||||
complete: (jqxhr, status) ->
|
||||
btn.button "reset"
|
||||
$("textarea[name=qb-question]").removeAttr "readonly"
|
||||
|
@ -55,36 +52,27 @@ $(document).on "click", "button[name=qb-ask]", ->
|
|||
$(document).on "click", "button[name=ib-answer]", ->
|
||||
btn = $(this)
|
||||
btn.button "loading"
|
||||
iid = $("input[name=ib-id]").val()
|
||||
iid = btn[0].dataset.ibId
|
||||
$("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly"
|
||||
$.ajax
|
||||
url: '/ajax/inbox' # TODO: find a way to use rake routes instead of hardcoding them here
|
||||
url: '/ajax/answer' # TODO: find a way to use rake routes instead of hardcoding them here
|
||||
type: 'POST'
|
||||
data:
|
||||
id: iid
|
||||
answer: $("textarea[name=ib-answer]").val()
|
||||
answer: $("textarea[name=ib-answer][data-id=#{iid}]").val()
|
||||
success: (data, status, jqxhr) ->
|
||||
if data.success
|
||||
$("div#inbox-box[data-id=#{iid}]").val ''
|
||||
$("div#inbox-box").slideUp()
|
||||
$.snackbar # allahu snackbar
|
||||
content: data.message
|
||||
style: "snackbar"
|
||||
timeout: 5000
|
||||
$("div.inbox-box[data-id=#{iid}]").slideUp()
|
||||
showSnackbar data.message
|
||||
else
|
||||
console.log data, status, jqxhr
|
||||
$.snackbar # allahu snackbar
|
||||
content: "An error occurred, a developer should check the console for details"
|
||||
style: "snackbar"
|
||||
timeout: 5000
|
||||
showSnackbar "An error occurred, a developer should check the console for details"
|
||||
error: (jqxhr, status, error) ->
|
||||
console.log jqxhr, status, error
|
||||
$.snackbar # allahu snackbar
|
||||
content: "An error occurred, a developer should check the console for details"
|
||||
style: "snackbar"
|
||||
timeout: 5000
|
||||
showSnackbar "An error occurred, a developer should check the console for details"
|
||||
complete: (jqxhr, status) ->
|
||||
btn.button "reset"
|
||||
$("textarea[name=qb-question]").removeAttr "readonly"
|
||||
$("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly"
|
||||
|
||||
$(document).on "click", "button#create-account", ->
|
||||
Turbolinks.visit "/sign_up"
|
||||
|
|
|
@ -11,9 +11,9 @@ class Ajax::InboxController < ApplicationController
|
|||
current_user.increment! :answered_count
|
||||
end
|
||||
|
||||
inbox = Inbox.find(params[:id]).first
|
||||
inbox = Inbox.find(params[:id])
|
||||
|
||||
unless current_user.id == Inbox.user_id
|
||||
unless current_user == inbox.user
|
||||
@status = :fail
|
||||
@message = "question not in your inbox"
|
||||
@success = false
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
%ul
|
||||
.container.j2-page
|
||||
- @inbox.each do |i|
|
||||
%li
|
||||
%strong
|
||||
= user_screen_name i.question.user
|
||||
asked
|
||||
= i.question.content
|
||||
.panel.inbox-box{'data-id' => i.id}
|
||||
%p
|
||||
%strong
|
||||
= user_screen_name i.question.user
|
||||
asked:
|
||||
%p
|
||||
%strong
|
||||
= i.question.content
|
||||
%textarea{name: 'ib-answer', 'data-id' => i.id}
|
||||
%br/
|
||||
%button.btn.btn-success{name: 'ib-answer', 'data-ib-id' => i.id}
|
||||
Answer
|
||||
|
|
Loading…
Reference in New Issue