<%- content_for :header_tags do %>
  <style>
    table { border-collapse: collapse; }
    td, th { padding-left: 1em; padding-right: 1em; text-align: left; vertical-align: top; border: 1px solid black; }
    th { font-weight: bold; }
    td.unfit { text-decoration: line-through; }
    td.selected { font-weight: bold; }
  </style>
<%- end %>

<script type="text/javascript">
  function enable_apply()
  {
    tasktracker = RB.$("#settings_task_tracker").val();
    submit = RB.$('input[type=submit]')

    disable = false;
    log = tasktracker + '::'
    RB.$("#settings_story_trackers :selected").each(function(i, selected){
      disable = disable || (RB.$(selected).attr('value') == tasktracker);
    });
    if (disable) {
      submit.attr('disabled', 'disabled');
    } else {
      submit.removeAttr('disabled');
    }
  }

  RB.$(document).ready(function() {
    RB.$("#settings_task_tracker").change(function() { enable_apply(); });
    RB.$("#settings_story_trackers").change(function() { enable_apply(); });

    enable_apply();
  });
</script>

<h2>Backlogs version <%= Backlogs.version %></h2>
<p>
  <%= content_tag(:label, l(:backlogs_story_tracker)) %>
  <%= select_tag("settings[story_trackers]", options_from_collection_for_select(Tracker.all, :id, :name, RbStory.trackers), :multiple => true) %>
  <table>
    <thead>
      <tr>
        <th>Tracker</th>
        <th>To&nbsp;do</th>
        <th>In&nbsp;progress</th>
        <th>Accepted</th>
        <th>Rejected</th>
      </tr>
    </thead>
    <tbody>
      <% Tracker.all.each do |tracker| %>
        <% states = tracker.issue_statuses.group_by {|status| status.backlog} %>
        <tr>
          <td class="<%= RbStory.trackers.include?(tracker.id) ? 'selected' : 'not-selected' %> <%= tracker.backlog? ? 'fit' : 'unfit' %>"><%= h(tracker.name) %></span></td>
          <td><%= h((states[:new] || []).join(', ')) %></td>
          <td><%= h((states[:in_progress] || []).join(', ')) %></td>
          <td><%= h((states[:success] || []).join(', ')) %></td>
          <td><%= h((states[:failure] || []).join(', ')) %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
</p>

<p>
  <%= content_tag(:label, l(:backlogs_task_tracker)) %>
  <%= select_tag("settings[task_tracker]", options_from_collection_for_select(Tracker.all, :id, :name, RbTask.tracker)) %>
</p>

<p>
  <%= content_tag(:label, l(:backlogs_points_burn_direction)) %>
  <%= select_tag("settings[points_burn_direction]",
            options_for_select([
                    [l(:label_points_burn_up), 'up'],
                    [l(:label_points_burn_down), 'down']
                ], Setting.plugin_redmine_backlogs[:points_burn_direction])) %>
</p>

<p>
  <%= content_tag(:label, l(:backlogs_card_specification)) %>
  <%= select_tag("settings[card_spec]", options_for_select(BacklogsCards::LabelStock::LAYOUTS.keys.sort.collect{|label| [label, label]}, Setting.plugin_redmine_backlogs[:card_spec])) %>
</p>

<p>
  <%= content_tag(:label, l(:rb_taskboard_card_order)) %>
  <%= select_tag("settings[taskboard_card_order]",
            options_for_select([
                    [l(:rb_task_cards_story_follows_tasks), 'story_follows_tasks'],
                    [l(:rb_task_cards_tasks_follow_story), 'tasks_follow_story'],
                    [l(:rb_task_cards_stories_then_tasks), 'stories_then_tasks']
                ], Setting.plugin_redmine_backlogs[:taskboard_card_order])) %>
</p>

<p>
  <%= content_tag(:label, l(:backlogs_wiki_template)) %>
  <%= text_field_tag("settings[wiki_template]", Setting.plugin_redmine_backlogs[:wiki_template]) %>
</p>

<p>
  <%= content_tag(:label, l(:rb_timelog_from_taskboard)) %>
	<%= check_box_tag("settings[timelog_from_taskboard]",'enabled',Setting.plugin_redmine_backlogs[:timelog_from_taskboard]) %>
</p>

<p>
  <%= content_tag(:label, l(:rb_show_burndown_in_sidebar)) %>
	<%= check_box_tag("settings[show_burndown_in_sidebar]",'enabled',Setting.plugin_redmine_backlogs[:show_burndown_in_sidebar]) %>
</p>

<p>
  <%= content_tag(:label, l(:field_story_points)) %>
  <%= l(:comma_delimited_numbers) %><br>
  <%= l(:use_free_text_if_empty) %><br>
  <%= text_field_tag("settings[story_points]", Setting.plugin_redmine_backlogs[:story_points]) %>
</p>

<p>
  <%= content_tag(:label, l(:rb_auto_refresh)) %>
  <%= select_tag("settings[autorefresh_wait]",
            options_for_select([
                    ['1',  '1000'],
                    ['10', '10000'],
                    ['30', '30000'],
                    ['60', '60000'],
                ], Setting.plugin_redmine_backlogs[:autorefresh_wait])) %>
</p>
