<style type="text/css">
  #manualMeasures td {
    vertical-align: top;
  }

  #manualMeasures td.pendingMeasure {
    background-color: orange;
    padding: 0 2px;
    width: 2px;
  }
</style>

<div class="page">
  <header class="page-header">
    <h1 class="page-title"><%= message('manual_measures.page') -%></h1>
    <div class="page-actions">
      <a id="addMeasureLink"
         href="<%=ApplicationController.root_context-%>/manual_measures/create_form/<%= @resource.id -%>"
         class="open-modal link-action"><%= message('manual_measures.add_measure') -%></a>
    </div>
    <p class="page-description"><%= message('manual_measures.page.description') -%></p>
  </header>

  <% has_pendings=false %>
  <table class="width100 data sortable" id="manualMeasures">
    <thead>
    <tr>
      <th style="padding: 0; margin: 0" class="nosort"></th>
      <th class="thin nowrap"><%= message('manual_measures.col.domain') -%></th>
      <th class="thin nowrap sortfirstasc"><%= message('manual_measures.col.metric') -%></th>
      <th class="thin nowrap nosort" style="text-align: right"><%= message('manual_measures.col.value') -%></th>
      <th><%= message('manual_measures.col.description') -%></th>
      <th class="righticon" style="text-align: right"><%= message('manual_measures.col.author') -%></th>
      <th class="righticon" style="text-align: right"><%= message('manual_measures.col.date') -%></th>
      <th class="thin nowrap nosort"><%= message('manual_measures.col.operations') -%></th>
    </tr>
    </thead>
    <tbody>
    <% if @measures.empty? %>
      <td colspan="8" class="even">No measures</td>
    <% end %>
    <%
       @measures.each do |measure|
    %>
      <a name="<%= measure.metric.key -%>"></a>
      <tr>
        <% if measure.pending?(@snapshot)
             has_pendings=true
        %>
          <td class="pendingMeasure"></td>
        <% else %>
          <td style="padding: 0"></td>
        <% end %>
        <td class="thin nowrap"><%= measure.metric.domain -%></td>
        <td class="thin nowrap"><%= measure.metric.short_name -%></td>
        <td class="thin nowrap" align="right"><%= measure.formatted_value -%></td>
        <td id="desc"><%= measure.description -%></td>
        <td align="right"><%= measure.username -%>
        </td>
        <td align="right">
          <%= l(measure.updated_at) -%>
        </td>
        <td class="thin nowrap">
          <a href="<%= url_for :controller => 'manual_measures', :action => 'edit_form', :metric => measure.metric.key, :id => @resource.id -%>" class="open-modal link-action"><%= message('edit') -%></a>&nbsp;

          <%= link_to_action message('delete'), "#{ApplicationController.root_context}/manual_measures/delete/#{ @resource.id}?metric=#{measure.metric.key}",
                             :class => 'link-action link-red',
                             :id => "delete_#{measure.metric.key}",
                             :confirm_button => message('delete'),
                             :confirm_title => message('manual_measures.delete_measure'),
                             :confirm_msg => message('manual_measures.delete_measure.desc', :params => [measure.metric.short_name])
          -%>
        </td>
      </tr>
    <% end %>
    </tbody>
  </table>
  <script>jQuery('#manualMeasures').sortable();</script>

  <% if has_pendings %>
    <div class="doc">
      <p>
        <span style="background-color: orange;width: 8px;height: 8px;display: inline-block;vertical-align: middle;margin-right: 5px"> </span>
        <%= message('manual_measures.pending_message') -%>
      </p>
    </div>
  <% end %>
</div>
