the checkbox should now share to services

This commit is contained in:
nilsding 2014-12-13 15:17:50 +01:00
parent 6e154bc462
commit 013d1d44b7
3 changed files with 16 additions and 5 deletions

View File

@ -25,12 +25,18 @@ $(document).on "click", "button[name=ib-answer]", ->
btn.button "loading" btn.button "loading"
iid = btn[0].dataset.ibId iid = btn[0].dataset.ibId
$("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly" $("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly"
shareTo = []
($ "input[type=checkbox][name=ib-share][data-ib-id=#{iid}]:checked").each (i, share) ->
shareTo.push share.dataset.service
$.ajax $.ajax
url: '/ajax/answer' # TODO: find a way to use rake routes instead of hardcoding them here url: '/ajax/answer'
type: 'POST' type: 'POST'
data: data:
id: iid id: iid
answer: $("textarea[name=ib-answer][data-id=#{iid}]").val() answer: $("textarea[name=ib-answer][data-id=#{iid}]").val()
share: JSON.stringify shareTo
success: (data, status, jqxhr) -> success: (data, status, jqxhr) ->
if data.success if data.success
$("div.inbox-box[data-id=#{iid}]").slideUp() $("div.inbox-box[data-id=#{iid}]").slideUp()

View File

@ -24,6 +24,7 @@ class Ajax::InboxController < ApplicationController
def destroy def destroy
params.require :id params.require :id
params.require :answer params.require :answer
params.require :share
inbox = Inbox.find(params[:id]) inbox = Inbox.find(params[:id])
@ -45,9 +46,11 @@ class Ajax::InboxController < ApplicationController
return return
end end
# sharing
share_to = JSON.parse params[:share]
Thread.new do Thread.new do
current_user.services.each do |service| current_user.services.each do |service|
service.post answer service.post answer if share_to.include? service.provider
end end
end end

View File

@ -23,6 +23,8 @@
Answer Answer
%button.btn.btn-danger{name: 'ib-destroy', data: { ib_id: i.id }} %button.btn.btn-danger{name: 'ib-destroy', data: { ib_id: i.id }}
Delete Delete
- current_user.services.each do |service|
%label %label
%input{type: 'checkbox', name: 'ib-share-twitter'} %input{type: 'checkbox', name: 'ib-share', data: { ib_id: i.id, service: service.provider }}
Post to Twitter Post to
= service.provider.capitalize