From e588d7ab6af5755cd91f9702a1b0513e5b9b7fca Mon Sep 17 00:00:00 2001 From: danielvincent Date: Mon, 20 Sep 2010 17:26:20 -0700 Subject: [PATCH] DG IZ moving friends is now ajaxy --- app/controllers/aspects_controller.rb | 6 ++-- app/views/aspects/manage.html.haml | 4 --- app/views/shared/_aspect_nav.haml | 2 +- config/routes.rb | 5 +-- lib/diaspora/user/querying.rb | 3 +- public/javascripts/aspect-edit.js | 51 ++++++++------------------- 6 files changed, 22 insertions(+), 49 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 520485d33..779ce0f6f 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -79,10 +79,10 @@ class AspectsController < ApplicationController end if aspect = current_user.aspect_by_id(params[:to][:to]) flash[:notice] = "You are now showing your friend a different aspect of yourself." - respond_with aspect + render :nothing => true else - flash[:notice] = "You are now showing your friend a different aspect of yourself." - respond_with current_user.visible_person_by_id(params[:friend_id]) + flash[:error] = "Invalid aspect id!" + render aspects_manage_path end end diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index 656f0cb96..3903039ea 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -63,8 +63,4 @@ %div{:id => "add_request_pane_#{aspect.id}"} = render "requests/new_request", :aspect => aspect -%p - %br - = link_to 'Update Aspects', '#', :class => 'button', :id => "move_friends_link" - #content_bottom diff --git a/app/views/shared/_aspect_nav.haml b/app/views/shared/_aspect_nav.haml index ed3fe6f8f..dbca3bbef 100644 --- a/app/views/shared/_aspect_nav.haml +++ b/app/views/shared/_aspect_nav.haml @@ -6,7 +6,7 @@ #aspect_nav %ul - for aspect in @aspects - %li{:id => aspect.id, :class => ("selected" if current_aspect?(aspect))} + %li{:class => ("selected" if current_aspect?(aspect))} = link_for_aspect aspect %ul{ :style => "position:absolute;right:0;bottom:0.01em;"} diff --git a/config/routes.rb b/config/routes.rb index 188c4b137..ae757499c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,10 +13,11 @@ Diaspora::Application.routes.draw do resources :photos, :except => [:index] resources :albums - match 'aspects/manage', :to => 'aspects#manage' - resources :aspects, :except => [:edit] match 'aspects/move_friends', :to => 'aspects#move_friends', :as => 'move_friends' match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' + match 'aspects/manage', :to => 'aspects#manage' + resources :aspects, :except => [:edit] + match 'warzombie', :to => "dev_utilities#warzombie" match 'zombiefriends', :to => "dev_utilities#zombiefriends" diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 00ae27735..1079949b0 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -31,8 +31,7 @@ module Diaspora end def aspect_by_id( id ) - id = id.to_id - aspects.detect{|x| x.id == id } + self.aspects.find( id ) end def album_by_id( id ) diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index e07877cb7..39eee791a 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -20,28 +20,6 @@ function decrementRequestsCounter() { } $(function() { - - - $('#move_friends_link').live( 'click', function(){ - $.post( - '/aspects/move_friends', - { 'moves' : $('#aspect_list').data() }, - function() { - $('#aspect_title').html("Groups edited successfully!"); - } - ); - - // should the following logic be moved into the $.post() callback? - $("#aspect_list").removeData(); - - $(".person") - .css('background-color','none') - .attr('from_aspect_id', function() { - return $(this).parent().attr('id') - }); - - }); - // Multiple classes here won't work $("ul .person").draggable({ revert: true @@ -65,24 +43,23 @@ $(function() { } }); - } else { - var $aspect_list = $('#aspect_list'), - move = {}; - - // This is poor implementation - move[ 'friend_id' ] = ui.draggable[0].id; // ui.draggable.attr('id') - move[ 'to' ] = $(this)[0].id;// $(this).attr('id'); - move[ 'from' ] = ui.draggable[0].getAttribute('from_aspect_id'); // ui.draggable.attr('from_aspect_id') - - // if created custom attr's - should be using `data-foo` - - - if (move['to'] == move['from']){ - $aspect_list.data( ui.draggable[0].id, []); + }; + var dropzone = $(this)[0]; + + if ($(this)[0].id == ui.draggable[0].getAttribute('from_aspect_id')){ ui.draggable.css('background-color','#eee'); } else { - $aspect_list.data( ui.draggable[0].id, move); ui.draggable.css('background-color','orange'); + $.ajax({ + url: "/aspects/move_friend/", + data: {"friend_id" : ui.draggable[0].id, + "from" : ui.draggable[0].getAttribute('from_aspect_id'), + "to" : { "to" : dropzone.id }}, + success: function(data){ + ui.draggable.attr('from_aspect_id', dropzone.id); + ui.draggable.css('background','none'); + }}); + } } $(this).closest("ul").append(ui.draggable);