mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-01-31 15:39:11 +01:00
users now can answer other people's questions
This commit is contained in:
parent
496ff61a65
commit
f4d63ae4e3
2 changed files with 56 additions and 7 deletions
35
app/assets/javascripts/question.coffee
Normal file
35
app/assets/javascripts/question.coffee
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
$(document).on "keydown", "textarea#q-answer", (evt) ->
|
||||||
|
qid = $(this)[0].dataset.id
|
||||||
|
if evt.keyCode == 13 and evt.ctrlKey
|
||||||
|
# trigger warning:
|
||||||
|
$("button#q-answer[data-q-id=#{qid}]").trigger 'click'
|
||||||
|
|
||||||
|
|
||||||
|
$(document).on "click", "button#q-answer", ->
|
||||||
|
btn = $(this)
|
||||||
|
btn.button "loading"
|
||||||
|
qid = btn[0].dataset.qId
|
||||||
|
$("textarea#q-answer[data-q=#{qid}]").attr "readonly", "readonly"
|
||||||
|
|
||||||
|
shareTo = []
|
||||||
|
($ "input[type=checkbox][name=share][data-q-id=#{qid}]:checked").each (i, share) ->
|
||||||
|
shareTo.push share.dataset.service
|
||||||
|
|
||||||
|
$.ajax
|
||||||
|
url: '/ajax/answer'
|
||||||
|
type: 'POST'
|
||||||
|
data:
|
||||||
|
id: qid
|
||||||
|
answer: $("textarea#q-answer[data-id=#{qid}]").val()
|
||||||
|
share: JSON.stringify shareTo
|
||||||
|
inbox: false
|
||||||
|
success: (data, status, jqxhr) ->
|
||||||
|
if data.success
|
||||||
|
$("div#q-answer-box").slideUp()
|
||||||
|
showNotification data.message, data.success
|
||||||
|
error: (jqxhr, status, error) ->
|
||||||
|
console.log jqxhr, status, error
|
||||||
|
showNotification "An error occurred, a developer should check the console for details", false
|
||||||
|
complete: (jqxhr, status) ->
|
||||||
|
btn.button "reset"
|
||||||
|
$("textarea#q-answer[data-id=#{qid}]").removeAttr "readonly"
|
|
@ -5,13 +5,27 @@
|
||||||
- unless @question.author_is_anonymous
|
- unless @question.author_is_anonymous
|
||||||
%a.pull-left{href: show_user_profile_path(@question.user.screen_name)}
|
%a.pull-left{href: show_user_profile_path(@question.user.screen_name)}
|
||||||
%img.img-rounded.answerbox--img{src: gravatar_url(@question.user)}
|
%img.img-rounded.answerbox--img{src: gravatar_url(@question.user)}
|
||||||
.media-body
|
.media-body
|
||||||
%h6.text-muted.media-heading.answerbox--question-user
|
%h6.text-muted.media-heading.answerbox--question-user
|
||||||
= user_screen_name @question.user, @question.author_is_anonymous
|
= user_screen_name @question.user, @question.author_is_anonymous
|
||||||
asked
|
asked
|
||||||
= time_ago_in_words(@question.created_at)
|
= time_ago_in_words(@question.created_at)
|
||||||
ago
|
ago
|
||||||
%p.answerbox--question-text= @question.content
|
%p.answerbox--question-text= @question.content
|
||||||
|
|
||||||
|
- if user_signed_in? and !current_user.answered? @question
|
||||||
|
#q-answer-box
|
||||||
|
Add your Senf here:
|
||||||
|
.panel-body
|
||||||
|
%textarea#q-answer.form-control{placeholder: 'Write your answer here...', data: { id: @question.id }}
|
||||||
|
%br/
|
||||||
|
%button#q-answer.btn.btn-success{data: { q_id: @question.id }}
|
||||||
|
Answer
|
||||||
|
- current_user.services.each do |service|
|
||||||
|
%label
|
||||||
|
%input{type: 'checkbox', name: 'share', checked: :checked, data: { q_id: @question.id, service: service.provider }}
|
||||||
|
Post to
|
||||||
|
= service.provider.capitalize
|
||||||
|
|
||||||
- @answers.each do |a|
|
- @answers.each do |a|
|
||||||
= render 'shared/answerbox', a: a, show_question: false
|
= render 'shared/answerbox', a: a, show_question: false
|
||||||
|
|
Loading…
Reference in a new issue