<% javascript 'taxonomy' %>
<%= form_for taxonomy do |f| %>
  <%= base_errors_for taxonomy %>
  <%= text_f f, :name %>
  <div class="form-group row">
    <ul class="nav nav-pills nav-stacked col-md-3" data-tabs="pills">
      <li class="active"><a href="#users" data-toggle="tab"><%= _("Users") %></a></li>
      <li><a href="#smart_proxies" data-toggle="tab"><%= _("Smart Proxies") %></a></li>
      <% if SETTINGS[:unattended] %>
        <li><a href="#subnets" data-toggle="tab"><%= _("Subnets") %></a></li>
        <li><a href="#compute_resources" data-toggle="tab"><%= _("Compute Resources") %></a></li>
        <li><a href="#media" data-toggle="tab"><%= _("Media") %></a></li>
        <li><a href="#template" data-toggle="tab"><%= _("Templates") %></a></li>
        <li><a href="#domains" data-toggle="tab"><%= _("Domains") %></a></li>
      <% end %>
      <li><a href="#environments" data-toggle="tab"><%= _("Environments") %></a></li>
      <li><a href="#hostgroups" data-toggle="tab"><%= _("Host Groups") %></a></li>
      <% if (taxonomy.is_a?(Organization) && SETTINGS[:locations_enabled]) %>
        <li><a href="#locations" data-toggle="tab"><%= _('Locations') %></a></li>
      <% elsif taxonomy.is_a?(Location) && SETTINGS[:organizations_enabled] %>
        <li><a href="#organizations" data-toggle="tab"><%= _("Organizations") %></a></li>
    <% end %>
      <li><a href="#params" data-toggle="tab"><%= _("Parameters") %></a></li>
    </ul>

    <div class="tab-content col-md-9">
      <div class="tab-pane active" id="users">
        <%= checkbox_f(f, :ignore_types, {:label => _("All users"), :multiple => true, :onchange => 'ignore_checked(this)'}, "User") %>
        <%= multiple_selects f, :users, User.except_admin, taxonomy.selected_ids[:user_ids],
           {:disabled => taxonomy.used_and_selected_ids[:user_ids], :label => _('Select users')},
           {'data-mismatches' => taxonomy.need_to_be_selected_ids[:user_ids].to_json} %>
      </div>

      <div class="tab-pane" id="smart_proxies">
        <%= checkbox_f(f, :ignore_types, {:label => _("All smart proxies"), :multiple => true, :onchange => 'ignore_checked(this)'}, "SmartProxy") %>
        <%= multiple_selects f, :smart_proxies, SmartProxy, taxonomy.selected_ids[:smart_proxy_ids],
           {:disabled => taxonomy.used_and_selected_ids[:smart_proxy_ids], :label => _('Select smart proxies')},
           {'data-mismatches' => taxonomy.need_to_be_selected_ids[:smart_proxy_ids].to_json} %>
      </div>

      <% if SETTINGS[:unattended] %>
        <div class="tab-pane" id="subnets">
          <%= checkbox_f(f, :ignore_types, {:label => _("All subnets"), :multiple => true, :onchange => 'ignore_checked(this)'}, "Subnet") %>
          <%= multiple_selects f, :subnets, Subnet, taxonomy.selected_ids[:subnet_ids],
            {:disabled => taxonomy.used_and_selected_ids[:subnet_ids], :label => _('Select subnets')},
            {'data-mismatches' => taxonomy.need_to_be_selected_ids[:subnet_ids].to_json} %>
        </div>

        <div class="tab-pane" id="compute_resources">
          <%= checkbox_f(f, :ignore_types, {:label => _("All compute resources"), :multiple => true, :onchange => 'ignore_checked(this)'}, "ComputeResource") %>
          <%= multiple_selects f, :compute_resources, ComputeResource, taxonomy.selected_ids[:compute_resource_ids],
            {:disabled => taxonomy.used_and_selected_ids[:compute_resource_ids], :label => _('Select compute resources')},
            {'data-mismatches' => taxonomy.need_to_be_selected_ids[:compute_resource_ids].to_json} %>
        </div>

        <div class="tab-pane" id="media">
          <%= checkbox_f(f, :ignore_types, {:label => _("All media"), :multiple => true, :onchange => 'ignore_checked(this)'}, "Medium") %>
          <%= multiple_selects f, :media, Medium, taxonomy.selected_ids[:medium_ids],
            {:disabled => taxonomy.used_and_selected_ids[:medium_ids], :label => _('Select media')},
            {'data-mismatches' => taxonomy.need_to_be_selected_ids[:medium_ids].to_json} %>
        </div>

        <div class="tab-pane" id="template">
          <%= checkbox_f(f, :ignore_types, {:label => _("All templates"), :multiple => true, :onchange => 'ignore_checked(this)'}, "ConfigTemplate") %>
          <%= multiple_selects f, :config_templates, ConfigTemplate, taxonomy.selected_ids[:config_template_ids],
            {:disabled => taxonomy.used_and_selected_ids[:config_template_ids], :label => _('Select templates')},
            {'data-mismatches' => taxonomy.need_to_be_selected_ids[:config_template_ids].to_json} %>
        </div>

        <div class="tab-pane" id="domains">
          <%= checkbox_f(f, :ignore_types, {:label => _("All domains"), :multiple => true, :onchange => 'ignore_checked(this)'}, "Domain") %>
          <%= multiple_selects f, :domains, Domain, taxonomy.selected_ids[:domain_ids],
            {:disabled => taxonomy.used_and_selected_ids[:domain_ids], :label => _('Select domains')},
            {'data-mismatches' => taxonomy.need_to_be_selected_ids[:domain_ids].to_json} %>
        </div>
      <% end %>

      <div class="tab-pane" id="environments">
        <%= checkbox_f(f, :ignore_types, {:label => _("All environments"), :multiple => true, :onchange => 'ignore_checked(this)'}, "Environment") %>
        <%= multiple_selects f, :environments, Environment, taxonomy.selected_ids[:environment_ids],
          {:disabled => taxonomy.used_and_selected_ids[:environment_ids], :label => _('Select environments')},
          {'data-mismatches' => taxonomy.need_to_be_selected_ids[:environment_ids].to_json} %>
      </div>

      <div class="tab-pane" id="hostgroups">
        <%= checkbox_f(f, :ignore_types, {:label => _("All host groups"), :multiple => true, :onchange => 'ignore_checked(this)'}, "Hostgroup") %>
        <%= multiple_selects f, :hostgroups, Hostgroup, taxonomy.selected_ids[:hostgroup_ids],
          {:disabled => taxonomy.used_and_selected_ids[:hostgroup_ids], :label => _('Select host groups')},
          {'data-mismatches' => taxonomy.need_to_be_selected_ids[:hostgroup_ids].to_json} %>
     </div>

      <% if taxonomy.is_a?(Location) && SETTINGS[:locations_enabled] %>
        <div class="tab-pane" id="organizations">
          <%= organization_selects f, taxonomy.selected_ids[:organization_ids],
                                   { :disabled => taxonomy.used_and_selected_ids[:organization_ids], :label => _('Select organizations')},
                                   { 'data-mismatches' => taxonomy.need_to_be_selected_ids[:organization_ids].to_json } %>
        </div>
      <% elsif taxonomy.is_a?(Organization) && SETTINGS[:organizations_enabled] %>
        <div class="tab-pane" id="locations">
          <%= location_selects f, taxonomy.selected_ids[:location_ids],
                               { :disabled => taxonomy.used_and_selected_ids[:location_ids], :label => _('Select locations')},
                               { 'data-mismatches' => taxonomy.need_to_be_selected_ids[:location_ids].to_json } %>
        </div>
      <% end %>

      <div class="tab-pane" id="params">
        <%= render "common_parameters/parameters", { :f => f, :type => :parameters } %>
      </div>

      <%= submit_or_cancel f %>
    </div>
  </div>
<% end %>
