<%= render :partial => 'sub_menu' %>

<div class='toolbar'>
  <ul class='actions'>
    <li id="new_ot_link">
      <%= button_link_to t("cms.new_post"), new_object_url,
                         {:remote => true,
                         'data-update' => 'new-post',
                         :icon => 'add'} %>
    </li>
  </ul>
  <br class='clear' />
</div>


<h1><%= "#{t('actions.listing')} #{t('posts')}" %></h1>

<%= image_tag "spinner.gif", :plugin=>"spree", :style => "display:none", :id => 'busy_indicator' %>
<div id="new-post"></div>

<table class="index">
  <tr>
    <%= hook :admin_posts_index_headers do %>
      <th><%= order @search, :by => :title, :as => t("cms.title") %></th>
      <th><%= order @search, :by => :author, :as => t("cms.author") %></th>
      <th><%= t("cms.tags") %></th>
      <th><%= order @search, :by => :date, :as => t("cms.date") %></th>
    <% end %>
    <th>
      <%= hook :admin_posts_index_header_actions %>
    </th>
  </tr>

<% @collection.each do |post| %>
  <%- locals = {:post => post} -%>
  <tr>
    <%= hook :admin_posts_index_rows, locals do %>
      <td><%= link_to h(post.title), [:edit,:admin,post] %> (<%= post.is_active == 1 ? t("cms.published") : t("cms.draft") %>) </td>      
      <td><%= link_to post.user.display_name, [:admin, post.user] %></td>
      <td><%= post.tag_list %></td>
      <td><%= (post.published_at.blank? ? post.updated_at : post.published_at).strftime("%B %d, %Y at %I:%M%p") %></td>
      <td class="actions">
        <%= hook :admin_pages_index_row_actions, locals do %>
          <%= link_to_edit post %>
          &nbsp;
          <%= link_to_delete post %>
        <% end %>
      </td>
    <% end %>
  </tr>
<% end %>
</table>

<%= will_paginate(:previous_label => "&#171; #{t('previous')}", :next_label => "#{t('next')} &#187;") %>

<%= content_for :sidebar do %>

  <%= form_for @search do |f| %>
    <div class="box">
      <h3><%= t(:search) %></h3>

      <%- locals = {:f => f} -%>
      <%= hook :admin_posts_index_search, locals do %>
        <p>
          <label><%= t("cms.title") %></label><br />
          <%= f.text_field :title_contains, :size => 15 %>
        </p>
        
        <label><%= t("cms.published_date_range") %></label><br />
        <div class="yui-g date-range-filter">
          <div class="yui-u sub-field first">
            <%= f.unobtrusive_date_text_picker :published_at_after %><br />
            <label class="sub"><%= t("start") %></label>
          </div>
          <div class="yui-u sub-field">
            <%= f.unobtrusive_date_text_picker :published_at_before %><br />
            <label><%= t("stop") %></label>
          </div>
        </div>

        <p>
          <label><%= t("cms.author") %></label><br />
          <%= collection_select( :user, :user_id, User.roles_name_equals("admin"), :id, :display_name) %></p>
        </p>
        <p>
          <%= f.check_box :is_active, {:style => "vertical-align:middle;"}, "1", ""  %>
          <label>
            <%= t("cms.show_only_published_posts") %>
          </label>
        </p>
      <% end %>

      <%= hook :admin_posts_index_search_buttons, locals do %>
        <p class="form-buttons">
          <%= button t("search") %>
        </p>
      <% end %>
    </div>
  <% end %>

<% end %>