Skip to content

Instantly share code, notes, and snippets.

@marcuscaum
Created September 18, 2015 03:14
Show Gist options
  • Save marcuscaum/3503148679d85e4ab25c to your computer and use it in GitHub Desktop.
Save marcuscaum/3503148679d85e4ab25c to your computer and use it in GitHub Desktop.
class LeadDecorator < Draper::Decorator
include Draper::LazyHelpers
include Lead::SearchHelper
delegate_all
def personal_phone
lead_field model.lead_info.personal_phone, label: :personal_phone
end
def mobile_phone
lead_field model.lead_info.mobile_phone, label: :mobile_phone
end
def source
lead_field model.source, label: :origin
end
def uf
lead_field model.uf, label: :state
end
def city
lead_field model.city, label: :city
end
def twitter
lead_link_field(model.lead_info.twitter,
model.lead_info.twitter_url,
label: :twitter)
end
def facebook
lead_link_field(model.lead_info.facebook,
model.lead_info.facebook_url,
label: :facebook)
end
def linkedin
if model.name.present? && model.lead_info.linkedin?
lead_link_field(model.lead_info.linkedin,
model.lead_info.linkedin_url,
label: :linkedin)
end
end
def full_website
lead_link_field(model.lead_info.full_website,
model.lead_info.full_website,
label: :website)
end
def linkedin_search
if model.name.present? && model.lead_info.linkedin?
lead_link_field('',
lead_linkedin_search_url(lead),
label: :linkedin_search,
link_class: 'evergage-lead-reference-linkedin',
icon_class: 'xicon-linkedin2',
info_tag: false)
end
end
def google_search
lead_link_field('',
lead_google_search_url(lead),
label: :google_search,
link_class: 'evergage-lead-reference-google',
icon_class: 'xicon-google',
info_tag: false)
end
private
def lead_field(info, label: '', info_tag: '')
if info.present?
content_tag :li, class: 'list-group-item' do
concat content_tag(:small, I18n.t("lead.form.#{label}")) unless label.blank?
if info_tag != false
concat content_tag(:p, info)
else
concat info
end
end
end
end
def lead_link_field(info, url, label: '', info_tag:'', link_class: '', icon_class: '')
if !icon_class.blank?
lead_field(link_with_icon(url,
label: label,
link_class: link_class,
icon_class: icon_class),info_tag: info_tag) if url.present?
else
lead_field(link_to(info,
url,
target: :_blank,
class: link_class), label: label) if info.present?
end
end
def link_with_icon(url, label: '', link_class: '', icon_class: '')
link_to url, class: link_class, target: :_blank do
content_tag(:i, '', class: icon_class) + I18n.t("lead.lead_body.lead_details.#{label}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment