From 013d1d44b7e5ba19fcea928b030d61d68d97afa7 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 13 Dec 2014 15:17:50 +0100 Subject: [PATCH] the checkbox should now share to services --- app/assets/javascripts/inbox.coffee | 8 +++++++- app/controllers/ajax/inbox_controller.rb | 5 ++++- app/views/inbox/_entry.html.haml | 8 +++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/inbox.coffee b/app/assets/javascripts/inbox.coffee index c6d13d4b..87bd87e9 100644 --- a/app/assets/javascripts/inbox.coffee +++ b/app/assets/javascripts/inbox.coffee @@ -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() diff --git a/app/controllers/ajax/inbox_controller.rb b/app/controllers/ajax/inbox_controller.rb index 90bb36ff..5cf8132d 100644 --- a/app/controllers/ajax/inbox_controller.rb +++ b/app/controllers/ajax/inbox_controller.rb @@ -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 diff --git a/app/views/inbox/_entry.html.haml b/app/views/inbox/_entry.html.haml index 4817f59e..2aa9f6cc 100644 --- a/app/views/inbox/_entry.html.haml +++ b/app/views/inbox/_entry.html.haml @@ -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 \ No newline at end of file + - 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 \ No newline at end of file