diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 8dfd1d480..d9118c9b8 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -15,7 +15,7 @@ class AspectsController < ApplicationController @aspect = :all @contact_hashes = hashes_for_contacts @contacts - + if current_user.getting_started == true redirect_to getting_started_path end @@ -48,7 +48,7 @@ class AspectsController < ApplicationController begin current_user.drop_aspect @aspect flash[:notice] = I18n.t 'aspects.destroy.success',:name => @aspect.name - rescue RuntimeError => e + rescue RuntimeError => e flash[:error] = e.message end @@ -106,12 +106,21 @@ class AspectsController < ApplicationController def add_to_aspect begin current_user.add_person_to_aspect( params[:person_id], params[:aspect_id]) + + @aspect = current_user.aspects.find(params[:aspect_id]) + @aspect_id = @aspect.id @person_id = params[:person_id] - @aspect_id = params[:aspect_id] + flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success' respond_to do |format| - format.js { render :status => 200 } + format.js { render :json => { + :button_html => render_to_string(:partial => 'aspects/add_to_aspect', + :locals => {:aspect_id => @aspect_id, + :person_id => @person_id}), + :badge_html => render_to_string(:partial => 'aspects/aspect_badge', + :locals => {:aspect => @aspect}) + }} format.html{ redirect_to aspect_path(@aspect_id)} end rescue Exception => e @@ -130,7 +139,12 @@ class AspectsController < ApplicationController flash.now[:notice] = I18n.t 'aspects.remove_from_aspect.success' respond_to do |format| - format.js { render :status => 200 } + format.js { render :json => {:button_html => + render_to_string(:partial => 'aspects/remove_from_aspect', + :locals => {:aspect_id => @aspect_id, + :person_id => @person_id}), + :aspect_id => @aspect_id + }} format.html{ redirect_to aspect_path(@aspect_id)} end rescue Exception => e @@ -142,7 +156,7 @@ class AspectsController < ApplicationController end end end - + private def hashes_for_contacts contacts people = Person.all(:id.in => contacts.map{|c| c.person_id}, :fields => [:profile]) @@ -154,7 +168,7 @@ class AspectsController < ApplicationController def hashes_for_aspects aspects, contacts, opts = {} aspects.map do |a| hash = {:aspect => a} - aspect_contacts = contacts.select{|c| + aspect_contacts = contacts.select{|c| c.aspect_ids.include?(a.id)} hash[:contact_count] = aspect_contacts.count person_ids = aspect_contacts.map{|c| c.person_id} diff --git a/app/views/aspects/_add_to_aspect.haml b/app/views/aspects/_add_to_aspect.haml new file mode 100644 index 000000000..ae6ee1be7 --- /dev/null +++ b/app/views/aspects/_add_to_aspect.haml @@ -0,0 +1,7 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + += remove_from_aspect_button(aspect_id,person_id) + diff --git a/app/views/aspects/_aspect_badge.haml b/app/views/aspects/_aspect_badge.haml new file mode 100644 index 000000000..3d92edfd1 --- /dev/null +++ b/app/views/aspects/_aspect_badge.haml @@ -0,0 +1,7 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +.aspect_badge.single{:guid=>aspect.id} + = link_to aspect.name, aspect diff --git a/app/views/aspects/_aspect_contacts.haml b/app/views/aspects/_aspect_contacts.haml index 7b1f30218..70871235c 100644 --- a/app/views/aspects/_aspect_contacts.haml +++ b/app/views/aspects/_aspect_contacts.haml @@ -21,6 +21,9 @@ - for contact in contacts = person_image_link(contact[:person]) + %br + %br + %br .section %h3= t('shared.invitations.invites') = render "shared/invitations", :invites => @invites diff --git a/app/views/aspects/_remove_from_aspect.haml b/app/views/aspects/_remove_from_aspect.haml new file mode 100644 index 000000000..606997d90 --- /dev/null +++ b/app/views/aspects/_remove_from_aspect.haml @@ -0,0 +1,7 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + += add_to_aspect_button(aspect_id,person_id) + diff --git a/app/views/people/_aspect_list.haml b/app/views/people/_aspect_list.haml new file mode 100644 index 000000000..0cc238fb2 --- /dev/null +++ b/app/views/people/_aspect_list.haml @@ -0,0 +1,50 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +- content_for :head do + =javascript_include_tag 'contact-list' + + :javascript + $(document).ready(function() { + $("#edit_contact_aspects").click(function(evt){ + evt.preventDefault(); + $(".badges").fadeOut(200, function(){ + $(".edit").fadeIn(200); + }); + }); + + $("#done_contact_aspects").click(function(evt){ + evt.preventDefault(); + $(".edit").fadeOut(200, function(){ + $(".badges").fadeIn(200); + }); + }); + }); + +.aspects + .badges + - for aspect in aspects_with_person + = render :partial => 'aspects/aspect_badge', :locals => {:aspect => aspect} + .right + = link_to "edit aspect membership", "#", :id=> "edit_contact_aspects" + + .edit + .contact_list + %ul + - for aspect in aspects_with_person + %li + %span.name + = link_to aspect.name, aspect + .right + = aspect_membership_button(aspect.id, contact) + + - for aspect in aspects_without_person + %li + %span.name + = link_to aspect.name, aspect + .right + = aspect_membership_button(aspect.id, contact) + + .right + = link_to "done editing", "#", :id => "done_contact_aspects" diff --git a/app/views/people/_profile_sidebar.html.haml b/app/views/people/_profile_sidebar.html.haml index a695881d3..0820dbb57 100644 --- a/app/views/people/_profile_sidebar.html.haml +++ b/app/views/people/_profile_sidebar.html.haml @@ -16,25 +16,24 @@ #profile .profile_photo - = person_image_link(person, :to => :photos) + = person_image_link(person, :size => :thumb_large, :to => :photos) %p - = action_link(person, is_contact) + = action_link(person, contact) %hr{:style=>"width:300px;"} %ul - - if is_contact + - if contact %li - %ul#aspects_for_person - %b= t('.in_aspects') - %br - - for aspect in @aspects_with_person - %li - = link_to aspect.name, aspect - = link_to "x", {:controller => "aspects", :action => "remove_from_aspect", :person_id => person.id, :aspect_id => aspect.id}, :confirm => t('.remove_from', :name => person.name, :aspect => aspect), :remote => true, :class => "delete" + = render :partial => 'people/aspect_list', + :locals => {:contact => contact, + :aspects_with_person => @aspects_with_person, + :aspects_without_person => @aspects.reject{ |aspect| @aspects_with_person.include?(aspect)}} + %br + %hr{:style=>"width:300px;"} - -if is_contact || person == current_user.person + -if contact || person == current_user.person %ul#profile_information %li %h3 #{t('.bio')} diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 97dc45177..6a0e4a2bf 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -19,28 +19,28 @@ = link_to t('_photos'), person_photos_path(@person) .span-8.append-1.last - = render :partial => 'people/profile_sidebar', :locals => {:person => @person, :is_contact => @contact} + = render :partial => 'people/profile_sidebar', :locals => {:person => @person, :contact => @contact} .span-15.last - unless @contact || current_user.person == @person - if current_user.has_incoming_request_from(@person) .floating - %h3 - = t('.incoming_request') + %h3 + = t('.incoming_request') %h4 = link_to t('.return_to_aspects'), aspects_manage_path = t('.to_accept_or_ignore') - + - else .floating %h3 = t('.not_connected', :name => @person.name) - + - unless pending_request_for(@person) %h3 .description = t('.request_people') - + = render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :destination_handle => @person.diaspora_handle} - else diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index a5fabe864..91dac84c4 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -3,7 +3,7 @@ -# the COPYRIGHT file. %li.message{:data=>{:guid=>post.id}} - =person_image_link(person) + =person_image_link(person, :size => :thumb_small) .content .from diff --git a/public/javascripts/contact-list.js b/public/javascripts/contact-list.js index 7482b6221..6f544ac05 100644 --- a/public/javascripts/contact-list.js +++ b/public/javascripts/contact-list.js @@ -5,7 +5,7 @@ $(document).ready( function(){ - var ContactList = { + var List = { initialize: function(){ $(".contact_list_search").keyup(function(e){ var search = $(this); @@ -23,32 +23,25 @@ $(document).ready( function(){ } }); }); - }, - - refreshContactCount: function(){ - var contactCountElement = $(".aspect_contact_count"), - contactCount = $(".contact_pictures")[0].childElementCount, - newHTML = contactCountElement.html().replace(/\d+/,contactCount); - - contactCountElement.html(newHTML); } }; - $('.added').live('ajax:loading', function(data, html, xhr) { + $('.added').live('ajax:loading', function() { $(this).fadeTo(200,0.4); }); - $('.added').live('ajax:success', function(data, html, xhr) { - var person_id = $(this).closest("li").find(".avatar").attr("data-person_id"); - $(".contact_pictures").find("img[data-person_id='"+person_id+"']").parent().remove(); + $('.added').live('ajax:success', function(data, json, xhr) { + var json = $.parseJSON(json); + var contactPictures = $(".contact_pictures"); - $(this).parent().html(html); - ContactList.refreshContactCount(); - - if( $(".contact_pictures")[0].childElementCount == 0 ) { - $("#no_contacts").fadeIn(200); + if( contactPictures.length > 0 ) { + if( contactPictures[0].childElementCount == 0 ) { + $("#no_contacts").fadeIn(200); + } } + $(".aspect_badge[guid='"+json['aspect_id']+"']", ".aspects").remove(); + $(this).parent().html(json['button_html']); $(this).fadeTo(200,1); }); @@ -57,21 +50,18 @@ $(document).ready( function(){ $(this).fadeTo(200,1); }); - $('.add').live('ajax:loading', function(data, html, xhr) { + $('.add').live('ajax:loading', function() { $(this).fadeTo(200,0.4); }); - $('.add').live('ajax:success', function(data, html, xhr) { - var person_image = $(this).closest("li").find(".avatar") - person_image.parent().clone().appendTo(".contact_pictures"); - - $(this).parent().html(html); - ContactList.refreshContactCount(); - + $('.add').live('ajax:success', function(data, json, xhr) { + var json = $.parseJSON(json); if( $("#no_contacts").is(':visible') ) { $("#no_contacts").fadeOut(200); } + $(".badges").prepend(json['badge_html']); + $(this).parent().html(json['button_html']); $(this).fadeTo(200,1); }); @@ -83,5 +73,5 @@ $(document).ready( function(){ $(this).children("img").attr("src","/images/icons/monotone_check_yes.png"); }); - ContactList.initialize(); + List.initialize(); }); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 87fc6a6e2..97a763a4f 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -2003,6 +2003,24 @@ h3,h4 &:hover :color #eee +.aspects + :position relative + + .right + :right 12px + + .contact_list + :height auto + :max-height auto + :width 298px + + .edit + :display none + +.aspects .aspect_badge + :font + :size 1em + .aspect_badge.public :background :color #C0E76C @@ -2023,3 +2041,4 @@ h3,h4 :top -0.1em .aspect_badge :top -0.2em +