{% extends 'default/base.html' %}
{% load i18n %}
{% load contains %}

{% block title %}{% trans "Config" %} - {{block.super}} {% endblock %}
{% block subtitle %}{% trans "Config" %}{% endblock %}

{% block head %}
<script type="text/javascript">
    window.addEvent('domready', function()
    {
        $$('#toptabs a').addEvent('click', function(e)
        {
            $$('#toptabs a').removeProperty('class');
            e.target.set('class', 'selected');

            $$('#tabs span').removeProperty('class');
            $('g_'+e.target.get('href').substring(1)).set('class', 'selected');

            var firstsel = $$('#tabs span.selected a')[0];
            firstsel.fireEvent('click', {target: firstsel});
            return false;
        });

	$$('#tabs a').addEvent('click', function(e)
        {
            $$('#tabs a').removeProperty('class');
            e.target.set('class', 'selected');

            $$('div.tabContent').set('class', 'tabContent hide');
            $(e.target.get('href').substring(1)).set('class', 'tabContent');
            return false;
        });

        $$('#toptabs a')[0].set('class', 'selected');
        $$('#tabs span')[0].set('class', 'selected')

        var firstsel = $$('#tabs span.selected a')[0];
        firstsel.fireEvent('click', {target: firstsel});
    });

    
</script>

{% endblock %}

{% block menu %}
<li>
    <a href="/" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> {% trans "Home" %}</a>
</li>
<li>
    <a href="/queue/" title=""><img src="{{ MEDIA_URL }}img/head-menu-queue.png" alt="" /> {% trans "Queue" %}</a>
</li>
<li>
    <a href="/collector/" title=""><img src="{{ MEDIA_URL }}img/head-menu-collector.png" alt="" /> {% trans "Collector" %}</a>
</li>
<li>
    <a href="/downloads/" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> {% trans "Downloads" %}</a>
</li>
<li class="right">
    <a href="/logs/"  class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />{% trans "Logs" %}</a>
</li>
<li class="right selected">
    <a href="/settings/"  class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-config.png" alt="" />{% trans "Config" %}</a>
</li>
{% endblock %}

{% block content %}
    
<ul id="toptabs" class="tabs">
    {% for configname, config in conf.iteritems  %}
        <li><a href="#{{configname}}">{{configname}}</a></li>
    {% endfor %}
</ul>

<div id="tabsback">
    <ul id="tabs" class="tabs">
        {% for configname, config in conf.iteritems  %}
            <span id="g_{{configname}}">
				{% ifnotequal configname "Accounts" %}
					{% for skey, section in config.iteritems  %}
					    <li><a href="#{{configname}}{{skey}}">{{section.desc}}</a></li>
					{% endfor %}
				{% else %}
					{% for skey, section in config.iteritems  %}
					    <li><a href="#{{configname}}{{skey}}">{{skey}}</a></li>
					{% endfor %}
				{% endifnotequal %}
            </span>
        {% endfor %}
    </ul>
</div>
<form id="horizontalForm" action="" method="POST">
{% for configname, config in conf.iteritems  %}
	{% ifnotequal configname "Accounts" %}
    {% for skey, section in config.iteritems  %}
        <div class="tabContent" id="{{configname}}{{skey}}">
            <table class="settable">
                {% for okey, option in section.items %}
                    {% ifnotequal okey "desc" %}
                        <tr>
                            <td><label for="{{configname}}|{{skey}}|{{okey}}" style="color:#424242;">{{option.desc}}:</label></td>
                            <td>
                                {% ifequal option.type "bool" %}
                                    <select id="{{skey}}|{{okey}}" name="{{configname}}|{{skey}}|{{okey}}">
                                        <option {% if option.value %} selected="selected" {% endif %}value="True">{% trans "on" %}</option>
                                        <option {% if not option.value %} selected="selected" {% endif %}value="False">{% trans "off" %}</option>
                                    </select>
                                {% else %}
                                    {% if option.type|contains:";" %}
                                        <select id="{{skey}}|{{okey}}" name="{{configname}}|{{skey}}|{{okey}}">
                                            {% for entry in option.list %}
                                                <option {% ifequal option.value entry %} selected="selected" {% endifequal %}>{{entry}}</option>
                                            {% endfor %}
                                        </select>
                                    {% else %}
                                        <input id="{{skey}}|{{okey}}" name="{{configname}}|{{skey}}|{{okey}}" type="text" value="{{option.value}}"/>
                                    {% endif %}
                                {% endifequal %}
                            </td>
                        </tr>
                    {% endifnotequal %}
                {% endfor %}
            </table>
        </div>
    {% endfor %}
	{% else %}
	<!-- Accounts -->	
	{% for plugin, accounts in config.iteritems  %}
        <div class="tabContent" id="{{configname}}{{plugin}}">
            <table class="settable">
                {% for account in accounts %}         
                        <tr>
                            <td><label for="{{configname}}|{{plugin}}|password;{{account.login}}" style="color:#424242;">{{account.login}}:</label></td>
                            <td>
							<input id="{{plugin}}|delete;{{account.login}}" name="{{configname}}|{{plugin}}|password;{{account.login}}" type="password" value="{{account.password}}"/>
                            </td>
							<td>
							{% trans "Delete? " %}
							<input id="{{plugin}}|delete;{{account.login}}" name="{{configname}}|{{plugin}}|delete;{{account.login}}" type="checkbox" value="True"/>

							</td>
                        </tr>
												
                {% endfor %}
				<tr><td>&nbsp;</td></tr>
				
				<tr>
					<td><label for="{{configname}}|{{plugin}}|{{account.login}}" style="color:#424242;">{% trans "New account:" %}</label></td>
                            
					<td>
						<input id="{{plugin}}|newacc" name="{{configname}}|{{plugin}}|newacc" type="text"/>
					</td>
				</tr>
				<tr>
					<td><label for="{{configname}}|{{plugin}}|{{account.name}}" style="color:#424242;">{% trans "New password:" %}</label></td>
                            
					<td>
						<input id="{{config}}|{{plugin}}" name="{{configname}}|{{plugin}}|newpw" type="password"/>
					</td>
				</tr>	
				
            </table>
        </div>
    {% endfor %}
	
	{% endifnotequal %}
{% endfor %}
{% if conf %}
<input class="submit" type="submit" value="{% trans "Submit" %}" />
</form>

<br>
{% for message in errors %}
<b>{{message}}</b><br>
{% endfor %}

{% endif %}

{% endblock %}