foreman/app/helpers/taxonomy_helper.rb @ 9d43fc71
611f5bff | Amos Benari | module TaxonomyHelper
|
|
1fa008a4 | Joseph Magen | include AncestryHelper
|
|
3952cb53 | amirfefer | include FormHelper
|
|
1fa008a4 | Joseph Magen | ||
611f5bff | Amos Benari | def show_location_tab?
|
|
SETTINGS[:locations_enabled] && User.current.allowed_to?(:view_locations)
|
|||
end
|
|||
def show_organization_tab?
|
|||
SETTINGS[:organizations_enabled] && User.current.allowed_to?(:view_organizations)
|
|||
end
|
|||
9a280163 | Dominic Cleal | def taxonomy_single
|
|
_(controller_name.singularize)
|
|||
671b45e9 | Joseph Mitchell Magen | end
|
|
9a280163 | Dominic Cleal | def taxonomy_title
|
|
_(controller_name.singularize.titleize)
|
|||
671b45e9 | Joseph Mitchell Magen | end
|
|
def taxonomy_upcase
|
|||
9a280163 | Dominic Cleal | _(controller_name.humanize.titleize)
|
|
671b45e9 | Joseph Mitchell Magen | end
|
|
f9171fc3 | Tomer Brisker | def taxonomy_new
|
|
is_location? ? _("New Location") : _("New Organization")
|
|||
end
|
|||
85eac622 | Amos Benari | def wizard_header(current, *args)
|
|
9d43fc71 | Michael Moll | content_tag(:ul, :class => "wizard") do
|
|
step = 1
|
|||
85eac622 | Amos Benari | content = nil
|
|
args.each do |arg|
|
|||
9d43fc71 | Michael Moll | step_content = content_tag(:li, (content_tag(:span, step, :class => "badge" + " #{'badge-inverse' if step == current}") + arg).html_safe, :class => ('active' if step == current).to_s)
|
|
da9865b8 | Michael Moll | (step == 1) ? content = step_content : content += step_content
|
|
85eac622 | Amos Benari | step += 1
|
|
end
|
|||
content
|
|||
end
|
|||
end
|
|||
671b45e9 | Joseph Mitchell Magen | ||
5f029ed6 | Daniel Lobato | def option_button(text, href, options)
|
|
85eac622 | Amos Benari | field(nil, "", options) do
|
|
link_to(text, href, options)
|
|||
end
|
|||
end
|
|||
671b45e9 | Joseph Mitchell Magen | ||
da04b443 | Joseph Mitchell Magen | def is_location?
|
|
controller_name == "locations"
|
|||
end
|
|||
def edit_taxonomy_path(taxonomy)
|
|||
is_location? ? edit_location_path(taxonomy) : edit_organization_path(taxonomy)
|
|||
end
|
|||
def hash_for_edit_taxonomy_path(taxonomy)
|
|||
is_location? ? hash_for_edit_location_path(:id => taxonomy) : hash_for_edit_organization_path(:id => taxonomy)
|
|||
end
|
|||
def hash_for_clone_taxonomy_path(taxonomy)
|
|||
is_location? ? hash_for_clone_location_path(:id => taxonomy) : hash_for_clone_organization_path(:id => taxonomy)
|
|||
end
|
|||
1fa008a4 | Joseph Magen | def hash_for_nest_taxonomy_path(taxonomy)
|
|
is_location? ? hash_for_nest_location_path(taxonomy) : hash_for_nest_organization_path(taxonomy)
|
|||
end
|
|||
da04b443 | Joseph Mitchell Magen | def hash_for_taxonomy_path(taxonomy)
|
|
is_location? ? hash_for_location_path(:id => taxonomy) : hash_for_organization_path(:id => taxonomy)
|
|||
end
|
|||
def hash_for_new_taxonomy_path
|
|||
is_location? ? hash_for_new_location_path : hash_for_new_organization_path
|
|||
end
|
|||
def mismatches_taxonomies_path
|
|||
is_location? ? mismatches_locations_path : mismatches_organizations_path
|
|||
end
|
|||
5f029ed6 | Daniel Lobato | def import_mismatches_taxonomy_path(taxonomy)
|
|
bff31850 | Ohad Levy | is_location? ? import_mismatches_location_path(taxonomy) : import_mismatches_organization_path(taxonomy)
|
|
end
|
|||
c65bdeac | Joseph Magen | def hash_for_mismatches_taxonomies_path
|
|
is_location? ? hash_for_mismatches_locations_path : hash_for_mismatches_organizations_path
|
|||
end
|
|||
def hash_for_import_mismatches_taxnomies_path
|
|||
is_location? ? hash_for_import_mismatches_locations_path : hash_for_import_mismatches_organizations_path
|
|||
end
|
|||
da04b443 | Joseph Mitchell Magen | def assign_all_hosts_taxonomy_path(taxonomy)
|
|
is_location? ? assign_all_hosts_location_path(taxonomy) : assign_all_hosts_organization_path(taxonomy)
|
|||
end
|
|||
def assign_hosts_taxonomy_path(taxonomy)
|
|||
is_location? ? assign_hosts_location_path(taxonomy) : assign_hosts_organization_path(taxonomy)
|
|||
end
|
|||
111ef124 | Joseph Mitchell Magen | def taxonomy_ids_sym
|
|
is_location? ? :location_ids : :organization_ids
|
|||
end
|
|||
410505f4 | Marek Hulan | def organization_selects(f, selected_ids, options = {}, options_html = {})
|
|
taxonomy_selects(f, selected_ids, Organization, 'Organizations', options, options_html)
|
|||
end
|
|||
def location_selects(f, selected_ids, options = {}, options_html = {})
|
|||
taxonomy_selects(f, selected_ids, Location, 'Locations', options, options_html)
|
|||
end
|
|||
def taxonomy_selects(f, selected_ids, taxonomy, label, options = {}, options_html = {})
|
|||
e611a26c | Joseph Magen | options[:disabled] = Array.wrap(options[:disabled])
|
|
9d43fc71 | Michael Moll | options[:label] ||= _(label)
|
|
2d69ecbf | Marek Hulan | multiple_selects f, label.downcase.singularize + '_ids', taxonomy.authorized("assign_#{label.downcase}", taxonomy), selected_ids, options, options_html
|
|
410505f4 | Marek Hulan | end
|
|
42a712b3 | Tomer Brisker | ||
def all_checkbox(f, resource)
|
|||
f358e676 | Marek Hulan | return ''.html_safe unless User.current.admin? || User.current.filters.joins(:permissions).where({:'permissions.name' => "view_#{resource}",
|
|
42a712b3 | Tomer Brisker | :search => nil,
|
|
:taxonomy_search => nil}).present?
|
|||
checkbox_f(f, :ignore_types,
|
|||
{:label => translated_label(resource, :all),
|
|||
:multiple => true,
|
|||
:onchange => 'ignore_checked(this)'},
|
|||
707d9bdd | Shlomi Zadok | resource.to_s.classify)
|
|
42a712b3 | Tomer Brisker | end
|
|
def show_resource_if_allowed(f, taxonomy, resource_options)
|
|||
if resource_options.is_a? Hash
|
|||
resource = resource_options[:resource]
|
|||
association = resource_options[:association]
|
|||
else
|
|||
resource = resource_options
|
|||
association = resource.to_s.classify.constantize
|
|||
end
|
|||
return unless User.current.allowed_to?("view_#{resource}".to_sym)
|
|||
02e4c535 | Daniel Lobato | ids = "#{association.where(nil).klass.to_s.underscore.singularize}_ids".to_sym
|
|
42a712b3 | Tomer Brisker | ||
content_tag(:div, :id => resource, :class => "tab-pane") do
|
|||
all_checkbox(f, resource) +
|
|||
02e4c535 | Daniel Lobato | multiple_selects(f, association.where(nil).klass.to_s.underscore.pluralize.to_sym, association, taxonomy.selected_or_inherited_ids[ids],
|
|
42a712b3 | Tomer Brisker | {:disabled => taxonomy.used_and_selected_or_inherited_ids[ids],
|
|
:label => translated_label(resource, :select)},
|
|||
{'data-mismatches' => taxonomy.need_to_be_selected_ids[ids].to_json,
|
|||
'data-inheriteds' => taxonomy.inherited_ids[ids].to_json,
|
|||
'data-useds' => taxonomy.used_ids[ids].to_json })
|
|||
end
|
|||
end
|
|||
def translated_label(resource, verb)
|
|||
labels = { :users => { :all => _("All users"), :select => _("Select users") },
|
|||
:smart_proxies => { :all => _("All smart proxies"), :select => _("Select smart proxies") },
|
|||
:subnets => { :all => _("All subnets"), :select => _("Select subnets") },
|
|||
:compute_resources => { :all => _("All compute resources"), :select => _("Select compute resources") },
|
|||
:media => { :all => _("All media"), :select => _("Select media") },
|
|||
510d53cd | Marek Hulan | :provisioning_templates => { :all => _("All provisioning templates"), :select => _("Select provisioning templates") },
|
|
:ptables => { :all => _("All partition tables"), :select => _("Select partition tables") },
|
|||
42a712b3 | Tomer Brisker | :domains => { :all => _("All domains"), :select => _("Select domains") },
|
|
:realms => { :all => _("All realms"), :select => _("Select realms") },
|
|||
:environments => { :all => _("All environments"), :select => _("Select environments") },
|
|||
f4459c11 | David Davis | :hostgroups => { :all => _("All host groups"), :select => _("Select host groups") }
|
|
42a712b3 | Tomer Brisker | }
|
|
labels[resource][verb]
|
|||
end
|
|||
f619eb4d | Marek Hulan | ||
def org_loc_string(conjunction)
|
|||
Taxonomy.enabled_taxonomies.map { |tax| _(tax) }.join(" #{conjunction} ")
|
|||
end
|
|||
611f5bff | Amos Benari | end
|