{% extends "wginfo/wg_base.html" %}

{% block wg_titledetail %}Manage Workflow{% endblock %}

{% block pagehead %}
{{ block.super }}
<script type="text/javascript" src="/js/lib/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/yui/yui-20100305.js"></script>
<script type="text/javascript" src="/js/base.js"></script>
{% endblock pagehead %}

{% block wg_content %}
<div class="wg-workflow-management">
<h2>Edit workflow</h2>
<div id="mytabs" class="yui-navset">
<ul class="yui-nav">
  <li class="selected"><a href="#info"><em>Info</em></a></li>
  <li><a href="#states"><em>Select states</em></a></li>
  <li><a href="#transitions"><em>Edit transitions</em></a></li>
  <li><a href="#tags"><em>Select Annotation Tags</em></a></li>
</ul>

<div class="yui-content">
<div id="info">
<table style="width: 100%;"><tr style="vertical-align: top;"><td>
<table class="ietf-table" style="width: 100%">
  <tr> 
    <th>States used in {{ wg }} Working Group</th>
  </tr>
  {% for state in states %}
  <tr class="{% cycle "oddrow" "evenrow" %}">
    <td>{{ state.name }}</td>
  </tr>
{% endfor %}
</table><br />
<table class="ietf-table" style="width: 100%;">
  <tr> 
    <th>Annotation tags used in {{ wg }} Working Group</th>
  </tr>
  {% for tag in tags %}
  <tr class="{% cycle "oddrow" "evenrow" %}">
    <td>{{ tag.name }}</td>
  </tr>
{% endfor %}
</table>
</td><td>
<table class="ietf-table" style="width: 100%;">
  <tr>
    <th>Transition name</th><th>Initial states</th><th>Destination state</th>
  </tr>
  {% for transition in workflow.transitions.all %}
  <tr class="{% cycle "oddrow" "evenrow" %}">
    <td>
      {{ transition.name }}
    </td>
    <td>
    {% for state in transition.states.all %}
      {{state.name }}{% if not forloop.last %}<br />{% endif %}
    {% endfor %}
    </td>
    <td>
      {{ transition.destination.name }}
    </td>
  </tr>
  {% endfor %}
  {% if not workflow.transitions.all.count %}
  <tr class="oddrow"><td colspan="3">There are no transitions defined so any state change is allowed</td></tr>
  {% endif %}
</table>
</td></tr></table>
</div>

<div id="states">
<p>
Please note that the states you can not uncheck are needed in all IETF WGs.
</p>
<p>
You can see the default Working Group I-D State Diagram in <a href="http://tools.ietf.org/html/rfc6174#section-4.1">Section 4.1 of RFC6174</a>
</p>
<form action="#info" method="POST">
<table class="ietf-table">
  <tr> 
    <th>Used in {{ wg }}</th><th>Available states</th><th>Definition</th>
  </tr>
  {% for state in default_states %}
  <tr class="{% cycle "oddrow" "evenrow" %}" style="vertical-align: top;">
    <td><input type="checkbox" id="id_states_{{ state.pk }}" name="states" value="{{ state.pk }}" {% if state.used %}checked="checked" {% endif %}{% if state.freeze %} disabled="disabled"{% endif %}/></td>
    <td><label for="id_states_{{ state.pk }}">{{ state.name }}</label></td>
    <td>
    <div class="statedefinition" style="height: 1em; overflow: hidden;">
       <pre style="margin-top: 0px;"><a class="showDefinition" href="#">[+]</a><a class="hideDefinition" style="display: none;" href="#">[-]</a> {{ state.statedescription_set.all.0.definition|safe }}</pre>
    </div>
    </td>
  </tr>
{% endfor %}
</table>
<input type="submit" name="update_states" value="Update states" />
</form>
</div>

<div id="transitions">
<p>
You can see the default Working Group I-D State Diagram in <a href="http://tools.ietf.org/html/rfc6174#section-4.1">Section 4.1 of RFC6174</a>
</p>
<form action="#transitions" method="POST">
<table class="ietf-table">
  <tr>
    <th>Delete</th><th>Transition name</th><th>Initial states</th><th>Destination state</th>
  </tr>
{{ formset.as_table }}
</table>
<input type="submit" name="update_transitions" value="Update transitions" />
</form>
</div>

<div id="tags">
<form action="#info" method="POST">
<table class="ietf-table">
  <tr> 
    <th>Used in {{ wg }}</th><th>Available annotation tags</th>
  </tr>
  {% for tag in default_tags %}
  <tr class="{% cycle "oddrow" "evenrow" %}">
    <td><input type="checkbox" id="id_tags_{{ tag.pk }}" name="tags" value="{{ tag.pk }}" {% if tag.used %}checked="checked" {% endif %}/></td>
    <td><label for="id_tags_{{ tag.pk }}">{{ tag.name }}</label></td>
  </tr>
{% endfor %}
</table>
<input type="submit" name="update_tags" value="Update tags" />
</form>
</div>
</div>
</div>

<script type="text/javascript">
//<![CDATA[
var tabView = new YAHOO.widget.TabView('mytabs');
var url = location.href.split('#'); 
if (url[1]) { 
  url[1] = "#"+url[1];
  var tabs = tabView.get('tabs'); 
  for (var i = 0; i < tabs.length; i++) { 
    if (url[1].indexOf(tabs[i].get('href')) == 0) {
      tabView.set('activeIndex', i);
      break; 
     } 
  } 
} 

jQuery('.showDefinition').click(function() {
    jQuery(this).parent().parent().css('height', 'auto');
    jQuery(this).hide();
    jQuery(this).next().show();
    return false;
});
jQuery('.hideDefinition').click(function() {
    jQuery(this).parent().parent().css('height', '1em');
    jQuery(this).hide();
    jQuery(this).prev().show();
    return false;
});
//]]>
</script>

{% endblock %}
