{% extends "admin/change_list.html" %}
{% block extrahead %}
    {{block.super}}
    <script type="text/javascript">
    (function($) {
        $(document).ready(function()  {
            var srchString = document.getElementById('searchbar').value;
            if (srchString == '')
                treeTable = $("#result_list").treeTable({initialState : "{{ EDITOR_TREE_INITIAL_STATE }}"});
            else
                treeTable = $("#result_list").treeTable({initialState : "expanded"});
        function toggleChildren(index, value) {
            var row = value.parentNode.parentNode;
            if (row.className.match(/child-of-node-\d+/)) {
                value.checked = /child-of-node-(\d+)/.exec(row.className);
            }
            if($(row).hasClass("parent")) {
                $("table.treeTable tbody tr.child-of-" + row.id + " input").each(toggleChildren);
            }
            $("tr input.action-select").actions();
        };
        $('.action-select').each(
            function(){
                $(this).bind('click', function(event){
                    // Get the tr from checkbox -> td -> tr
                    var row = event.currentTarget.parentNode.parentNode;
                    $("table.treeTable tbody tr.child-of-" + row.id + " input").each(toggleChildren);
                });
            });
        });
    })(django.jQuery);
    </script>
{% endblock %}
{% block result_list %}
    {% load admin_list i18n admin_tree_list_tags %}
    {% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %}
    {% result_tree_list cl %}
    {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %}
{% endblock %}