<%
sorting = active_scaffold_config.list.user.sorting
sorting_stages = ['reset', 'ASC', 'DESC']
default_sorting = active_scaffold_config.list.sorting
default_sorting_stages = ['ASC', 'DESC']
-%>
<% active_scaffold_config.list.columns.each do |column| -%>
  <%
  stages = default_sorting.sorts_on?(column) ? default_sorting_stages : sorting_stages
  column_sort_direction = stages.after(sorting.direction_of(column)) || 'ASC'
  sort_params = params_for(:action => :update_table, :page => 1,
                           :sort => column.name, :sort_direction => column_sort_direction)
  column_header_id = active_scaffold_column_header_id(column)
  -%>
  <th id="<%= column_header_id %>" class="<%= column.css_class unless column.css_class.nil? %> <%= "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column %>" title="<%= h column.description %>">
  <% if column.sortable? -%>
    <% href = url_for(sort_params) -%>
    <%= link_to_remote column.label,
      { :url => sort_params,
        :before => "addActiveScaffoldPageToHistory('#{href}', '#{controller_id}')",
        :loading => "Element.addClassName('#{column_header_id}','loading');",
        :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')",
        :update => active_scaffold_content_id,
        :method => :get },
      { :href => href } %>
   <% else -%>
     <p><%= column.label %></p>
   <% end -%>
 </th>
<% end -%>
<th class="actions">
</th>
