can now select individual services to be added

This commit is contained in:
zhitomirskiyi 2011-02-24 15:53:29 -08:00
parent e61cc2fd34
commit adfcc59631
5 changed files with 95 additions and 4 deletions

View file

@ -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)

View file

@ -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'

View file

@ -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(
'<input id="services_" name="services[]" type="hidden" value="'+service+'">');
};
},
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();
}

View file

@ -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 = []

View file

@ -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");
//<input id="aspect_ids_" name="aspect_ids[]" type="hidden" value="1">
});
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');