remove friend from aspect box, with js call to remove the person from the aspect
This commit is contained in:
parent
ae7891194e
commit
6fa82490c9
7 changed files with 51 additions and 4 deletions
|
|
@ -96,12 +96,21 @@ class AspectsController < ApplicationController
|
||||||
if current_user.add_person_to_aspect( params[:friend_id], params[:aspect_id])
|
if current_user.add_person_to_aspect( params[:friend_id], params[:aspect_id])
|
||||||
flash[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
flash[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
||||||
else
|
else
|
||||||
flash[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
flash[:error] = I18n.t 'aspects.add_to_aspect.failure'
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to aspects_path(params[:aspect_id])
|
redirect_to aspects_path(params[:aspect_id])
|
||||||
end
|
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
|
private
|
||||||
def clean_hash(params)
|
def clean_hash(params)
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ class User
|
||||||
|
|
||||||
def delete_person_from_aspect(person_id, aspect_id, opts = {})
|
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)
|
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)
|
opts[:posts] ||= aspect.posts.all(:person_id => person_id)
|
||||||
aspect.posts -= opts[:posts]
|
aspect.posts -= opts[:posts]
|
||||||
aspect.save
|
aspect.save
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,13 @@
|
||||||
= person_image_tag(request.person)
|
= person_image_tag(request.person)
|
||||||
.name
|
.name
|
||||||
= request.person.real_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
|
.remove
|
||||||
%ul.dropzone
|
%ul.dropzone
|
||||||
%li.grey Drag to ignore/remove
|
%li.grey Drag to ignore/remove
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ Diaspora::Application.routes.draw do
|
||||||
|
|
||||||
match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend'
|
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/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/manage', :to => 'aspects#manage'
|
||||||
match 'aspects/public', :to => 'aspects#public'
|
match 'aspects/public', :to => 'aspects#public'
|
||||||
resources :aspects, :except => [:edit]
|
resources :aspects, :except => [:edit]
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
$(".aspect h3").live( 'focus', function() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -871,7 +871,8 @@ h1.big_text
|
||||||
|
|
||||||
.aspect,
|
.aspect,
|
||||||
.requests,
|
.requests,
|
||||||
.remove
|
.remove,
|
||||||
|
.aspect_remove
|
||||||
:list
|
:list
|
||||||
:style none
|
:style none
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,5 +80,15 @@ describe AspectsController do
|
||||||
@aspect1.reload
|
@aspect1.reload
|
||||||
@aspect1.people.include?(@user2.person).should be true
|
@aspect1.people.include?(@user2.person).should be true
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue