Module: TaxonomyHelper

Defined in:
app/helpers/taxonomy_helper.rb

Instance Method Summary collapse

Instance Method Details

#assign_all_hosts_taxonomy_path(taxonomy) ⇒ Object


95
96
97
# File 'app/helpers/taxonomy_helper.rb', line 95

def assign_all_hosts_taxonomy_path(taxonomy)
  is_location? ? assign_all_hosts_location_path(taxonomy) : assign_all_hosts_organization_path(taxonomy)
end

#assign_hosts_taxonomy_path(taxonomy) ⇒ Object


99
100
101
# File 'app/helpers/taxonomy_helper.rb', line 99

def assign_hosts_taxonomy_path(taxonomy)
  is_location? ? assign_hosts_location_path(taxonomy) : assign_hosts_organization_path(taxonomy)
end

#edit_taxonomy_path(taxonomy) ⇒ Object


67
68
69
# File 'app/helpers/taxonomy_helper.rb', line 67

def edit_taxonomy_path(taxonomy)
  is_location? ? edit_location_path(taxonomy) : edit_organization_path(taxonomy)
end

#hash_for_clone_taxonomy_path(taxonomy) ⇒ Object


75
76
77
# File 'app/helpers/taxonomy_helper.rb', line 75

def hash_for_clone_taxonomy_path(taxonomy)
  is_location? ? hash_for_clone_location_path(:id => taxonomy) : hash_for_clone_organization_path(:id => taxonomy)
end

#hash_for_edit_taxonomy_path(taxonomy) ⇒ Object


71
72
73
# File 'app/helpers/taxonomy_helper.rb', line 71

def hash_for_edit_taxonomy_path(taxonomy)
  is_location? ? hash_for_edit_location_path(:id => taxonomy) : hash_for_edit_organization_path(:id => taxonomy)
end

#hash_for_new_taxonomy_pathObject


83
84
85
# File 'app/helpers/taxonomy_helper.rb', line 83

def hash_for_new_taxonomy_path
  is_location? ? hash_for_new_location_path : hash_for_new_organization_path
end

#hash_for_taxonomy_path(taxonomy) ⇒ Object


79
80
81
# File 'app/helpers/taxonomy_helper.rb', line 79

def hash_for_taxonomy_path(taxonomy)
  is_location? ? hash_for_location_path(:id => taxonomy) : hash_for_organization_path(:id => taxonomy)
end

#import_mismatches_taxonomy_path(taxonomy) ⇒ Object


91
92
93
# File 'app/helpers/taxonomy_helper.rb', line 91

def import_mismatches_taxonomy_path taxonomy
  is_location? ? import_mismatches_location_path(taxonomy) : import_mismatches_organization_path(taxonomy)
end

#is_location?Boolean


63
64
65
# File 'app/helpers/taxonomy_helper.rb', line 63

def is_location?
  controller_name == "locations"
end

#location_dropdown(count) ⇒ Object


23
24
25
26
27
28
29
30
# File 'app/helpers/taxonomy_helper.rb', line 23

def location_dropdown count
    text = Location.current.nil? ? _("Any Location") : Location.current.to_label
    if count == 1 && !User.current.admin?
      link_to text, "#"
    else
      link_to(text, "#", :class => "dropdown-toggle", :'data-toggle'=>"dropdown")
    end
end

#location_selects(f, selected_ids, options = {}, options_html = {}) ⇒ Object


111
112
113
# File 'app/helpers/taxonomy_helper.rb', line 111

def location_selects(f, selected_ids, options = {}, options_html = {})
  taxonomy_selects(f, selected_ids, Location, 'Locations', options, options_html)
end

#mismatches_taxonomies_pathObject


87
88
89
# File 'app/helpers/taxonomy_helper.rb', line 87

def mismatches_taxonomies_path
  is_location? ? mismatches_locations_path : mismatches_organizations_path
end

#option_button(text, href, options) ⇒ Object


57
58
59
60
61
# File 'app/helpers/taxonomy_helper.rb', line 57

def option_button text, href, options
  field(nil, "", options) do
    link_to(text, href, options)
  end
end

#organization_dropdown(count) ⇒ Object


14
15
16
17
18
19
20
21
# File 'app/helpers/taxonomy_helper.rb', line 14

def organization_dropdown count
  text = Organization.current.nil? ? _("Any Organization") : Organization.current.to_label
  if count == 1 && !User.current.admin?
    link_to text, "#"
  else
    link_to(text, "#", :class => "dropdown-toggle", :'data-toggle'=>"dropdown")
  end
end

#organization_selects(f, selected_ids, options = {}, options_html = {}) ⇒ Object


107
108
109
# File 'app/helpers/taxonomy_helper.rb', line 107

def organization_selects(f, selected_ids, options = {}, options_html = {})
  taxonomy_selects(f, selected_ids, Organization, 'Organizations', options, options_html)
end

#show_location_tab?Boolean


2
3
4
# File 'app/helpers/taxonomy_helper.rb', line 2

def show_location_tab?
  SETTINGS[:locations_enabled] && User.current.allowed_to?(:view_locations)
end

#show_organization_tab?Boolean


6
7
8
# File 'app/helpers/taxonomy_helper.rb', line 6

def show_organization_tab?
  SETTINGS[:organizations_enabled] && User.current.allowed_to?(:view_organizations)
end

#show_taxonomy_tabs?Boolean


10
11
12
# File 'app/helpers/taxonomy_helper.rb', line 10

def show_taxonomy_tabs?
  SETTINGS[:locations_enabled] or SETTINGS[:organizations_enabled]
end

#taxonomy_ids_symObject


103
104
105
# File 'app/helpers/taxonomy_helper.rb', line 103

def taxonomy_ids_sym
  is_location? ? :location_ids : :organization_ids
end

#taxonomy_selects(f, selected_ids, taxonomy, label, options = {}, options_html = {}) ⇒ Object


115
116
117
118
119
# File 'app/helpers/taxonomy_helper.rb', line 115

def taxonomy_selects(f, selected_ids, taxonomy, label, options = {}, options_html = {})
  options[:disabled] = Array.wrap(options[:disabled]) + Array.wrap(taxonomy.current.try(:id))
  options[:label]    ||= _(label)
  multiple_selects f, label.downcase, taxonomy, selected_ids, options, options_html
end

#taxonomy_singleObject


32
33
34
# File 'app/helpers/taxonomy_helper.rb', line 32

def taxonomy_single
  _(controller_name.singularize)
end

#taxonomy_titleObject


36
37
38
# File 'app/helpers/taxonomy_helper.rb', line 36

def taxonomy_title
  _(controller_name.singularize.titleize)
end

#taxonomy_upcaseObject


40
41
42
# File 'app/helpers/taxonomy_helper.rb', line 40

def taxonomy_upcase
  _(controller_name.humanize.titleize)
end

#wizard_header(current, *args) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/taxonomy_helper.rb', line 44

def wizard_header(current, *args)
  (:ul,:class=>"wizard") do
    step=1
    content = nil
    args.each do |arg|
      step_content = (:li,((:span,step,:class=>"badge" +" #{'badge-inverse' if step==current}")+arg).html_safe, :class=>"#{'active' if step==current}")
      step == 1 ? content = step_content : content += step_content
      step += 1
    end
    content
  end
end