Skip to content

Commit

Permalink
Opportunity campaign selector is now on ajax.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyken committed Jan 23, 2014
1 parent 6a8794c commit 86fc51e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/helpers/accounts_helper.rb
Expand Up @@ -22,9 +22,10 @@ def account_summary(account)
].join(', ')
end

# Generates a select list with the first 25 accounts
# and prepends the currently selected account, if any.
#----------------------------------------------------------------------------
def account_select(options = {})
# Generates a select list with the first 25 accounts,
# and prepends the currently selected account, if available
options[:selected] = (@account && @account.id) || 0
accounts = ([@account] + Account.my.order(:name).limit(25)).compact.uniq
collection_select :account, :id, accounts, :id, :name, options,
Expand Down
1 change: 1 addition & 0 deletions app/helpers/campaigns_helper.rb
Expand Up @@ -32,4 +32,5 @@ def campaign_summary(campaign)
metrics = render :file => "campaigns/_metrics.html.haml", :locals => { :campaign => campaign }
"#{t(campaign.status)}, " << [ status, metrics ].map { |str| strip_tags(str) }.join(' ').gsub("\n", '')
end

end
14 changes: 14 additions & 0 deletions app/helpers/opportunities_helper.rb
Expand Up @@ -30,4 +30,18 @@ def opportunity_summary(opportunity)
end
summary.compact.join(', ')
end

# Generates a select list with the first 25 campaigns
# and prepends the currently selected campaign, if any.
#----------------------------------------------------------------------------
def opportunity_campaign_select(options = {})
options[:selected] ||= (@campaign && @campaign.id) || 0
campaigns = ([@campaign] + Campaign.my.order(:name).limit(25)).compact.uniq
collection_select :opportunity, :campaign_id, campaigns, :id, :name, options,
{:"data-placeholder" => t(:select_a_campaign),
:"data-url" => auto_complete_campaigns_path(format: 'json'),
:style => "width:330px; display:none;",
:class => 'ajax_chosen' }
end

end
2 changes: 1 addition & 1 deletion app/views/opportunities/_top_section.html.haml
Expand Up @@ -46,7 +46,7 @@
%tr
%td
.label #{t :campaign}:
= f.collection_select "campaign_id", Campaign.all, :id, :name, { :selected => (@campaign.try(:id) || @opportunity.campaign_id), :include_blank => true }
= opportunity_campaign_select( selected: (@campaign.try(:id) || @opportunity.campaign_id), include_blank: true )

- if Setting.background_info && Setting.background_info.include?(:opportunity)
%tr
Expand Down
1 change: 1 addition & 0 deletions config/locales/en-US_fat_free_crm.yml
Expand Up @@ -383,6 +383,7 @@ en-US:
was_supposed_to_finish: was supposed to finish on %{value}
was_supposed_to_start: was supposed to start %{time_ago} ago on %{start_date}
was_supposed_to_start_in: was supposed to start in %{starts_in} on %{start_date}
select_a_campaign: Select a campaign

# Views -> Contacts.
#----------------------------------------------------------------------------
Expand Down

0 comments on commit 86fc51e

Please sign in to comment.