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

{% block title %}{{ section.title }}{% endblock %}
{% block javascript %}
<script type="text/javascript">
        var csrf = "{{ csrf_token }}";
        var install = function(name,url,sha) {
            $.ajax({type:'POST', url:'/api/v1/plugin/'+name+'/install/', async:true,
                data:{
                    csrfmiddlewaretoken:csrf
                },
                success: function(data, status, xhr) {
                }
            });
        };
        var uninstall = function(id) {
            $.ajax({type:'GET', url:'/api/v1/plugin/'+id+'/uninstall/', async:true
            });
        };
        var enable = function(id) {
            $.ajax({type:'GET', url:'/api/v1/plugin/'+id+'/enable/', async:true
            });
        };
        var disable = function(id) {
            $.ajax({type:'GET', url:'/api/v1/plugin/'+id+'/disable/', async:true
            });
        };
    </script>
{% endblock %}

{% block content %}
<div class=span12>
    {% for plugin in Plugins %}
        <ul>
            <li><h2>{{ plugin.name }}</h2></li>
            <li>{{ plugin.author }}</li>
            <li>{{ plugin.version }}</li>
            <ul>
                {% for lang in plugin.lang %}
                    <li>{{ lang }}</li>
                {% endfor %}
            </ul>
            <li>{{ plugin.description_fr }}</li>
            <li>{{ plugin.description_ru }}</li>
            <li>{{ plugin.description_en }}</li>
            {{ plugin }}
            <li id="action">
                {% if plugin.enabled == True %}
                    <a href="#" onclick="disable('{{ plugin.id }}');" class="button" id="button-disable">
                        <span class="disable">Disable</span>
                    </a>
                {% elif plugin.installed == True %}
                    <a href="#" onclick="enable('{{ plugin.id }}');" class="button"id="button-enable">
                        <span class="enable">Enable</span>
                    </a>
                    <a href="#" onclick="uninstall('{{ plugin.id }}');" class="button" id="button-remove">
                        <span class="remove">Remove</span>
                    </a>
                {% else %}
                    <a href="#" onclick="install('{{ plugin.name }}','{{ plugin.url }}','{{ plugin.sha }}');" class="button" id="button-install">
                        <span class="install">Install</span>
                    </a>
                {% endif %}
                {% if plugin.upgrade %}
                    <a href="#" class="button" id="button-upgrade">
                        <span class="upgrade">Upgrade</span>
                    </a>
                {% endif %}
            </li>
        </ul>
    {% endfor %}
</div>
{% endblock %}
