diaspora/app/helpers/aspects_helper.rb
Florian Staudacher 4cbae601e8 [WIP] aspect membership dropdown Backbone.js rework
* initial backbone port
* changed AspectMembershipsController#destroy to use aspect_membership_id
* included rudimentary jasmine specs
* more specs, updating the list elements after de-/selection
* update selected aspect count on button
* don't even try to render html in AspectMembershipsController
* more specs for button summary text
* adapt aspect management on contacts page and in the popup boxes
* adapt inline creation of aspects + memberships

TODO
* more tests
2013-02-17 13:40:10 +01:00

43 lines
1.4 KiB
Ruby

# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module AspectsHelper
def add_to_aspect_button(aspect_id, person_id)
link_to image_tag('icons/monotone_plus_add_round.png'),
{ :controller => 'aspect_memberships',
:action => 'create',
:format => :json,
:aspect_id => aspect_id,
:person_id => person_id
},
:method => 'post',
:class => 'add button',
'data-aspect_id' => aspect_id,
'data-person_id' => person_id
end
def remove_from_aspect_button(membership_id, aspect_id, person_id)
link_to image_tag('icons/monotone_check_yes.png'),
{ :controller => "aspect_memberships",
:action => 'destroy',
:id => membership_id
},
:method => 'delete',
:class => 'added button',
'data-membership_id' => membership_id,
'data-aspect_id' => aspect_id,
'data-person_id' => person_id
end
def aspect_membership_button(aspect, contact, person)
return if person && person.closed_account?
membership = contact.aspect_memberships.where(:aspect_id => aspect.id).first
if contact.nil? || membership.nil?
add_to_aspect_button(aspect.id, person.id)
else
remove_from_aspect_button(membership.id, aspect.id, person.id)
end
end
end