{% extends "admin/change_list.html" %}
{% load adminmedia admin_list i18n %}

{% block extrahead %}
{{ block.super }}

<style type="text/css">
    .page_marker { display:block; text-align: right; float: left; padding: 1px 2px 0 0; }
    tr.cut { border: 2px dashed black; opacity: 0.5; }
</style>

<script type="text/javascript">
    /* This represents the current state of the page tree. Would need to be
       refreshed if pages are moved or deleted, but for now that is not possible */
    var tree_structure = {{ tree_structure|default:"{}" }};

    /* After loading the page, show all root nodes */
    $(function()
        {
        {% if is_popup %}
        // resize window a bit, the default size is too small for the tree column
        window.resizeTo(Math.min(window.outerWidth+300, screen.availWidth), window.outerHeight);
        {% endif %}

        $('table').hide(); /* hide table until set up */
        $('a.paste_target').hide();

        expand_sym = '&#9658;'; //'<img alt="+" src="{{ EDITOR_MEDIA_PATH }}img/disclosure-right.png">';
        collapse_sym = '&#9660;'; //'<img alt="-" src="{{ EDITOR_MEDIA_PATH }}img/disclosure-down.png">';

        tree_structure_clean(); /* reduce structure to actually present items */

        root_items = [];
        for(k in tree_structure)
            {
            p = page(k);
            if(p.ptr)
                {
                p.row.hide(); /* default hide */
                /* Note all root (ie. has no parent) nodes */
                if(!p.parent)
                    root_items.push(p);
                }
            }

        for(i in root_items)
            {
            p = root_items[i];
            p.row.show();
            if(p.open)
                open_subtree(p.id);
            }

        /* yuck :-) */
        $('table thead tr th:eq(1)').attr('style', 'width: 450px;');

        $('tbody tr').removeClass('row1').removeClass('row2');
        $('table').show();
        recolor_lines();
        });

    var cut_item_pk = null;
    function cut_item(pk, elem) {
        var row = $(elem.parentNode.parentNode);

        if(row.hasClass('cut')) {
            cut_item_pk = null;
            $('a.paste_target').hide();
            row.removeClass('cut');
        } else {
            cut_item_pk = pk;
            $('a.paste_target').show();
            $('tr').removeClass('cut');
            row.addClass('cut').find('a.paste_target').hide();
        }

        return false;
    }

    function paste_item(pk, position) {
        if(!cut_item_pk)
            return false;

        $.post('.', {
            '__cmd': 'move_node',
            'position': position,
            'cut_item': cut_item_pk,
            'pasted_on': pk
        }, function(data) {
            if(data == 'OK')
                window.location.reload();
            else
                alert(data);
        });

        return false;
    }

</script>

{% endblock %}


{% comment %}
      {% block filters %}
        {% if cl.has_filters %}
          <div id="changelist-filter">
            <h2>{% trans 'Filter' %}</h2>
            {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}

	<h3>Links</h3>
	<li class="selected"><a href="#">Dings</a> </li>
          </div>
        {% endif %}

      {% endblock %}
{% endcomment %}
