Module: SourcesHelper

Defined in:
app/helpers/sources_helper.rb

Overview

== Schema Information

Table name: sources

id :integer not null, primary key
name :string(255)
description :string(255)
parent_id :integer
hidden :boolean
featured :boolean default(FALSE)
referral_code :string(20)
full_name :string(200)
created_at :datetime
creator_id :integer
updated_at :datetime
updater_id :integer
campaign :string(255)
featured_until :datetime
analytics_source :string(255)
customers_count :integer

Instance Method Summary collapse

Instance Method Details

#grouped_source_options_for_select(sourceable = nil) ⇒ Object

Returns list of campaigns active for customer combined with presently selected
source if it is a campaign



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/sources_helper.rb', line 38

def grouped_source_options_for_select(sourceable = nil)
  customer = sourceable.try(:customer)
  source = sourceable.try(:source)
  opts = {}
  campaign_sources = []
  if customer
    campaign_sources = Source.campaign_sources_featured_for_customer(customer)
    opts['Customer Source'] = [[customer.source.full_name, customer.source_id]] if customer.source
  end
  campaign_sources << [sourceable.source.full_name, sourceable.source_id] if source&.campaigns&.any?
  opts['Customer Campaigns'] = campaign_sources.uniq if campaign_sources.present?
  opts['Other Sources'] = Source.visible_options_for_select - opts.values
  opts
end

#source_command_options(_source) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/sources_helper.rb', line 25

def source_command_options(_source)
  [].tap do |opts|
    if can?(:update, Source)
      opts << link_to(fa_icon('wrench', text: 'Edit'), edit_source_path(@source))
      opts << link_to("New Source", new_source_path(parent_id: @source.id))
      opts << link_to(fa_icon('trash', text: @source.ok_to_destroy? ? "Delete" : "Hide"), source_url(@source), method: :delete, data: { confirm: "Are you sure you want to delete/hide this source and its children?" })
    end
    opts << link_to("Generate QR Code", generate_qr_source_path(@source))
  end
end

#source_tab_options(source = @source) ⇒ Object



53
54
55
56
57
58
59
60
# File 'app/helpers/sources_helper.rb', line 53

def source_tab_options(source = @source)
  {
    details: { remote_href: tab_details_source_path(source) },
    children: { remote_href: tab_children_source_path(source) },
    attributions: { remote_href: tab_attributions_source_path(source) },
    related: { remote_href: tab_related_source_path(source) }
  }
end