From df4ebb286d525ac48d702472e15c1c765153fe61 Mon Sep 17 00:00:00 2001
From: zhitomirskiyi <ilya@joindiaspora.com>
Date: Thu, 3 Feb 2011 17:03:57 -0800
Subject: [PATCH] accept invitation feature passing

wip, added a form to add aspect to the contact list

added files

typo

render the partial

remote friend

specifying the provider for the route

refactored local person person friend finder functionality to use the partial

typo

trying to use the stream
---
 app/controllers/aspects_controller.rb         |  13 +++-
 app/controllers/users_controller.rb           |   5 +-
 app/views/aspects/_aspect_list_item.haml      |   9 +++
 app/views/people/_person.html.haml            |   9 ++-
 app/views/people/_share_with_pane.html.haml   |  31 ++++++---
 app/views/services/_finder.html.haml          |   8 +++
 app/views/services/_remote_friend.html.haml   |  51 ++++++--------
 app/views/services/finder.html.haml           |   5 +-
 .../users/getting_started/_step_3.html.haml   |  62 ++++--------------
 features/accepts_invitation.feature           |  14 +++-
 features/connects_users.feature               |  25 +++++--
 public/images/icons/monotone_add_plus.png     | Bin 0 -> 228 bytes
 public/javascripts/contact-list.js            |   5 ++
 13 files changed, 133 insertions(+), 104 deletions(-)
 create mode 100644 app/views/aspects/_aspect_list_item.haml
 create mode 100644 app/views/services/_finder.html.haml
 create mode 100644 public/images/icons/monotone_add_plus.png

diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb
index 56c34f0bc7..9efce5a0f3 100644
--- a/app/controllers/aspects_controller.rb
+++ b/app/controllers/aspects_controller.rb
@@ -6,7 +6,7 @@ class AspectsController < ApplicationController
   before_filter :authenticate_user!
 
   respond_to :html
-  respond_to :json, :only => :show
+  respond_to :json, :only => [:show, :create]
   respond_to :js
 
   def index
@@ -47,6 +47,17 @@ class AspectsController < ApplicationController
         redirect_to :back
       elsif request.env['HTTP_REFERER'].include?("aspects/manage")
         redirect_to :back
+      elsif params[:aspect][:share_with]
+        @contact = Contact.where(:id => params[:aspect][:contact_id]).first
+        @person = Person.where(:id => params[:aspect][:person_id]).first
+        respond_to do |format|
+          format.js { render :json => {:html => render_to_string(
+              :partial => 'aspects/aspect_list_item',
+              :locals => {:aspect => @aspect,
+                            :person => @person,
+                            :contact => @contact}
+                                      )},:status => 201 }
+              end
       else
         respond_with @aspect
       end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 61196f2887..761ac79246 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -83,7 +83,10 @@ class UsersController < ApplicationController
     @step = ((params[:step].to_i>0)&&(params[:step].to_i<5)) ? params[:step].to_i : 1
     @step ||= 1
 
-    if @step == 4
+    if @step == 3
+      service = current_user.services.where(:type => "Services::Facebook").first
+      @friends = service ? service.finder : {}
+    elsif @step == 4
       @user.getting_started = false
       @user.save
     end
diff --git a/app/views/aspects/_aspect_list_item.haml b/app/views/aspects/_aspect_list_item.haml
new file mode 100644
index 0000000000..8ee855aa15
--- /dev/null
+++ b/app/views/aspects/_aspect_list_item.haml
@@ -0,0 +1,9 @@
+-#   Copyright (c) 2010, Diaspora Inc.  This file is
+-#   licensed under the Affero General Public License version 3 or later.  See
+-#   the COPYRIGHT file.
+
+%li{:data=>{:guid=>aspect.id}}
+  %span.name
+    = link_to aspect.name, aspect
+  .right
+    = aspect_membership_button(aspect, contact, person)
diff --git a/app/views/people/_person.html.haml b/app/views/people/_person.html.haml
index cc424791d4..228ad17e09 100644
--- a/app/views/people/_person.html.haml
+++ b/app/views/people/_person.html.haml
@@ -9,8 +9,15 @@
       = t('.thats_you')
     - elsif contact && !contact.pending
       = t('.already_connected')
-    - elsif (contact && contact.pending) || request
+    - elsif (contact && contact.pending) || (request && request.recipient == person)
       = t('.pending_request')
+    - elsif request && request.sender == person
+      = link_to t('people.show.incoming_request', :name => truncate(person.name, :length => 20, :separator => ' ', :omission => '')),
+        {:controller => "people",
+        :action => "share_with",
+        :id => person.id},
+        :class => 'share_with button',
+        :rel => 'facebox'
     - else
       = link_to t('people.show.start_sharing'),
         {:controller => "people",
diff --git a/app/views/people/_share_with_pane.html.haml b/app/views/people/_share_with_pane.html.haml
index 74c5ced8b3..7ee48f4573 100644
--- a/app/views/people/_share_with_pane.html.haml
+++ b/app/views/people/_share_with_pane.html.haml
@@ -5,16 +5,27 @@
 .aspect_list#aspects_list
   %ul
     - for aspect in aspects_with_person
-      %li{:data=>{:guid=>aspect.id}}
-        %span.name
-          = link_to aspect.name, aspect
-        .right
-          = aspect_membership_button(aspect, contact, person)
+      = render :partial => 'aspects/aspect_list_item', 
+               :locals => {:aspect => aspect, :person => person,
+                           :contact => contact}
 
     - for aspect in aspects_without_person
-      %li{:data=>{:guid=>aspect.id}}
-        %span.name
-          = link_to aspect.name, aspect
-        .right
-          = aspect_membership_button(aspect, contact, person)
+      = render :partial => 'aspects/aspect_list_item', 
+               :locals => {:aspect => aspect, :person => person,
+                           :contact => contact}
+
+.add_aspect
+  = t('users.getting_started.step_3.aspect_name')
+  = form_for(Aspect.new, :remote => true) do |aspect|
+    = aspect.error_messages
+    = aspect.hidden_field :person_id, :value => person.id if person
+    = aspect.hidden_field :contact_id, :value => contact.id if contact
+    = aspect.hidden_field :share_with, :value => true
+    = aspect.text_field :name, :id => "step-3-aspect-name", :style => "display:inline;"
+    %p.checkbox_select
+      = aspect.label :contacts_visible, t('aspects.edit.make_aspect_list_visible')
+      = aspect.check_box :contacts_visible, :default => true
+    .right
+      = aspect.submit :src => '/images/icons/monotone_add_plus.png', :type => "image", :value => "", :class => 'button'
+
 
diff --git a/app/views/services/_finder.html.haml b/app/views/services/_finder.html.haml
new file mode 100644
index 0000000000..f505950077
--- /dev/null
+++ b/app/views/services/_finder.html.haml
@@ -0,0 +1,8 @@
+-#   Copyright (c) 2010, Diaspora Inc.  This file is
+-#   licensed under the Affero General Public License version 3 or later.  See
+-#   the COPYRIGHT file.
+
+= search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('shared.contact_list.all_contacts')
+%ul
+  - for uid in friends.keys
+    = render :partial => 'services/remote_friend', :locals => {:friend => friends[uid], :uid => uid}
diff --git a/app/views/services/_remote_friend.html.haml b/app/views/services/_remote_friend.html.haml
index 800970cf33..fa28a2f91a 100644
--- a/app/views/services/_remote_friend.html.haml
+++ b/app/views/services/_remote_friend.html.haml
@@ -1,35 +1,22 @@
 %li
-  .right
-    -if friend[:contact] && !friend[:contact].pending
-      = t('people.person.already_connected')
-    - elsif (friend[:contact] && friend[:contact].pending)
-      = t('people.person.pending_request')
-    - elsif friend[:invitation_id]
-      = t('invitations.new.already_invited')
-      %br
-      = link_to t('.resend'), service_inviter_path(:uid => uid, :provider => 'facebook', :invitation_id => friend[:invitation_id])
-    - elsif friend[:person]
-      = link_to t('people.show.start_sharing'),
-        {:controller => "people",
-        :action => "show",
-        :id => friend[:person].id,
-        :share_with => true},
-        :class => 'button'
+  -if friend[:person]
+    = render :partial => 'people/person', :locals => {:person => friend[:person], :contact => friend[:contact], :request => friend[:request]}
+  -else
+    .stream_element
+      .right
+        -if friend[:invitation_id]
+          = t('invitations.new.already_invited')
+          %br
+          = link_to t('.resend'), service_inviter_path(:uid => uid, :provider => 'facebook', :invitation_id => friend[:invitation_id])
+        - elsif current_user.invites > 0
+          = form_tag service_inviter_path(:provider => 'facebook') do
+            = select_tag(:aspect_id, options_from_collection_for_select(@all_aspects, 'id', 'name'))
+            = hidden_field_tag :uid, uid
+            = submit_tag t('.invite')
 
-    - elsif current_user.invites > 0
-      = form_tag service_inviter_path do
-        = select_tag(:aspect_id, options_from_collection_for_select(@all_aspects, 'id', 'name'))
-        = hidden_field_tag :uid, uid
-        = hidden_field_tag :provider, 'facebook'
-        = submit_tag t('.invite')
+    
+      = image_tag('/images/user/default.png', :class => 'avatar')
 
-  - if friend[:person]
-    = person_image_link(friend[:person])
-  - else
-    = image_tag('/images/user/default.png', :class => 'avatar')
-
-  %h4.name
-    - if friend[:person]
-      = link_to friend[:name], person_path(friend[:person])
-    - else
-      = friend[:name]
+      .content
+        %span.from
+          = friend[:name]
diff --git a/app/views/services/finder.html.haml b/app/views/services/finder.html.haml
index f26e73375c..f3256ab068 100644
--- a/app/views/services/finder.html.haml
+++ b/app/views/services/finder.html.haml
@@ -18,10 +18,7 @@
 
   .contact_list
     - if @friends.keys.length > 0
-      = search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('shared.contact_list.all_contacts')
-      %ul
-        - for uid in @friends.keys
-          = render :partial => 'remote_friend', :locals => {:friend => @friends[uid], :uid => uid}
+      = render :partial => 'services/finder', :locals => {:friends => @friends}
     - else
       %br
       %br
diff --git a/app/views/users/getting_started/_step_3.html.haml b/app/views/users/getting_started/_step_3.html.haml
index 8ff298d55e..de5cb05c72 100644
--- a/app/views/users/getting_started/_step_3.html.haml
+++ b/app/views/users/getting_started/_step_3.html.haml
@@ -8,55 +8,21 @@
   = t('.your_aspects')
   .description
     = t('.description')
+    -if @requests.length > 0
+      %br 
+      = t('.your_inviter')
+      %br
+
+      #people_stream.stream
+        - for pending_req in @requests
+          - person = pending_req.sender
+          
+          = render :partial => 'people/person', :locals => {:request => pending_req, :person => person, :contact => nil}
+    -unless @friends.blank?
+      %br
+      .contact_list
+        = render :partial => 'services/finder', :locals => {:friends => @friends, :getting_started => true}
 
--if @requests.size > 0
-  %h3
-    = t('.your_inviter')
-
-  %h3
-    %ul.dropzone
-      - if @requests.size < 1
-        %li=t('.no_requests')
-      - else
-        - for request in @requests
-          %li.person.request{:data=>{:guid=>request.id, :person_id=>request.sender.id}}
-            = person_image_link(request.sender)
-    .requests
-      %p= "#{t('.drag_to_add')} =>"
-
-
-%ul#aspect_list
-  - for aspect in @all_aspects
-    %li.aspect{:data=>{:guid=>aspect.id}}
-
-      .aspect_name
-        %span.edit_name_field
-          %h3{:contenteditable=>true}
-            = aspect.name
-          %span.tip click to edit
-
-        %ul.tools
-          %li!= remove_link(aspect)
-
-      %ul.dropzone{:data=>{:aspect_id=>aspect.id}}
-        -for contact in aspect.contacts
-          %li.person{:data=>{:guid=>contact.person.id, :aspect_id=>aspect.id}}
-            .delete
-              .x
-                X
-              .circle
-            = person_image_link(contact.person)
-%h4
-  = t('.aspect_name')
-  = form_for Aspect.new do |aspect|
-    = aspect.text_field :name, :id => "step-3-aspect-name", :style => "display:inline;"
-    %p.checkbox_select
-      = aspect.label :contacts_visible, t('aspects.edit.make_aspect_list_visible')
-      = aspect.check_box :contacts_visible, :default => true
-    %br
-    = aspect.submit t('.add')
-%br
-%br
 
 .submit_block
   = link_to "#{t('users.getting_started.save_and_continue')} →", getting_started_path(:step => 4), :class => "button"
diff --git a/features/accepts_invitation.feature b/features/accepts_invitation.feature
index 8810eea280..1df103a533 100644
--- a/features/accepts_invitation.feature
+++ b/features/accepts_invitation.feature
@@ -11,6 +11,7 @@ Feature: invitation acceptance
       Then I should be on the getting started page
       And I should see "Welcome to Diaspora!"      
       And I should see "ohai"
+     When I follow "Save and continue"
       And I fill in "profile_first_name" with "O"
       And I fill in "profile_last_name" with "Hai"
       And I fill in "profile_gender" with "guess!"
@@ -30,15 +31,22 @@ Feature: invitation acceptance
       Then I should be on the getting started page
       And I should see "Welcome to Diaspora!"      
       And I should see "ohai"
+     When I follow "Save and continue"
       And I fill in "profile_first_name" with "O"
       And I fill in "profile_last_name" with "Hai"
       And I fill in "profile_gender" with "guess!"
       And I press "Save and continue"
       Then I should see "Profile updated"
+      
       And I should see "Your aspects"
       And I should see "Here are the people who are waiting for you:"
-      And I should see 1 contact request
-      When I drag the contact request to the "Family" aspect
+
+      And I press the first ".share_with.button"
+      And I press the first ".add.button" within "#facebox #aspects_list ul > li:first-child"
       And I wait for the ajax to finish
-      Then I should see 1 contact in "Family"
+      
+     When I go to the home page
+     Then I go to the aspects manage page
+     Then I should see 1 contact in "Family"
+
 
diff --git a/features/connects_users.feature b/features/connects_users.feature
index 6097aed194..0d591c8d6c 100644
--- a/features/connects_users.feature
+++ b/features/connects_users.feature
@@ -1,11 +1,9 @@
+@javascript
 Feature: sending and receiving requests
 
   Background: 
     Given a user with email "bob@bob.bob"
     And a user with email "alice@alice.alice"
-    
-  @javascript
-  Scenario: initiating and accepting a contact request
     When I sign in as "bob@bob.bob"
     And I am on "alice@alice.alice"'s page
     And I press the first ".share_with.button" within "#author_info"
@@ -13,7 +11,8 @@ Feature: sending and receiving requests
     And I wait for the ajax to finish
     Then I should see a ".added.button" within "#facebox #aspects_list ul > li:first-child"
     Then I go to the destroy user session page
-
+    
+  Scenario: accepting a contact request
     When I sign in as "alice@alice.alice"
     And I am on the aspects manage page
     Then I should see 1 contact request
@@ -30,3 +29,21 @@ Feature: sending and receiving requests
     And I am on the aspects manage page
     Then I should see 1 contact in "Besties"
 
+  
+  Scenario: accepting a contact request into a new aspect
+    When I sign in as "alice@alice.alice"
+    And I am on "bob@bob.bob"'s page
+    And I press the first ".share_with.button" within "#author_info"
+    And I fill in "Name" with "Super People" in the modal window
+    And I press "aspect_submit" in the modal window
+    And I wait for the ajax to finish
+    And I press the first ".add.button" within "#facebox #aspects_list ul > li:last-child"
+
+   When I go to the home page
+   Then I go to the aspects manage page
+   Then I should see 1 contact in "Super People"
+   Then I go to the destroy user session page
+
+   When I sign in as "bob@bob.bob"
+   And I am on the aspects manage page
+   Then I should see 1 contact in "Besties"
diff --git a/public/images/icons/monotone_add_plus.png b/public/images/icons/monotone_add_plus.png
new file mode 100644
index 0000000000000000000000000000000000000000..f03378c1eecd97ecee3c05b7caac10f5e601b7dd
GIT binary patch
literal 228
zcmeAS@N?(olHy`uVBq!ia0vp^A|TAd3?%E9GuQzs#^NA%Cx&(BWL^R}iUB?$u8qyj
zEbQ#guC50T9$dI+(SrvMjLpnM#KkXMxG-_jr2qf_H@LFafOM7w`2{mLJiCzw;v{*y
zyD)UH%6b4foCO|{#S9GG!XV7ZFl&wkP>{XE)7O>#HWLezFoW_F@phn)zNd?02*>s0
z1O+w&Y3TzqdYYID)R@(R0|Ep(6nz*suviIuGEQ*2)Rw^YC{>7;!QX*dI^(14DWFyc
MPgg&ebxsLQ0D^Zs+W-In

literal 0
HcmV?d00001

diff --git a/public/javascripts/contact-list.js b/public/javascripts/contact-list.js
index b01c821d45..be016c680a 100644
--- a/public/javascripts/contact-list.js
+++ b/public/javascripts/contact-list.js
@@ -74,5 +74,10 @@ $(document).ready(function() {
     $(this).children("img").attr("src","/images/icons/monotone_check_yes.png");
   });
 
+  $('.new_aspect').live('ajax:success', function(data, json, xhr){
+      var json = JSON.parse(json);
+      $('#aspects_list ul').append(json.html);
+      });
+
   List.initialize();
 });
-- 
GitLab