<%= javascript_tag do %>
  var workflowOptions = JSON.parse('<%= workflow_options_json.html_safe %>');
<% end %>
<div class="autoscroll">
  <table class="list workflows transitions transitions-<%= name %>">
    <thead>
      <tr>
        <th>
          <%= link_to_function('', "toggleCheckboxesBySelector('table.transitions-#{name} input[type=checkbox]')",
                                                              :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}", :class => 'icon icon-checked') %>
          <%=l(:label_current_status)%>
        </th>
        <th colspan="<%= @statuses.length %>"><%=l(:label_new_statuses_allowed)%></th>
      </tr>
      <tr>
        <td></td>
        <% @statuses.each_with_index do |new_status, position| %>
        <td style="width:<%= 75 / @statuses.size %>%;">
          <%= link_to_function('', "toggleCheckboxesBySelector('table.transitions-#{name} input.new-status-#{new_status.id}')",
                                                          :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}", :class => 'icon icon-checked') %>
          <span class="select-workflow-status-<%= position %>" data-values-selector="<%= "table.transitions select[id$='_#{new_status.id}_always']" %>">
            <%= new_status.name %>
          </span>
        </td>
        <% end %>
      </tr>
    </thead>
    <tbody>
      <% ([nil] + @statuses).each_with_index do |old_status, position| %>
      <% next if old_status.nil? && name != 'always' %>
      <% old_status_id = old_status.nil? ? 0 : old_status.id %>
      <tr class="<%= cycle('odd', 'even') %>">
        <td class="name">
          <%= link_to_function('', "toggleCheckboxesBySelector('table.transitions-#{name} input.old-status-#{old_status_id}')",
                                                              :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}", :class => 'icon icon-checked') %>

          <span class="select-workflow-status-<%= position %>" data-values-selector="<%= "table.transitions select[id^='transitions_#{old_status_id}_']" %>">
            <%= old_status.nil? ? content_tag('em', l(:label_issue_new)) : old_status.name %>
          </span>
        </td>
        <% for new_status in @statuses -%>
        <% checked = workflows.detect {|w| w.old_status_id == old_status_id && w.new_status_id == new_status.id} %>
        <td class="<%= checked ? 'enabled' : '' %>">
          <%= transition_tag workflows, old_status, new_status, name %>
        </td>
        <% w = workflows.select {|w| w.old_status_id == old_status_id && w.new_status_id == new_status.id}.size %>
          <%= javascript_tag do %>
            var data = {type: "multivalueselect", name: "test", source: workflowOptions, title: ' '}

            var $me = $('.select-workflow-status-<%= position %>');
            $me.wrap('<span class="editable-parent"></span>');
            $me.editable(data)
                .attr('title', I18n.titleInlineEditable);
            $('<span/>')
                .addClass('icon-edit')
                .attr('title', I18n.titleInlineEditableAll)
                .css('z-index', 2)
                .insertAfter($me)
                .click(function () {
                    $(this).prev().editable('toggle');
                    return false;
                });
            $me.removeClass('select-workflow-status-<%= position %>');
          <% end if !(w == 0 || w == @roles.size * @trackers.size) %>
        <% end -%>
      </tr>
      <% end %>
    </tbody>
  </table>
</div>
