remove friend from aspect box, with js call to remove the person from the aspect

This commit is contained in:
ilya 2010-10-20 17:34:52 -07:00
parent ae7891194e
commit 6fa82490c9
7 changed files with 51 additions and 4 deletions

View file

@ -96,12 +96,21 @@ class AspectsController < ApplicationController
if current_user.add_person_to_aspect( params[:friend_id], params[:aspect_id])
flash[:notice] = I18n.t 'aspects.add_to_aspect.success'
else
flash[:notice] = I18n.t 'aspects.add_to_aspect.success'
flash[:error] = I18n.t 'aspects.add_to_aspect.failure'
end
redirect_to aspects_path(params[:aspect_id])
end
def remove_from_aspect
if current_user.delete_person_from_aspect( params[:friend_id], params[:aspect_id])
flash[:notice] = I18n.t 'aspects.remove_from_aspect.success'
else
flash[:error] = I18n.t 'aspects.remove_from_aspect.failure'
end
redirect_to aspects_manage_path
end
private
def clean_hash(params)
return {

View file

@ -130,7 +130,7 @@ class User
def delete_person_from_aspect(person_id, aspect_id, opts = {})
raise "Can not delete a person from an aspect you do not own" unless aspect = self.aspects.find_by_id(aspect_id)
aspect.person_ids.delete(person_id)
aspect.person_ids.delete(person_id.to_id)
opts[:posts] ||= aspect.posts.all(:person_id => person_id)
aspect.posts -= opts[:posts]
aspect.save

View file

@ -25,8 +25,13 @@
= person_image_tag(request.person)
.name
= request.person.real_name
%h3=t('.ignore_remove')
%h3 Remove from Aspect
.aspect_remove
%ul.dropzone
%li.grey Drag to remove person from aspect
%h3=t('.ignore_remove')
.remove
%ul.dropzone
%li.grey Drag to ignore/remove

View file

@ -22,6 +22,7 @@ Diaspora::Application.routes.draw do
match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend'
match 'aspects/add_to_aspect',:to => 'aspects#add_to_aspect', :as => 'add_to_aspect'
match 'aspects/remove_from_aspect',:to => 'aspects#remove_from_aspect', :as => 'remove_from_aspect'
match 'aspects/manage', :to => 'aspects#manage'
match 'aspects/public', :to => 'aspects#public'
resources :aspects, :except => [:edit]

View file

@ -93,6 +93,27 @@ $(function() {
}
});
$(".aspect_remove ul").droppable({
hoverClass: 'active',
drop: function(event, ui) {
if (!$(ui.draggable[0]).hasClass('requested_person')){
var aspect = ui.draggable[0].getAttribute('from_aspect_id')
var person_id = ui.draggable[0].id
$.ajax({
type: "POST",
url: "/aspects/remove_from_aspect",
data:{
'friend_id' : person_id,
'aspect_id' : aspect
}
});
}
$(ui.draggable[0]).fadeOut('slow'); // ui.draggable.fadeOut('slow')
}
});
$(".aspect h3").live( 'focus', function() {

View file

@ -871,7 +871,8 @@ h1.big_text
.aspect,
.requests,
.remove
.remove,
.aspect_remove
:list
:style none

View file

@ -81,4 +81,14 @@ describe AspectsController do
@aspect1.people.include?(@user2.person).should be true
end
end
describe "#remove_from_aspect" do
it 'adds the users to the aspect' do
@aspect.reload
@aspect.people.include?(@user2.person).should be true
post 'remove_from_aspect', {:friend_id => @user2.person.id, :aspect_id => @aspect1.id }
@aspect1.reload
@aspect1.people.include?(@user2.person).should be false
end
end
end