<%= javascript 'host_edit', 'host_edit_interfaces', 'class_edit', 'lookup_keys' %>
<%= form_for @hostgroup, :html => {:data => {:id => @hostgroup.try(:id)}} do |f| %>
  <%= base_errors_for @hostgroup %>

  <ul class="nav nav-tabs" data-tabs="tabs">
    <li class="active"><a href="#primary" data-toggle="tab"><%= _('Hostgroup') %></a></li>
    <li><a href="#puppet_klasses" data-toggle="tab"><%= _('Puppet Classes') %></a></li>
    <% if SETTINGS[:unattended] %>
      <li><a href="#network" data-toggle="tab"><%= _('Network') %></a></li>
      <li><a href="#os" data-toggle="tab"><%= _('Operating System') %></a></li>
    <% end %>
    <li><a href="#params" id='params-tab' data-url='<%= current_parameters_hostgroups_path %>' data-url2='<%= puppetclass_parameters_hostgroups_path %>' data-toggle="tab"><%= _('Parameters') %></a></li>
    <% if show_location_tab? %>
      <li><a href="#locations" data-toggle="tab"><%= _('Locations') %></a></li>
    <% end %>
    <% if show_organization_tab? %>
      <li><a href="#organizations" data-toggle="tab"><%= _('Organizations') %></a></li>
    <% end %>
  </ul>

  <div class="tab-content">

    <div class="tab-pane active" id="primary">
      <%= select_f(f, :parent_id, parent_hostgroups, :id, :to_label, {:include_blank => true}, {:label => _('Parent'),
                      :onchange => 'hostgroup_changed(this);', :'data-url'=> process_hostgroup_hostgroups_path,
                      :help_inline => :indicator }) if show_parent?(@hostgroup) %>
      <%= text_f f, :name %>
      <%= select_f f, :environment_id, Environment.all, :id, :to_label, {:include_blank => blank_or_inherit_f(f, :environment)},
        {:label => _("Environment"), :onchange => 'update_puppetclasses(this);', :"data-url" => environment_selected_hostgroups_path} %>
      <%= select_f(f, :compute_profile_id, ComputeProfile.visibles, :id, :name,
                       { :include_blank => blank_or_inherit_f(f, :compute_profile) },
                       { :label => _("Compute profile") }
                  ) if ComputeProfile.visibles.any? %>
      <%= puppet_master_fields f %>
    </div>

    <div class="tab-pane" id="puppet_klasses">
      <% if @environment or @hostgroup.environment %>
        <%= render 'puppetclasses/class_selection', :obj => @hostgroup %>
      <% else %>
        <%= alert :class => 'alert-warning', :text =>  _('Please select an environment first') %>
      <% end %>
    </div>

    <div class="tab-pane" id="network">
      <fieldset>
        <%= select_f f, :domain_id, accessible_domains, :id, :to_label, {:include_blank => blank_or_inherit_f(f, :domain)},
          {:help_inline => :indicator, :label => _("Domain"),
           :onchange => 'interface_domain_selected(this);', :'data-url' => method_path('domain_selected') } %>
        <%= select_f f, :subnet_id, domain_subnets, :id, :to_label,
                     { :include_blank => domain_subnets.any? ? blank_or_inherit_f(f, :subnet) : _("No subnets") },
                     { :disabled => domain_subnets.empty?,
                       :data     => { :url     => SETTINGS[:unattended] ? freeip_subnets_path : '',
                                      :subnets => subnets_ipam_data.to_json },
                       :label    => _("Subnet"),
                       :help_inline => :indicator } %>
        <%= select_f f, :realm_id, Realm.with_taxonomy_scope_override(@location,@organization).authorized(:view_realms), :id, :to_label,
                        {:include_blank => blank_or_inherit_f(f, :realm)}, {:label => _("Realm")} %>
      </fieldset>
    </div>

    <div class="tab-pane" id="os">
      <%= render "common/os_selection/initial", :item=> @hostgroup %>
      <%= password_f f, :root_pass, :help_inline => _("Password must be 8 characters or more")%>
    </div>

    <div class="tab-pane" id="params">
      <h4><%= _('Puppet classes parameters') %></h4>
      <p/>
      <%= render "puppetclasses/classes_parameters", { :obj => @hostgroup } %>
      <p/>
      <%= render "common_parameters/puppetclasses_parameters", :f => f %>
      <p/>
      <h4><%= _('Host group parameters') %></h4>
      <p/>
      <% if @hostgroup.parent.present? %>
          <%= render "common_parameters/parent_parameter", :f => f %>
      <% end %>
      <p/>
      <%= render "common_parameters/parameters", { :f => f, :type => :group_parameters } %>
    </div>

    <%= render "taxonomies/loc_org_tabs", :f => f, :obj => @hostgroup %>
  </div>

  <%= f.hidden_field :id %>
  <%= submit_or_cancel f %>
<% end %>
