<% if @user.present? and @device.present? and @commands.count > 1 %>
  <%= form_for(CommandsUserVehicle.new, url: save_permission_by_client_hardware_profiles_path(:format => "js"), remote: true, method: :post) do |f| %>
    <%= f.hidden_field :vehicle_id, value: @vehicle.id %>
    <%= f.hidden_field :client_id, value: @vehicle.client.id %>
    <%= f.hidden_field :user_id, value: @user.id %>
    <table class="table-content-crud table table-hover table-striped">
      <thead>
      <tr>
        <th><%= _("Command") %></th>
        <th><%= _("Enable") %></th>
      </tr>
      </thead>
      <tbody>
        <% @commands.where("name <> 'custom'").each do |command| %>
          <% checked = CommandsUserVehicle.find_by(command_id: command.id, vehicle_id: @vehicle.id, client_id:  @vehicle.client.id, user_id: @user.id) %>
          <tr>
            <td><%= command.name %></td>
            <td><input type="checkbox" name="commands_enabled[<%= command.id %>]" <%= "checked" if checked %>></td>
          </tr>
        <% end %>
      </tbody>
    </table>

    <input type="checkbox" name="all_users" id="all_users"> <label for="all_users"><%= _("apply all users?") %></label>
    <br>
    <input type="checkbox" name="all_vehicles" id="all_vehicles"> <label for="all_vehicles"><%= _("apply all vehicles?") %></label>
    <br>
    <%= f.submit _("Send") %>
  <% end %>
<% else %>
  <%= _("No info to show") %>
<% end %>
