<% if @versions.any? %>
  <div class="contextual">
    <%= link_to sprite_icon('lock', l(:label_close_versions)), close_completed_project_versions_path(@project), :class => 'icon icon-locked', :method => :put %>
  </div>
<% end %>
<p>
  <%= link_to sprite_icon('add', l(:label_version_new)), new_project_version_path(@project, :back_url => ''), :class => 'icon icon-add' if User.current.allowed_to?(:manage_versions, @project) %>
</p>

<%= form_tag(settings_project_path(@project, :tab => 'versions'), :method => :get) do %>
<fieldset><legend><%= l(:label_filter_plural) %></legend>
<label for='status'><%= l(:field_status) %>:</label>
<%= select_tag 'version_status', options_for_select([[l(:label_all), '']] + Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]}, @version_status), :onchange => "this.form.submit(); return false;"  %>
<label for='name'><%= l(:label_version) %>:</label>
<%= text_field_tag 'version_name', @version_name, :size => 30 %>
<%= submit_tag l(:button_apply), :name => nil %>
<%= link_to sprite_icon('reload', l(:button_clear)), settings_project_path(@project, :tab => 'versions'), :class => 'icon icon-reload' %>
</fieldset>
<% end %>
&nbsp;

<% if @versions.present? %>
<table class="list versions">
  <thead><tr>
    <th><%= l(:label_version) %></th>
    <th><%= l(:field_default_version) %></th>
    <th><%= l(:field_effective_date) %></th>
    <th><%= l(:field_description) %></th>
    <th><%= l(:field_status) %></th>
    <th><%= l(:field_sharing) %></th>
    <th><%= l(:label_wiki_page) %></th>
    <th style="width:15%"></th>
    </tr></thead>
  <tbody>
<% @versions.each do |version| %>
    <tr class="version <%=h version.status %> <%= 'shared' if version.project != @project %>">
    <% is_shared = version.project != @project %>
    <td class="name">
      <span class="<%= 'icon' if is_shared %>">
        <%= sprite_icon('link') if is_shared %>
        <%= link_to_version version %>
      </span>
    </td>
    <td class="tick"><%= checked_image(version.id == @project.default_version_id) %></td>
    <td class="date"><%= format_date(version.effective_date) %></td>
    <td class="description"><%= version.description %></td>
    <td class="status"><%= l("version_status_#{version.status}") %></td>
    <td class="sharing"><%=h format_version_sharing(version.sharing) %></td>
    <td><%= link_to_if_authorized(version.wiki_page_title, {:controller => 'wiki', :action => 'show', :project_id => version.project, :id => Wiki.titleize(version.wiki_page_title)}) || h(version.wiki_page_title) unless version.wiki_page_title.blank? || version.project.wiki.nil? %></td>
    <td class="buttons">
      <% if version.project == @project && User.current.allowed_to?(:manage_versions, @project) %>
        <%= link_to sprite_icon('edit', l(:button_edit)), edit_version_path(version), :class => 'icon icon-edit' %>
        <%= delete_link version_path(version) %>
      <% end %>
     </td>
    </tr>
<% end %>
    </tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
