<div class="contextual">
<%= link_to sprite_icon('add', l(:label_user_new)), new_user_path, :class => 'icon icon-add' %>
  <%= actions_dropdown do %>
    <% if User.current.allowed_to?(:import_users, nil, :global => true) %>
      <%= link_to sprite_icon('import', l(:button_import)), new_users_import_path, :class => 'icon icon-import' %>
    <% end %>
  <% end %>
</div>

<h2><%= @query.new_record? ? l(:label_user_plural) : @query.name %></h2>
<%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description, class: 'subtitle') : '' %>

<%= form_tag(users_path, method: :get, id: 'query_form') do %>
  <%= render partial: 'queries/query_form' %>
<% end %>

<% if @query.valid? %>
  <% if @users.empty? %>
    <p class="nodata"><%= l(:label_no_data) %></p>
  <% else %>
    <%= render_query_totals(@query) %>
    <%= render partial: 'list', :locals => { :users => @users }%>
    <span class="pagination"><%= pagination_links_full @user_pages, @user_count %></span>
  <% end %>
  <% other_formats_links do |f| %>
    <%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '350px'); return false;" %>
  <% end %>

  <div id="csv-export-options" style="display:none;">
    <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
    <%= form_tag(users_path(format: 'csv'), method: :get, id: 'csv-export-form') do %>
    <%= query_as_hidden_field_tags(@query) %>
    <%= hidden_field_tag('query_name', @query.name) %>
    <p>
      <label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br />
      <label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label>
    </p>
    <% if @query.available_block_columns.any? %>
      <fieldset id="csv-export-block-columns">
        <legend>
          <%= toggle_checkboxes_link('#csv-export-block-columns input[type=checkbox]') %>
        </legend>
        <% @query.available_block_columns.each do |column| %>
          <label><%= check_box_tag 'c[]', column.name, @query.has_column?(column), :id => nil %> <%= column.caption %></label>
        <% end %>
      </fieldset>
    <% end %>
    <%= export_csv_encoding_select_tag %>
    <%= export_csv_separator_select_tag %>
    <p class="buttons">
      <%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);", :data => { :disable_with => false } %>
      <%= link_to_function l(:button_cancel), "hideModal(this);" %>
    </p>
    <% end %>
  </div>
<% end %>

<% content_for :sidebar do %>
  <%= render_sidebar_queries(UserQuery, nil) %>
  <%= call_hook(:view_users_sidebar_queries_bottom) %>
<% end %>
<% html_title(l(:label_user_plural)) -%>
