{% load i18n %}
{% load lfc_tags %}

{% ifhasperm edit %}
    {% if parent_for_portlets %}
        <form class="portlets-form"
              action="{% url lfc_update_portlets object_type_id, obj.id %}"
              method="post">
            <h2>{% trans 'Blocked parent slots' %}</h2>

            <table class="lfs-manage-table half">
                <th class="tiny padr">
                    {% trans "Blocked" %}
                </th>
                <th>
                    {% trans "Slot" %}
                </th>
                {% for slot in slots.items %}
                    <tr>
                        <td>
                            <input type="checkbox"
                                   name="block_slot"
                                   value="{{ slot.id }}"
                                   {% if slot.is_blocked %}checked="checked"{% endif %} />
                        </td>
                        <td>
                            {{ slot.name }}
                        </td>
                    </tr>
                {% endfor %}
            </table>
            <div class="padding-b">
                <input type="submit"
                       class="ajax-save-button"
                       value="{% trans 'Save blocked parent slots' %}" />
            </div>

        </form>
    {% endif %}

    <h2 class="first-heading">{% trans 'Slots' %}</h2>

    {% for slot in slots.items %}
        <h3 {% if forloop.first %}class="first-heading"{% endif %}>
            {% trans 'Slot' %}: {{ slot.name }}
        </h3>

        {% if slot.portlets %}

            <table class="lfs-manage-table half">
                <tr>
                    <th class="middle">
                        {% trans 'Type' %}
                    </th>
                    <th>
                        {% trans 'Title' %}
                    </th>
                    <th class="tiny right-padding">
                        {% trans 'Manage' %}
                    </th>
                </tr>
                {% for portlet in slot.portlets %}
                    <tr>
                        <td>
                            <a class="portlet-edit-button"
                               href="{% url lfc_edit_portlet portlet.pa_id %}">
                                {{ portlet.type }}
                            </a>
                        </td>
                        <td>
                            <a class="portlet-edit-button"
                               href="{% url lfc_edit_portlet portlet.pa_id %}">
                                {{ portlet.title }}
                            </a>
                        </td>
                        <td class="right">
                            <a class="edit portlet-edit-button"
                               title='{% trans "Edit" %}'
                               href="{% url lfc_edit_portlet portlet.pa_id %}"></a>

                            <a class="delete delete-link"
                               title='{% trans "Delete" %}'
                               href="{% url lfc_delete_portlet portlet.pa_id %}"></a>
                        </td>
                    </tr>
                {% endfor %}
            </table>
        {% else %}
            <p class="no-portlets">{% trans 'There are no portlets assigend' %}</p>
        {% endif %}
    {% endfor %}


    <h2 class="middle-heading">
        {% trans 'Add new portlet' %}
    </h2>

    <form class="portlet-add-form"
          action="{% url lfc_add_portlet object_type_id, obj.id %}"
          method="get">
        <select name="portlet_type">
            {% for portlet_type in portlet_types %}
                <option value="{{ portlet_type.type }}">
                    {{ portlet_type.name }}
                </option>
            {% endfor %}
        </select>

        <input class="portlet-add-button"
               type="submit"
               value="{% trans 'Add portlet' %}" />
    </form>
{% else %}
    {% if parent_for_portlets %}
        <h2>{% trans 'Blocked parent slots' %}</h2>
        <table class="lfs-manage-table half">
            <th class="small">
                {% trans "Slot" %}
            </th>
            <th>
                {% trans "Blocked" %}
            </th>
        {% for slot in slots.items %}
            <tr>
                <td>
                    {{ slot.name }}
                </td>
                <td>
                    {% if slot.is_blocked %}
                        {% trans "Yes" %}
                    {% else %}
                        {% trans "No" %}
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
        </table>
    {% endif %}

    <h2 class="middle-heading">{% trans 'Slots' %}</h2>

    {% for slot in slots.items %}
        <h3 {% if forloop.first %}class="first-heading"{% endif %}>
            {% trans 'Slot' %}: {{ slot.name }}
        </h3>

        {% if slot.portlets %}

            <table class="lfs-manage-table half">
                <tr>
                    <th class="middle">
                        {% trans 'Type' %}
                    </th>
                    <th class="middle">
                        {% trans 'Title' %}
                    </th>
                </tr>
                {% for portlet in slot.portlets %}
                    <tr>
                        <td>
                            {{ portlet.type }}
                        </td>
                        <td>
                            {{ portlet.title }}
                        </td>
                    </tr>
                {% endfor %}
            </table>
        {% else %}
            <p class="no-portlets">{% trans 'There are no portlets assigend' %}</p>
        {% endif %}
    {% endfor %}
{% endifhasperm %}

