{% extends "yawf/base.html" %}

{% block head %}
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
    <style>
        .warning {
            color: red;
            font-weight: bold;
        }
        .hidden {
            display: none;
        }
        .toggler {
            font-style: italic;
            cursor: pointer;
            border-bottom: 1px dotted;
        }
    </style>

    <script>
        $(document).ready(function(){
            $(".toggler").click(function(){
                $(this).siblings("ul").toggleClass("hidden");
            });
        });
    </script>
{% endblock %}

{% block content %}
<p>ID: <b>{{ workflow.id }}</b></p>
<p>Verbose name: {% if workflow.verbose_name %}{{ workflow.verbose_name }}{% else %}<span class="warning">not specified</span>{% endif %}</p>

{% if not workflow.model_class %}
<p class="warning">Model class is not specified</p>
{% endif %}

<p>
    States:
    <ul>
{% for state_id, state_info in state_map.iteritems %}
    {% if state_info.messages %}
        <li>{{ state_id }} ({{ state_info.verbose_name }})
            <br/><span class="toggler">Available messages</span>
            <ul class="hidden">
        {% for message_id in state_info.messages %}
                <li>{{ message_id }}</li>
        {% endfor %}
            </ul>
        </li>
    {% else %}
        <li class="warning" title="No messages with registered handlers">{{ state_id }} ({{ state_info.verbose_name }})</li>
    {% endif %}
{% endfor %}
    </ul>
</p>

<p>
    Registered messages:
    <ul>
{% for message_id, message_info in message_map.iteritems %}
        <li>{{ message_id }}{% if message_info.spec.verb %} ({{ message_info.spec }}){% endif %}
    {% if not message_info.states_from %}
            <span class="warning">No handlers registered</span>
    {% else %}
            <br/><span class="toggler">States from which this message can be handled</span>
            <ul class="hidden">
        {% for state in message_info.states_from %}
                <li>{{ state }}</li>
        {% endfor %}
            </ul>
    {% endif %}
        </li>
{% empty %}
        <li class="warning">No messages registered</li>
{% endfor %}
    </ul>
</p>
{% endblock %}
