Module: CrmTagsHelper

Defined in:
app/helpers/crm_tags_helper.rb

Overview

Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.


Instance Method Summary collapse

Instance Method Details

#tags_for_index(model) ⇒ Object

Generate tag links for use on asset index pages.




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

def tags_for_index(model)
  model.tag_list.inject([]) do |arr, tag|
    query = controller.send(:current_query) || ""
    hashtag = "##{tag}"
    if query.empty?
      query = hashtag
    elsif !query.include?(hashtag)
      query += " #{hashtag}"
    end
    arr << link_to_function(tag, "crm.search_tagged('#{query}', '#{model.class.to_s.tableize}')", :title => tag)
  end.join(" ").html_safe
end

#tags_for_show(model) ⇒ Object

Generate tag links for the asset landing page (shown on a sidebar).




37
38
39
40
41
# File 'app/helpers/crm_tags_helper.rb', line 37

def tags_for_show(model)
  model.tag_list.inject([]) do |arr, tag|
    arr << link_to(tag, url_for(:action => "tagged", :id => tag), :title => tag)
  end.join(" ").html_safe
end

#unsaved_param_tags(asset) ⇒ Object

Return asset tags to be built manually if the asset failed validation.



44
45
46
47
48
# File 'app/helpers/crm_tags_helper.rb', line 44

def unsaved_param_tags(asset)
  params[asset][:tag_list].join.split(",").map {|x|
    Tag.find_by_name(x.strip)
  }.compact.uniq
end