Module: E9Crm::ContactsHelper

Defined in:
app/helpers/e9_crm/contacts_helper.rb

Instance Method Summary collapse

Instance Method Details

#company_select_optionsObject



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

def company_select_options
  options = Company.select("companies.name, companies.id").ordered.all.map {|c| [c.name, c.id] }
  options.unshift(['Any Company', nil])
  options_for_select(options, params[:company])
end

#contact_email_template_select_tagObject



65
66
67
68
# File 'app/helpers/e9_crm/contacts_helper.rb', line 65

def contact_email_template_select_tag
  options = UserEmail.bulk_sendable.order('name').map {|e| [e.name, e.id] }
  select_tag 'email_id', options_for_select(options) if options.present?
end

#contact_simple_format(text) ⇒ Object



49
50
51
52
53
54
55
# File 'app/helpers/e9_crm/contacts_helper.rb', line 49

def contact_simple_format(text)
  auto_link(
    simple_format(text), 
    :html => { :rel => 'external nofollow' }, 
    :link => :urls
  )
end

#contact_tag_list(tags) ⇒ Object



61
62
63
# File 'app/helpers/e9_crm/contacts_helper.rb', line 61

def contact_tag_list(tags)
  tags.map {|tag| link_to_contact_search(:tagged, [tag], tag) }.join(', ').html_safe
end

#contact_tagsObject



3
4
5
6
7
8
9
10
11
# File 'app/helpers/e9_crm/contacts_helper.rb', line 3

def contact_tags
  @_contact_tags ||= begin 
    relation = Tagging.joins(:tag).select('distinct tags.name')
                      .where(:context => E9Tags.escape_context('users*'))
                      .order('tags.name ASC')

    Tagging.connection.send(:select_values, relation.to_sql, 'Contact Tags Select')
  end
end

#contact_user_subscribed_to_newsletter?(user) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
# File 'app/helpers/e9_crm/contacts_helper.rb', line 70

def contact_user_subscribed_to_newsletter?(user)
  @_newsletter ||= MailingList.newsletter
  @_newsletter && user.subscription_ids.include?(@_newsletter.id)
end


45
46
47
# File 'app/helpers/e9_crm/contacts_helper.rb', line 45

def google_maps_link(query, opts = {})
  link_to_google query, opts.merge(:text => :map, :exact => false, :base_url => "http://maps.google.com/maps?q=%s")
end


41
42
43
# File 'app/helpers/e9_crm/contacts_helper.rb', line 41

def google_news_link(query, opts = {})
  link_to_google query, opts.merge(:text => :news, :base_url => "http://news.google.com/news/search?q=%s")
end


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

def google_search_link(query, opts = {})
  link_to_google query, opts
end


57
58
59
# File 'app/helpers/e9_crm/contacts_helper.rb', line 57

def link_to_contact_search(attribute, query, text = nil)
  link_to(text || query, contacts_path(attribute => query), :class => "contact-search contact-#{attribute.to_s.dasherize}-search")
end


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

def link_to_google(query, opts = {})
  return unless query.present?

  opts.symbolize_keys!
  opts.reverse_merge!({
    :base_url => 'http://google.com/search?q=%s', 
    :exact => true,
    :text => :search
  })

  opts[:text] = I18n.t(opts[:text]) if opts[:text].is_a?(Symbol)

  query = query.to_s
  query = "\"#{query}\"" if query =~ /\s/ && opts[:exact]
  query = CGI.escape(query)
  link_to opts[:text], opts[:base_url] % query, :rel => 'nofollow external'
end

#records_table_field_map_for_contactObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/helpers/e9_crm/contacts_helper.rb', line 75

def records_table_field_map_for_contact
  {
    :fields => { 
      :avatar => proc {|r| link_to("<img src=\"#{r.avatar_url}\" alt=\"Avatar for #{r.name}\" />".html_safe, contact_path(r)) },
      :details => proc {|r| render('details', :record => r) }
    },

    :links => proc {|r| [
      link_to_show_resource(r), 
      link_to_edit_resource(r), 
      link_to_destroy_resource(r)
    ]}
  }
end