made aspect_dropdown ajax in (created route), in the process of removing aspect_membership js responses
This commit is contained in:
parent
675d9d7485
commit
1c79c2c6f0
14 changed files with 89 additions and 35 deletions
|
|
@ -6,6 +6,8 @@
|
||||||
class AspectMembershipsController < ApplicationController
|
class AspectMembershipsController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
|
respond_to :html, :json, :js
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
#note :id is garbage
|
#note :id is garbage
|
||||||
|
|
||||||
|
|
@ -17,14 +19,14 @@ class AspectMembershipsController < ApplicationController
|
||||||
|
|
||||||
if membership && membership.destroy
|
if membership && membership.destroy
|
||||||
@aspect = membership.aspect
|
@aspect = membership.aspect
|
||||||
|
|
||||||
flash.now[:notice] = I18n.t 'aspect_memberships.destroy.success'
|
flash.now[:notice] = I18n.t 'aspect_memberships.destroy.success'
|
||||||
|
|
||||||
respond_to do |format|
|
respond_with do |format|
|
||||||
format.js { }
|
format.all{ }
|
||||||
format.html{
|
format.json{ render :json => {
|
||||||
redirect_to :back
|
:person_id => @person_id,
|
||||||
}
|
:aspect_ids => @contact.aspects.map{|a| a.id}
|
||||||
|
} }
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
@ -44,12 +46,12 @@ class AspectMembershipsController < ApplicationController
|
||||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
||||||
|
|
||||||
if @contact = current_user.share_with(@person, @aspect)
|
if @contact = current_user.share_with(@person, @aspect)
|
||||||
|
|
||||||
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
||||||
|
respond_with AspectMembership.where(:contact_id => @contact.id, :aspect_id => @aspect.id).first
|
||||||
else
|
else
|
||||||
flash[:error] = I18n.t 'contacts.create.failure'
|
flash[:error] = I18n.t 'contacts.create.failure'
|
||||||
redirect_to :back
|
#TODO(dan) take this out once the .js template is removed
|
||||||
|
render :nothing => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,5 @@ class ContactsController < ApplicationController
|
||||||
@contacts = current_user.contacts.sharing.includes(:aspect_memberships)
|
@contacts = current_user.contacts.sharing.includes(:aspect_memberships)
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ class PeopleController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.all { respond_with @person, :locals => {:post_type => :all} }
|
format.all { respond_with @person, :locals => {:post_type => :all} }
|
||||||
format.json {
|
format.json {
|
||||||
render :json => @person.to_json(:aspect_ids => @aspects_with_person.to_json)
|
render :json => @person.to_json
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -120,6 +120,7 @@ class PeopleController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def retrieve_remote
|
def retrieve_remote
|
||||||
if params[:diaspora_handle]
|
if params[:diaspora_handle]
|
||||||
webfinger(params[:diaspora_handle], :single_aspect_form => true)
|
webfinger(params[:diaspora_handle], :single_aspect_form => true)
|
||||||
|
|
@ -136,7 +137,6 @@ class PeopleController < ApplicationController
|
||||||
@aspect = :profile
|
@aspect = :profile
|
||||||
@contacts_of_contact = @contact.contacts.paginate(:page => params[:page], :per_page => (params[:limit] || 15))
|
@contacts_of_contact = @contact.contacts.paginate(:page => params[:page], :per_page => (params[:limit] || 15))
|
||||||
@hashes = hashes_for_people @contacts_of_contact, @aspects
|
@hashes = hashes_for_people @contacts_of_contact, @aspects
|
||||||
@contact = current_user.contact_for(@person)
|
|
||||||
@aspects_with_person = @contact.aspects
|
@aspects_with_person = @contact.aspects
|
||||||
@aspect_ids = @aspects_with_person.map(&:id)
|
@aspect_ids = @aspects_with_person.map(&:id)
|
||||||
else
|
else
|
||||||
|
|
@ -144,8 +144,16 @@ class PeopleController < ApplicationController
|
||||||
redirect_to people_path
|
redirect_to people_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def aspect_membership_dropdown
|
||||||
|
@person = Person.find(params[:id])
|
||||||
|
@contact = current_user.contact_for(@person) || Contact.new
|
||||||
|
render :partial => 'aspect_memberships/aspect_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left'}
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def webfinger(account, opts = {})
|
def webfinger(account, opts = {})
|
||||||
Resque.enqueue(Job::SocketWebfinger, current_user.id, account, opts)
|
Resque.enqueue(Job::SocketWebfinger, current_user.id, account, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -68,16 +68,12 @@ module AspectGlobalHelper
|
||||||
def aspect_dropdown_list_item(aspect, contact, person)
|
def aspect_dropdown_list_item(aspect, contact, person)
|
||||||
checked = (contact.persisted? && contact.aspect_memberships.detect{ |am| am.aspect_id == aspect.id})
|
checked = (contact.persisted? && contact.aspect_memberships.detect{ |am| am.aspect_id == aspect.id})
|
||||||
klass = checked ? "selected" : ""
|
klass = checked ? "selected" : ""
|
||||||
hidden = !checked ? "hidden" : ""
|
|
||||||
|
|
||||||
str = <<LISTITEM
|
str = <<LISTITEM
|
||||||
<li data-aspect_id=#{aspect.id} class='#{klass}'>
|
<li data-aspect_id=#{aspect.id} class='#{klass}'>
|
||||||
<img src='/images/icons/check_yes_ok.png' width=18 height=18 class='check #{hidden}'/>
|
<img src='/images/icons/check_yes_ok.png' width=18 height=18 class='check'/>
|
||||||
<img src='/images/icons/check_yes_ok_white.png' width=18 height=18 class='checkWhite'/>
|
<img src='/images/icons/check_yes_ok_white.png' width=18 height=18 class='checkWhite'/>
|
||||||
#{aspect.name}
|
#{aspect.name}
|
||||||
<div class=\"hidden\">
|
|
||||||
#{aspect_membership_button(aspect, contact, person)}
|
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
LISTITEM
|
LISTITEM
|
||||||
str.html_safe
|
str.html_safe
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,12 @@ class AspectMembership < ActiveRecord::Base
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def as_json(opts={})
|
||||||
|
{
|
||||||
|
:id => self.id,
|
||||||
|
:person_id => self.person.id,
|
||||||
|
:contact_id => self.contact.id,
|
||||||
|
:aspect_ids => self.contact.aspects.map{|a| a.id}
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,6 @@ class Person < ActiveRecord::Base
|
||||||
:handle => self.diaspora_handle,
|
:handle => self.diaspora_handle,
|
||||||
:url => "/people/#{self.id}"
|
:url => "/people/#{self.id}"
|
||||||
}
|
}
|
||||||
json.merge(:aspect_ids => opts[:aspect_ids])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,3 @@ if($('#aspects_list').length == 1) {
|
||||||
};
|
};
|
||||||
|
|
||||||
element.fadeTo(200,1);
|
element.fadeTo(200,1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@
|
||||||
%img.avatar
|
%img.avatar
|
||||||
%h4
|
%h4
|
||||||
%a.person
|
%a.person
|
||||||
= render 'aspect_memberships/aspect_dropdown', :contact => Contact.new, :person => Person.new, :hang => 'left'
|
#hovercard_dropdown_container
|
||||||
|
|
||||||
.hovercard_footer
|
.hovercard_footer
|
||||||
.footer_container
|
.footer_container
|
||||||
Message
|
Message
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,8 @@ Diaspora::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "people/:id/aspect_membership_button" => "people#aspect_membership_dropdown", :as => "aspect_membership_button"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,9 @@ var ContactEdit = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
updateNumber: function(personId){
|
updateNumber: function(dropdown, personId, number){
|
||||||
var dropdown = $(".dropdown_list[data-person_id=" + personId.toString() +"]"),
|
var button = dropdown.parents(".dropdown").children('.button.toggle'),
|
||||||
number = dropdown.find(".selected").length,
|
replacement;
|
||||||
button = dropdown.parents(".dropdown").children('.button.toggle');
|
|
||||||
|
|
||||||
var replacement;
|
|
||||||
|
|
||||||
if (number == 0) {
|
if (number == 0) {
|
||||||
button.removeClass("in_aspects");
|
button.removeClass("in_aspects");
|
||||||
|
|
@ -36,7 +33,6 @@ var ContactEdit = {
|
||||||
|
|
||||||
toggleCheckbox:
|
toggleCheckbox:
|
||||||
function(check){
|
function(check){
|
||||||
check.toggleClass('hidden');
|
|
||||||
check.parent('li').toggleClass('selected');
|
check.parent('li').toggleClass('selected');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -44,10 +40,18 @@ var ContactEdit = {
|
||||||
var button = li.find('.button');
|
var button = li.find('.button');
|
||||||
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
|
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
|
||||||
|
|
||||||
var checkbox = li.find('img.check');
|
var checkbox = li.find('img.check'),
|
||||||
ContactEdit.toggleCheckbox(checkbox);
|
selected = li.hasClass("selected"),
|
||||||
|
routedId = selected ? "/42" : "";
|
||||||
|
|
||||||
$.fn.callRemote.apply(button);
|
$.post("/aspect_memberships" + routedId + ".json", {
|
||||||
|
"aspect_id": li.data("aspect_id"),
|
||||||
|
"person_id": li.parent().data("person_id"),
|
||||||
|
"_method": (selected) ? "DELETE" : "POST"
|
||||||
|
}, function(aspectMembership) {
|
||||||
|
ContactEdit.toggleCheckbox(checkbox);
|
||||||
|
ContactEdit.updateNumber(li.closest(".dropdown_list"), li.parent().data("person_id"), aspectMembership.aspect_ids.length);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,27 @@
|
||||||
|
|
||||||
self.hoverCard.tip.fadeIn('fast');
|
self.hoverCard.tip.fadeIn('fast');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$.get(self.target.attr('href')+'/aspect_membership_button',function(data){
|
||||||
|
self.hoverCard.tip.find('#hovercard_dropdown_container').html(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.populateDropdown = function(aspect_ids){
|
||||||
|
var dropdown = this.hoverCard.tip.find('.dropdown_list'),
|
||||||
|
listElements = dropdown.children('li'),
|
||||||
|
inAspects = false;
|
||||||
|
|
||||||
|
// check-off aspects
|
||||||
|
$.each(listElements, function(idx,el){
|
||||||
|
var element = $(el);
|
||||||
|
if( aspect_ids.indexOf(element.attr('data-aspect_id')) !== -1 ){
|
||||||
|
element.addClass('selected');
|
||||||
|
inAspects = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// make button green
|
||||||
};
|
};
|
||||||
|
|
||||||
this.clearTimeout = function(delayed) {
|
this.clearTimeout = function(delayed) {
|
||||||
|
|
@ -63,7 +84,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
if((typeof delayed === "boolean" && delayed) || (typeof delayed === "object" && delayed.type === "mouseleave")) {
|
if((typeof delayed === "boolean" && delayed) || (typeof delayed === "object" && delayed.type === "mouseleave")) {
|
||||||
self.hoverCardTimeout = setTimeout(callback, 300);
|
self.hoverCardTimeout = setTimeout(callback, 400);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callback();
|
callback();
|
||||||
|
|
|
||||||
|
|
@ -3071,8 +3071,8 @@ ul.left_nav
|
||||||
:display none
|
:display none
|
||||||
|
|
||||||
#hovercard
|
#hovercard
|
||||||
@include box-shadow(0,0,7px,#333)
|
|
||||||
@include border-radius(2px)
|
@include border-radius(2px)
|
||||||
|
@include dropdown-shadow
|
||||||
|
|
||||||
.avatar
|
.avatar
|
||||||
:position relative
|
:position relative
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,10 @@
|
||||||
|
|
||||||
&:hover
|
&:hover
|
||||||
:text-decoration none
|
:text-decoration none
|
||||||
|
|
||||||
|
&:not(.selected)
|
||||||
|
.check
|
||||||
|
:display none
|
||||||
|
|
||||||
&.hang_right
|
&.hang_right
|
||||||
.wrapper
|
.wrapper
|
||||||
|
|
@ -170,7 +173,7 @@
|
||||||
@include border-radius(3px, 3px, 0, 0)
|
@include border-radius(3px, 3px, 0, 0)
|
||||||
:border 1px solid #444
|
:border 1px solid #444
|
||||||
:bottom none
|
:bottom none
|
||||||
|
|
||||||
.selected
|
.selected
|
||||||
:font-weight bold
|
:font-weight bold
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ describe AspectMembershipsController do
|
||||||
}.should change{
|
}.should change{
|
||||||
alice.contact_for(bob.person).aspect_memberships.count
|
alice.contact_for(bob.person).aspect_memberships.count
|
||||||
}.by(1)
|
}.by(1)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a contact' do
|
it 'creates a contact' do
|
||||||
|
|
@ -62,8 +61,19 @@ describe AspectMembershipsController do
|
||||||
:aspect_id => @aspect0.id
|
:aspect_id => @aspect0.id
|
||||||
flash[:error].should_not be_empty
|
flash[:error].should_not be_empty
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
context 'json' do
|
||||||
|
it 'returns a list of aspect ids for the person' do
|
||||||
|
post :create,
|
||||||
|
:format => 'json',
|
||||||
|
:person_id => @person.id,
|
||||||
|
:aspect_id => @aspect0.id
|
||||||
|
|
||||||
|
contact = @controller.current_user.contact_for(@person)
|
||||||
|
response.body.should == contact.aspect_memberships.first.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#destroy" do
|
describe "#destroy" do
|
||||||
it 'removes contacts from an aspect' do
|
it 'removes contacts from an aspect' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue