Module: ContactsHelper

Defined in:
app/helpers/contacts_helper.rb

Instance Method Summary collapse

Instance Method Details

#anonymous_contact_buttonObject



37
38
39
40
41
# File 'app/helpers/contacts_helper.rb', line 37

def anonymous_contact_button
  form_tag new_user_session_path do |f|
    submit_tag t('contact.new.button.zero')
  end
end

#contact_button(contact_or_actor) ⇒ Object

Add contact button



11
12
13
14
15
16
17
# File 'app/helpers/contacts_helper.rb', line 11

def contact_button(contact_or_actor)
  if user_signed_in?
    signed_in_contact_button contact_or_actor
  else
    anonymous_contact_button
  end
end

#contact_count(actor) ⇒ Object



2
3
4
5
6
7
8
# File 'app/helpers/contacts_helper.rb', line 2

def contact_count(actor)
  if user_signed_in?
    t 'contact.in_common', :count => current_subject.common_contacts_count(actor)
  else
    t 'contact.n', count: actor.sent_active_contact_count
  end
end

#contact_select_options(options) ⇒ Object



47
48
49
50
51
52
53
# File 'app/helpers/contacts_helper.rb', line 47

def contact_select_options options
  if !options.empty? && options.first.respond_to?(:last) && Array === options.first.last
    grouped_options_for_select(options)
  else
    options_for_select(options)
  end
end

#current_contact_section?(section) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/helpers/contacts_helper.rb', line 43

def current_contact_section? section
  params[:type] == section.to_s
end

#signed_in_contact_button(contact_or_actor) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/contacts_helper.rb', line 19

def signed_in_contact_button contact_or_actor
  c =
    if contact_or_actor.is_a?(Contact)
      contact_or_actor
    else
      current_actor.contact_to!(contact_or_actor)
    end

  if c.reflexive?
    t('subject.this_is_you')
  elsif can? :update, c
    render partial: "contacts/button",
           locals: { contact: c }
  else
    ""
  end
end