diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 8b1cd73af1be9381d3a9ea9c9bcb27956977edb0..3bd27c72b5d40b4088e497e85d90ad121bdbe4b7 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -49,15 +49,21 @@ class GroupsController < ApplicationController end end - def move_person - unless current_user.move_friend( :friend_id => params[:friend_id], :from => params[:from], :to => params[:to][:to]) - flash[:error] = "didn't work #{params.inspect}" - end - if group = Group.first(:id => params[:to][:to]) - redirect_to group - else - redirect_to Person.first(:id => params[:friend_id]) - end + def move_friends + pp params + + params[:moves].each{ |move| + move = move[1] + unless current_user.move_friend(move) + flash[:error] = "Group editing failed for friend #{Person.find_by_id( move[:friend_id] ).real_name}." + redirect_to Group.first, :action => "edit" + return + end + } + + flash[:notice] = "Groups edited successfully." + redirect_to Group.first, :action => "edit" + end end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index c4ea5c0449b07d7c3070533c2821aa34c9f98b48..861eb0817a7c9415bfea78c887ff2ebc3e48a4eb 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -16,7 +16,7 @@ class PeopleController < ApplicationController @profile = @person.profile @groups_with_person = current_user.groups_with_person(@person) - @all_groups = current_user.groups.collect{|x| [x.to_s, x.id]} + @groups_dropdown_array = current_user.groups.collect{|x| [x.to_s, x.id]} @posts = Post.where(:person_id => @person.id, :_id.in => current_user.visible_post_ids).paginate :page => params[:page], :order => 'created_at DESC' diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml index c8e3e4fc4dc98a6bd8cac2bb0b66995b90695753..b7a9da65dd75febb478358f3af4cb89387ec50fc 100644 --- a/app/views/groups/edit.html.haml +++ b/app/views/groups/edit.html.haml @@ -3,22 +3,24 @@ = javascript_include_tag 'group-edit.js' -%h1.big_text +%h1{:class => 'big_text', :id => 'group_title'} .back = link_to "⇧ #{@group.name}", @group = "Editing Groups" -%ul +%ul#group_list - for group in @groups - %li.group + %li{:class => 'group'} = group.name - %ul - stuff + %ul{:id => group.id} + dummy person for dropping onto -for person in group.people - %li.person - = image_tag (person.profile.image_url(:thumb_small),:size => "30x30") unless person.profile.image_url.nil? + %li{:class => 'person', :id => person.id, :from_group_id => group.id} + = image_tag(person.profile.image_url(:thumb_small),:size => "30x30") unless person.profile.image_url.nil? = person.real_name - +%p + %br + = link_to 'Update Groups', '#', :class => 'button', :id => "move_friends_link" #content_bottom .back diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index b0e56879922ba32aebefbbc2685f06f9fcde07ad..eab323e830a0d52deafac80e6ca81e9b5bca89de 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -17,8 +17,8 @@ %li %i= "friends since: #{how_long_ago(@person)}" %li - = form_tag move_person_path - = select :to, :to, @all_groups + = form_tag move_friends_path + = select :to, :to, @groups_dropdown_array, :selected_value => @groups_with_person.first.id = hidden_field_tag :from, :from, :value => @groups_with_person.first.id = hidden_field_tag :friend_id, :friend_id, :value => @person.id = submit_tag "save" diff --git a/config/routes.rb b/config/routes.rb index e3c5b352a114c2995de97313b339dd25b62c0d0d..663dc9785d709f9ee6c0de7b7bc88aba4201c23e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ Diaspora::Application.routes.draw do match 'login', :to => 'devise/sessions#new', :as => "new_user_session" match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" match 'get_to_the_choppa', :to => 'devise/registrations#new', :as => "new_user_registration" - match 'groups/move_person', :to => 'groups#move_person', :as => 'move_person' + match 'groups/move_friends', :to => 'groups#move_friends', :as => 'move_friends' #public routes # match 'webfinger', :to => 'publics#webfinger' diff --git a/public/javascripts/group-edit.js b/public/javascripts/group-edit.js index e92cadb75078f876d4629f7d1312a1d79b0070e4..94ca47cfd6aad946f41f13d2edd66d8ced9b1c99 100644 --- a/public/javascripts/group-edit.js +++ b/public/javascripts/group-edit.js @@ -1,3 +1,10 @@ +$('#move_friends_link').live( 'click', + function(){ + $.post('/groups/move_friends', + {'moves' : $('#group_list').data()}, + function(){ $('#group_title').html("Groups edited successfully!");}); + }); + $(function() { $("li .person").draggable({ revert: true @@ -7,8 +14,14 @@ $(function() { drop: function(event, ui) { $(this).closest("ul").append(ui.draggable) //$("<li class='person ui-draggable'></li>").text(ui.draggable.text()).appendTo(this).draggable(); + var move = {}; + move[ 'friend_id' ] = ui.draggable[0].id + move[ 'to' ] = $(this)[0].id; + move[ 'from' ] = ui.draggable[0].getAttribute('from_group_id'); + $('#group_list').data( ui.draggable[0].id, move); } }); + });