Module: E9Crm::ContactsHelper

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

Instance Method Summary collapse

Instance Method Details

#company_select_optionsObject



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

def company_select_options
  options = Company.select('name', '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



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

def contact_email_template_select_tag
  options = EmailTemplate.order('name').map {|e| [e.name, e.id] }
  #select_tag 'etid', options_for_select( options.presence || [['n/a', nil]] )
  select_tag 'etid', options_for_select(options) if options.present?
end

#contact_newsletter_select_tagObject



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

def contact_newsletter_select_tag
  options = UserEmail.pending.order('name').map {|e| [e.name, e.id] }
  #select_tag 'eid', options_for_select( options.presence || [['n/a', nil]] )
  select_tag 'eid', options_for_select(options) if options.present?
end

#contact_simple_format(text) ⇒ Object



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

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

#contact_tag_list(tags) ⇒ Object



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

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
# 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*'))

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

#contact_user_subscribed_to_newsletter?(user) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
# File 'app/helpers/e9_crm/contacts_helper.rb', line 76

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


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

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


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

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


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

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


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

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


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

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/e9_crm/contacts_helper.rb', line 81

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