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

{% load i18n mptt_tags %}

{% block extrahead %}{{ block.super }}
<script type="text/javascript" src="../../jsi18n/"></script>

{% if FEINCMS_ADMIN_MEDIA_HOTLINKING %}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
{% else %}
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}ui/jqueryui-custom-1.7.2.min.js"></script>
{% endif %}
<link rel="stylesheet" type="text/css" href="{{ FEINCMS_ADMIN_MEDIA }}ui/jqueryui-custom-1.7.2.css" />

<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery.alerts.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery.json-1.3.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery.simple.tree.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery.contextmenu.r2.js"></script>

{% include "admin/feincms/_messages_js.html" %}

<link rel="stylesheet" type="text/css" href="{{ FEINCMS_ADMIN_MEDIA }}style.css" />
<link rel="stylesheet" type="text/css" href="{{ FEINCMS_ADMIN_MEDIA }}jquery.simple.tree.css" />
<style type="text/css">
#container { min-width: 0px; }
#content.colM { width: auto; }
#user-tools { display: none; }
{% if inactive_nodes %}{{ inactive_nodes }} { color: #888; }{% endif %}
</style>
<script type="text/javascript">
function frame_goto(location) {
    top.frames.frame_content.location.assign(top.location.pathname+location);
}
function close_tree() {
    if(top.frames.frame_content.location.href.indexOf(top.location.href)!=-1) {
        alert("{% trans "Cannot remove this frame while inside this admin section." %}");
        return false;
    }
    top.location.assign(top.frames.frame_content.location);
    return false;
}

var simpleTreeCollection;
$(document).ready(function(){
    simpleTreeCollection = $('.simpleTree').simpleTree({
        drag: {{ FEINCMS_ADMIN_TREE_DRAG_AND_DROP|yesno:"true,false" }},
        autoclose: false,
        afterClick:function(node){
            frame_goto(node.attr('id').substr(4)+'/');
        },
        afterDblClick:function(node){
            //alert("text-"+$('span:first',node).text());
        },
        afterMove:function(destination, source, pos){
            $.post('.', {
                '__cmd': 'move_node',
                'destination': destination.attr('id').substr(4),
                'source': source.attr('id').substr(4),
                'position': pos
            }, function(data) {
                alert(data);
            });
        },
        afterAjax:function()
        {
            //alert('Loaded');
        },
        animate:true,
        docToFolderConvert:true,
        imagesBasePath: '{{ FEINCMS_ADMIN_MEDIA }}images/'
    });

    $('.simpleTree .root span').contextMenu('myMenu1', {
        bindings: {
            'add': function(trigger) { frame_goto('add/'); },
            'reload': function(trigger) { window.location.reload(); }
        }
    });
    $('.simpleTree ul li span').contextMenu('myMenu2', {
        bindings: {
            'edit': function(trigger) { frame_goto(trigger.parentNode.id.substr(4)+'/'); },
            'delete': function(trigger) { frame_goto(trigger.parentNode.id.substr(4)+'/delete/'); }
        }
    });
});
</script>
{% endblock %}

{% block branding %}
    <div style="float:right;padding:3px 10px 0 0;cursor:pointer;" onclick="return close_tree()">{% trans "remove" %}</div>
    <h1 id="site-name">&nbsp;</h1>
{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
  {{ opts.verbose_name_plural|capfirst }}
</div>
{% endblock %}

{% block content %}

<div class="contextMenu" id="myMenu1">
    <ul>
        <li id="add"><img src="{{ FEINCMS_ADMIN_MEDIA }}images/folder_add.png" /> {% blocktrans with opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</li>
        <li id="reload"><img src="{{ FEINCMS_ADMIN_MEDIA }}images/arrow_refresh.png" /> {% trans "Reload" %}</li>
        {% comment %}
        <li id="edit"><img src="{{ FEINCMS_ADMIN_MEDIA }}images/folder_edit.png" /> {% trans "Edit" %}</li>
        <li id="delete"><img src="{{ FEINCMS_ADMIN_MEDIA }}images/folder_delete.png" /> {% trans "Delete" %}</li>
        {% endcomment %}
    </ul>
</div>
<div class="contextMenu" id="myMenu2">
    <ul>
        <li id="edit"><img src="{{ FEINCMS_ADMIN_MEDIA }}images/page_edit.png" /> {% trans "Edit" %}</li>
        <li id="delete"><img src="{{ FEINCMS_ADMIN_MEDIA }}images/page_delete.png" /> {% trans "Delete" %}</li>
    </ul>
</div>

<ul class="simpleTree">
<li class="root" id="item0"><span>{{ opts.verbose_name_plural|capfirst }}</span>
{% if full_object_list %}
    {% for item, structure in object_list|tree_info %}
        {% if structure.new_level %}<ul>{% else %}</li>{% endif %}
        <li id="item{{ item.id }}">
        <span>{{ item }}</span>
        {% for level in structure.closed_levels %}</li></ul>{% endfor %}
    {% endfor %}
{% else %}
    <ul>
    {% include "admin/feincms/splitpane_editor_tree_subtree.html" %}
    </ul>
{% endif %}
</li>
</ul>

{% endblock %}
