{% load i18n %}

<table class="table table-hover orderable activities-table">{% csrf_token %}
    <thead>
        <tr>
            {% if training and training.is_editable %}
                <th></th>
            {% endif %}
            <th class="col-md-1"></th>
            <th class="col-md-2">
                {% trans 'Type' %}
            </th>
            {% if current_sub_section == "public_library" %}
                <th class="col-md-6">
                    {% trans 'Title' %}
                </th>
                <th class="col-md-3">{% trans 'Author' %}</th>
            {% else %}
                <th class="col-md-8">
                    {% trans 'Title' %}
                </th>
            {% endif %}
            {% if training and training.is_editable %}
                <th class="text-right"><span class="orderable-message-holder"></span></th>
            {% endif %}
        </tr>
    </thead>
    <tbody>
        {% for activity in trainingactivity_list %}
            <tr class="activity-row" data-href="{{ activity.get_absolute_url }}">
                {% if training and training.is_editable %}
                    <td>
                        {{ activity.sort_order_display|safe }}
                    </td>
                {% endif %}
                <td class="activity-actions">
                    {% include "trainings/trainingactivity_actions.html" %}
                </td>
                <td>
                    <i class="icon-{{ activity.activity_type }} activity-type-icon"></i>
                    {{ activity.verbose_activity_name }}
                </td>
                <td {% if training %}colspan="2"{% endif %}>
                    <strong>
                        {{ activity.name }}
                    </strong>
                </td>
                {% if current_sub_section == "public_library" %}
                    <td>{{ activity.library_status.owner.get_full_name }}</td>
                {% endif %}
            </tr>
        {% endfor %}
    </tbody>
</table>
<script type="text/javascript">
    $(document).ready(function(){
        var $activitiesTable = $('.activities-table');
        $activitiesTable.find('tbody tr').css({cursor: 'pointer'});
        $activitiesTable.on('click', 'tbody tr', function(e){
            if ($('.activity-actions').has(e.target).length == 0) {
                window.location = $(this).data('href');
            }
        });
        $(".activity-actions .dropdown").on("show.bs.dropdown", function() {
            var $btnDropDown = $(this).find(".dropdown-toggle"),
                $listHolder = $(this).find(".dropdown-menu");
            //reset position property for DD container
            $(this).css("position", "static");
            $listHolder.css({
                "top": ($btnDropDown.position().top + $btnDropDown.outerHeight(true)) + "px",
                "left": $btnDropDown.position().left + "px"
            });
            $listHolder.data("open", true);
        });
        //add BT DD hide event
        $(".activity-actions .dropdown").on("hidden.bs.dropdown", function() {
            var $listHolder = $(this).find(".dropdown-menu");
            $listHolder.data("open", false);
        });
    });
</script>
