diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index c87220ce25ee071fc9cb6ae2a86472a56a2a4587..a683b093673953fc2cfcf52083d6b3a0cc6cfa8a 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -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 { diff --git a/app/models/user.rb b/app/models/user.rb index 8858c971f6971b2a631939442746a5d5b730d03f..6f8219765ba098bb58fea302319b629c6411d176 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index 6cd67166d5506cced1d46262540018a3d6469e0f..824814f89a5f02c79def2568c84656b626dc9c47 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 166e1492d7881fd3b48733ee13ec1e843dfebf4c..7364f901617830cb6e755c7d436a70554c034a0c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 77d990793979d83b646aac4b4bc185020d85afaa..dc0d1cd39f796453e957cceb28c4bfed85761ace 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -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() { diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 5249cb129493ad252c0b11bb180d75572da1cb46..87f7c9893f09ea3b09c4276cb9fb03336dcb6600 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -871,7 +871,8 @@ h1.big_text .aspect, .requests, -.remove +.remove, +.aspect_remove :list :style none diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 2e50b667984f22150495a3236b90dc6d3fe92648..425d3de4b0e430fb50279de297ac59626075de56 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -80,5 +80,15 @@ describe AspectsController do @aspect1.reload @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