Permalink
Browse files

Delete suggestions and pending requests. Fixes #12

  • Loading branch information...
1 parent 38b5205 commit 573a13929f1d4dc5e88dbe35d4b0c0a315ddcff9 @atd atd committed Jul 11, 2011
View
11 app/controllers/contacts_controller.rb
@@ -36,8 +36,13 @@ def update
end
end
- def suggestion
- @contact = current_subject.suggestion
- render :layout => false
+ def destroy
+ @contact = current_subject.sent_contacts.find params[:id]
+
+ @contact.relation_ids = [current_subject.relation_public.id]
+
+ respond_to do |format|
+ format.js
+ end
end
end
View
4 app/models/actor.rb
@@ -241,7 +241,7 @@ def suggestion(options = {})
# Candidates are all the instance of "type" minus all the subjects
# that are receiving any tie from this actor
candidates = candidates_classes.inject([]) do |cs, klass|
- cs += klass.all - contact_subjects(:type => klass.to_s.underscore, :direction => :sent)
+ cs += klass.all - contact_subjects(:type => klass.to_s.underscore, :direction => :sent, :relations => relations.to_a)
cs -= Array(subject) if subject.is_a?(klass)
cs
end
@@ -250,7 +250,7 @@ def suggestion(options = {})
return nil unless candidate.present?
- Contact.new :sender => self, :receiver => candidate.actor
+ contact_to!(candidate)
end
# Set of ties sent by this actor received by subject
View
6 app/views/contacts/_contact.html.erb
@@ -1,4 +1,4 @@
-<div id="contact_<%=dom_id(contact.receiver_subject)%>" class="row contact">
+<%= div_for contact, :class => 'row' do %>
<div class="logo">
<%= link_to(image_tag(contact.receiver.logo.url(:contact)),
contact.receiver_subject) %>
@@ -14,7 +14,7 @@
<%= contact_to(contact.receiver) %>
</div>
</div>
- <div class="close"><%=link_to('X','#')%></div>
+ <div class="close"><%= link_to 'X', contact, :method => :delete, :remote => true %></div>
<div class="space_center">
</div>
-</div>
+<% end %>
View
14 app/views/contacts/_suggestions.html.erb
@@ -1,16 +1,4 @@
<% if current_subject.suggestion.present? %>
- <% content_for :javascript do %>
-
- $(".suggestions .close").livequery("click",function(){
- temp = $(this);
- $.get("<%=suggestion_contacts_path%>", function(data) {
- temp.parents(".contact").replaceWith(data);
- });
-
- });
-
- <% end %>
-
<div class="block">
<div class="header">
<%= image_tag('btn/notifications.png', :class => "header_icon") %>
@@ -21,7 +9,7 @@
<div class="content">
<div class="suggestions">
<% if (sgs = current_subject.suggestions(2)).present? %>
- <%= render :partial => 'contacts/contact', :collection => sgs %>
+ <%= render sgs %>
<%end%>
</div>
</div>
View
6 app/views/contacts/destroy.js.erb
@@ -0,0 +1,6 @@
+<%
+ new_contact = @contact.pending? ? current_subject.pending_contacts.last : current_subject.suggestion
+ render_string = new_contact.present? ? render(new_contact) : ""
+%>
+
+$('#<%= dom_id(@contact) %>').replaceWith("<%= escape_javascript render_string %>");
View
6 config/routes.rb
@@ -27,11 +27,7 @@
end
end
- resources :contacts do
- collection do
- get 'suggestion'
- end
- end
+ resources :contacts
resources :spheres
namespace "relation" do

0 comments on commit 573a139

Please sign in to comment.