<%= javascript 'host_edit' %>
<%= 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-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, accessible_hostgroups, :id, :to_label, {:include_blank => true}, {:label => _('Parent'),
                      :onchange => 'hostgroup_changed(this);', :'data-url'=> process_hostgroup_hostgroups_path,
                      :help_inline => :indicator } %>
      <%= text_f f, :name %>
      <%= select_f f, :environment_id, Environment.all, :id, :to_label, {:include_blank => true},
        {:label => _("Environment"), :onchange => 'update_puppetclasses(this);', :"data-url" => environment_selected_hostgroups_path} %>
      <%= select_f(f, :compute_profile_id, ComputeProfile.visibles, :id, :name, {:include_blank => (f.object.parent_id.present? ? _("Inherit from parent") : '')},
                                                                                  {: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">
      <%= render 'common/domain_subnet', :item => @hostgroup %>
    </div>

    <div class="tab-pane" id="os">
      <%= render "common/os_selection/initial", :item=> @hostgroup %>
      <%= password_f f, :root_pass %>
    </div>

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

    <% if show_location_tab? %>
      <div class="tab-pane" id="locations">
        <%= location_selects f, @hostgroup.location_ids %>
      </div>
    <% end %>

    <% if show_organization_tab? %>
      <div class="tab-pane" id="organizations">
        <%= organization_selects f, @hostgroup.organization_ids %>
      </div>
    <% end %>
  </div>

  <%= submit_or_cancel f %>
<% end %>
