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



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

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 )
		if customer.source
			opts['Customer Source'] = [[ customer.source.full_name, customer.source_id ]]
		end
	end
	if source and source.campaigns.any?
		campaign_sources << [ sourceable.source.full_name, sourceable.source_id ]
	end
	if campaign_sources.present?
		opts['Customer Campaigns'] = campaign_sources.uniq
	end
	opts['Other Sources'] = Source.visible_options_for_select - opts.values
	opts
end

#source_command_options(source) ⇒ Object



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

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



58
59
60
61
62
63
64
65
66
# File 'app/helpers/sources_helper.rb', line 58

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