answering works now.

This commit is contained in:
nilsding 2014-11-11 18:02:59 +01:00
parent 1702c2fca4
commit ba7bd2239b
3 changed files with 33 additions and 38 deletions

View File

@ -10,6 +10,12 @@
NProgress.configure NProgress.configure
showSpinner: false showSpinner: false
showSnackbar = (text) ->
$.snackbar # allahu snackbar
content: data.message
style: "snackbar"
timeout: 5000
$(document).on "click", "button[name=qb-ask]", -> $(document).on "click", "button[name=qb-ask]", ->
btn = $(this) btn = $(this)
btn.button "loading" btn.button "loading"
@ -32,22 +38,13 @@ $(document).on "click", "button[name=qb-ask]", ->
if promote if promote
$("div#question-box").hide() $("div#question-box").hide()
$("div#question-box-promote").show() $("div#question-box-promote").show()
$.snackbar # allahu snackbar showSnackbar data.message
content: data.message
style: "snackbar"
timeout: 5000
else else
console.log data, status, jqxhr console.log data, status, jqxhr
$.snackbar # allahu snackbar showSnackbar "An error occurred, a developer should check the console for details"
content: "An error occurred, a developer should check the console for details"
style: "snackbar"
timeout: 5000
error: (jqxhr, status, error) -> error: (jqxhr, status, error) ->
console.log jqxhr, status, error console.log jqxhr, status, error
$.snackbar # allahu snackbar showSnackbar "An error occurred, a developer should check the console for details"
content: "An error occurred, a developer should check the console for details"
style: "snackbar"
timeout: 5000
complete: (jqxhr, status) -> complete: (jqxhr, status) ->
btn.button "reset" btn.button "reset"
$("textarea[name=qb-question]").removeAttr "readonly" $("textarea[name=qb-question]").removeAttr "readonly"
@ -55,36 +52,27 @@ $(document).on "click", "button[name=qb-ask]", ->
$(document).on "click", "button[name=ib-answer]", -> $(document).on "click", "button[name=ib-answer]", ->
btn = $(this) btn = $(this)
btn.button "loading" 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 $.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' type: 'POST'
data: data:
id: iid id: iid
answer: $("textarea[name=ib-answer]").val() answer: $("textarea[name=ib-answer][data-id=#{iid}]").val()
success: (data, status, jqxhr) -> success: (data, status, jqxhr) ->
if data.success if data.success
$("div#inbox-box[data-id=#{iid}]").val '' $("div.inbox-box[data-id=#{iid}]").slideUp()
$("div#inbox-box").slideUp() showSnackbar data.message
$.snackbar # allahu snackbar
content: data.message
style: "snackbar"
timeout: 5000
else else
console.log data, status, jqxhr console.log data, status, jqxhr
$.snackbar # allahu snackbar showSnackbar "An error occurred, a developer should check the console for details"
content: "An error occurred, a developer should check the console for details"
style: "snackbar"
timeout: 5000
error: (jqxhr, status, error) -> error: (jqxhr, status, error) ->
console.log jqxhr, status, error console.log jqxhr, status, error
$.snackbar # allahu snackbar showSnackbar "An error occurred, a developer should check the console for details"
content: "An error occurred, a developer should check the console for details"
style: "snackbar"
timeout: 5000
complete: (jqxhr, status) -> complete: (jqxhr, status) ->
btn.button "reset" btn.button "reset"
$("textarea[name=qb-question]").removeAttr "readonly" $("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly"
$(document).on "click", "button#create-account", -> $(document).on "click", "button#create-account", ->
Turbolinks.visit "/sign_up" Turbolinks.visit "/sign_up"

View File

@ -11,9 +11,9 @@ class Ajax::InboxController < ApplicationController
current_user.increment! :answered_count current_user.increment! :answered_count
end 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 @status = :fail
@message = "question not in your inbox" @message = "question not in your inbox"
@success = false @success = false

View File

@ -1,7 +1,14 @@
%ul .container.j2-page
- @inbox.each do |i| - @inbox.each do |i|
%li .panel.inbox-box{'data-id' => i.id}
%p
%strong %strong
= user_screen_name i.question.user = user_screen_name i.question.user
asked asked:
%p
%strong
= i.question.content = 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