[% PROCESS "global/field-descs.none.tmpl" %]

[% INCLUDE global/header.html.tmpl 
   title = "Edit Workflow" 
   style = '.col-header { width: 70px; }
            .checkbox-cell { border: 1px black solid }
            .open-status { color: green }
            .closed-status { color: red }
            .checked { background-color: lightblue }'
%]

[% open_statuses = ["UNCONFIRMED", "NEEDINFO", "NEW", "ASSIGNED", "REOPENED"] %]
[% closed_statuses = ["RESOLVED", "VERIFIED", "CLOSED", "BURIED"] %]
[% test_data = [ [ 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 ],
                 [ 0, 1, 2, 1, 1, 1, 0, 0, 0, 0 ],
                 [ 1, 1, 1, 2, 1, 0, 0, 0, 0, 0 ],
                 [ 0, 1, 1, 1, 2, 1, 0, 0, 0, 0 ],
                 [ 0, 0, 0, 0, 0, 2, 1, 1, 1, 0 ],
                 [ 2, 1, 1, 1, 1, 1, 2, 0, 0, 0 ],
                 [ 2, 0, 0, 0, 0, 0, 1, 2, 0, 0 ],
                 [ 2, 0, 0, 0, 0, 0, 0, 1, 2, 0 ],
                 [ 2, 0, 0, 0, 0, 0, 0, 0, 1, 2 ],
               ]
%]

[%# List concatenation in TT? %]
[% statuses =  open_statuses.merge(closed_statuses) %]

[% start = ["{Start}"] %]
[% status_cols = start.merge(statuses) %]

<script type="text/javascript">
  function toggle_cell(cell)
  {
    if (cell.checked)
    {
      cell.parentNode.style.backgroundColor = "lightblue";
    }
    else
    {
      cell.parentNode.style.backgroundColor = "inherit";
    }
  }
</script>

<p>This page allows you to define which status transitions are valid in your workflow.</p>

<table>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="[% status_cols.size %]" align="center">
    <h3>From</h3>
  </td>
</tr>

<tr>
  <th rowspan="[% status_cols.size %]" valign="center"><h3>To</h3></th>
  <th></th>
  [% FOREACH status = status_cols %]
    <th class="col-header
      [% closed_statuses.grep(status).0 ? " closed-status" : " open-status" %]
    ">
      [% status %]
    </th>
  [% END %]
</tr>

[% FOREACH status_row = statuses %]
  <tr>
    <th align="right" class="
      [% closed_statuses.grep(status_row).0 ? " closed-status" : " open-status" %]
    ">[% status_row %]</th>
    [% row_index = loop.index %]
    [% FOREACH status_col = status_cols %]
      [% col_index = loop.index %]
      <td align="center" class="checkbox-cell
        [% " checked" IF test_data.$row_index.$col_index == 1 %]"
      title="From [% status_col %] to [% status_row %]"
      >
        [% IF test_data.$row_index.$col_index != 2 %]
          <input type="checkbox"
            [% " checked='checked'" IF test_data.$row_index.$col_index == 1 %]
            onclick="toggle_cell(this)"
          >
        [% END %]
      </td>
    [% END %]
  </tr>
[% END %]

</table>

<br>

<p>[Note: this is the current Bugzilla workflow, with a couple of extra statuses (NEEDINFO, BURIED) thrown in for illustration purposes. Try clicking a checkbox. I believe this is all the UI that customised statuses would require. The presentation of the knob could be, in most cases, determined programmatically from the current state, the possible new states, and whether the transition was an open -> closed or not.]</p>


<br>

[% INCLUDE global/footer.html.tmpl %]