diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb
index 77a6b3e5a..51c0cef8d 100644
--- a/app/controllers/status_messages_controller.rb
+++ b/app/controllers/status_messages_controller.rb
@@ -10,6 +10,7 @@ class StatusMessagesController < ApplicationController
respond_to :json, :only => :show
def create
+ pp params
params[:status_message][:aspect_ids] = params[:aspect_ids]
photos = Photo.where(:id => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle)
diff --git a/app/views/shared/_publisher.html.haml b/app/views/shared/_publisher.html.haml
index 3c97ad4d3..420a08f88 100644
--- a/app/views/shared/_publisher.html.haml
+++ b/app/views/shared/_publisher.html.haml
@@ -46,11 +46,11 @@
%p.checkbox_select
= status.check_box( :public, {:title => t('.make_public')}, true, false)
- %span#publisher_service_icons.dim
- = link_to (image_tag "social_media_logos/feed-16x16.png", :title => "RSS"), current_user.public_url
+ %span#publisher_service_icons
+ = link_to (image_tag "social_media_logos/feed-16x16.png", :title => "RSS"), current_user.public_url, :class => 'public_icon dim'
- if current_user.services
- for service in current_user.services
- = image_tag "social_media_logos/#{service.provider}-16x16.png", :title => service.provider, :class => "service", :id =>"#{service.provider}"
+ = image_tag "social_media_logos/#{service.provider}-16x16.png", :title => service.provider, :class => "service_icon dim", :id =>"#{service.provider}"
= link_to '(?)', "#question_mark_pane", :class => 'question_mark', :style=>"display:none;", :rel => 'facebox'
diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js
index 282c5ddd5..22d2cdc33 100644
--- a/public/javascripts/publisher.js
+++ b/public/javascripts/publisher.js
@@ -283,13 +283,30 @@ var Publisher = {
$("#photodropzone").find('li').remove();
$("#publisher textarea").removeClass("with_attachments");
},
+ bindServiceIcons: function(){
+ $(".service_icon").bind("click", function(evt){
+ $(this).toggleClass("dim");
+ Publisher.toggleServiceField($(this).attr('id'));
+ });
+ },
+ toggleServiceField: function(service){
+ var hidden_field = $('#publisher [name="services[]"][value="'+service+'"]')
+ if(hidden_field.length > 0){
+ hidden_field.remove();
+ } else {
+ $("#publisher .content_creation form").append(
+ '');
+ };
+ },
initialize: function() {
Publisher.cachedForm = false;
Publisher.cachedInput = false;
Publisher.cachedHiddenInput = false;
Publisher.cachedSubmit = false;
+
+ Publisher.bindServiceIcons();
$("div.public_toggle input").live("click", function(evt) {
- $("#publisher_service_icons").toggleClass("dim");
+ $(".public_icon").toggleClass("dim");
if ($(this).attr('checked') == true) {
$(".question_mark").click();
}
diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb
index adcad98a6..d060e614c 100644
--- a/spec/controllers/aspects_controller_spec.rb
+++ b/spec/controllers/aspects_controller_spec.rb
@@ -65,6 +65,12 @@ describe AspectsController do
get :index, :prefill => "reshare things"
save_fixture(html_for("body"), "aspects_index_prefill")
end
+ it 'generates a jasmine fixture with services' do
+ @user.services << Services::Facebook.create(:user_id => @user.id)
+ @user.services << Services::Twitter.create(:user_id => @user.id)
+ get :index, :prefill => "reshare things"
+ save_fixture(html_for("body"), "aspects_index_services")
+ end
context 'filtering' do
before do
@posts = []
diff --git a/spec/javascripts/publisher-spec.js b/spec/javascripts/publisher-spec.js
index 89776ed5e..c58fb947a 100644
--- a/spec/javascripts/publisher-spec.js
+++ b/spec/javascripts/publisher-spec.js
@@ -20,6 +20,73 @@ describe("Publisher", function() {
expect(Publisher.close).wasNotCalled();
});
});
+
+ describe("bindServiceIcons", function() {
+ beforeEach( function(){
+ spec.loadFixture('aspects_index_services');
+ });
+
+ it('gets called on initialize', function(){
+ spyOn(Publisher, 'bindServiceIcons');
+ Publisher.initialize();
+ expect(Publisher.bindServiceIcons).toHaveBeenCalled();
+ });
+ it('binds to the services icons on click', function(){
+ expect("pending").toEqual("Is this a valid test? If so how do I test it?");
+ //spyOn($(".service"), 'bind');
+
+ //Publisher.bindServiceIcons();
+ //expect($(".service").bind).toHaveBeenCalled();
+ });
+ it('toggles dim only on the clicked icon', function(){
+ expect($(".service_icon#facebook").hasClass("dim")).toBeTruthy();
+ expect($(".service_icon#twitter").hasClass("dim")).toBeTruthy();
+
+ Publisher.bindServiceIcons();
+ $(".service_icon#facebook").click();
+
+ expect($(".service_icon#facebook").hasClass("dim")).toBeFalsy();
+ expect($(".service_icon#twitter").hasClass("dim")).toBeTruthy();
+ });
+ it('binds to the services icons and toggles the hidden field', function(){
+ spyOn(Publisher, 'toggleServiceField');
+ Publisher.bindServiceIcons();
+ $(".service_icon#facebook").click();
+
+ expect(Publisher.toggleServiceField).toHaveBeenCalledWith("facebook");
+ });
+ });
+
+ describe('toggleServiceField', function(){
+ beforeEach( function(){
+ spec.loadFixture('aspects_index_services');
+ });
+
+ it('adds a hidden field to the form if there is not one already', function(){
+ expect($('#publisher [name="services[]"]').length).toBe(0);
+ Publisher.toggleServiceField("facebook");
+ expect($('#publisher [name="services[]"]').length).toBe(1);
+ expect($('#publisher [name="services[]"]').attr('value')).toBe("facebook");
+ //
+ });
+
+ it('removes the hidden field if its already there', function() {
+ Publisher.toggleServiceField("facebook");
+ expect($('#publisher [name="services[]"]').length).toBe(1);
+
+ Publisher.toggleServiceField("facebook");
+ expect($('#publisher [name="services[]"]').length).toBe(0);
+ });
+
+ it('does not remove a hidden field with a different value', function() {
+ Publisher.toggleServiceField("facebook");
+ expect($('#publisher [name="services[]"]').length).toBe(1);
+
+ Publisher.toggleServiceField("twitter");
+ expect($('#publisher [name="services[]"]').length).toBe(2);
+ });
+ });
+
describe("open", function() {
beforeEach(function() {
spec.loadFixture('aspects_index');