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"
iid = btn[0].dataset.ibId
$("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
url: '/ajax/answer' # TODO: find a way to use rake routes instead of hardcoding them here
url: '/ajax/answer'
type: 'POST'
data:
id: iid
answer: $("textarea[name=ib-answer][data-id=#{iid}]").val()
share: JSON.stringify shareTo
success: (data, status, jqxhr) ->
if data.success
$("div.inbox-box[data-id=#{iid}]").slideUp()

View File

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

View File

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