<script type="text/JavaScript">
    function rename_dialog(id, name, lang) {
        $('#rename_menuitem_translation_id').val(id);
        $('#rename_menuitem_translation_name').val(name);
        $('#relang_menuitem_translation_lang').val(lang);
        $('#rename_menuitem_translation_dialog').dialog('open');
    }

    function toggle_requires_login(id) {
        $.ajax({
            url: "/yacon/nexus/control/toggle_menuitem_requires_login/" + id 
                + "/",
            dataType: "json",
            success: function(data) {
                refresh_tree();
            }
        });

    }

    function toggle_requires_admin(id) {
        $.ajax({
            url: "/yacon/nexus/control/toggle_menuitem_requires_admin/" + id 
                + "/",
            dataType: "json",
            success: function(data) {
                refresh_tree();
            }
        });

    }

    $(document).ready(function(){
        $('#menuitem_toolbar').show();

        {% if menuitem.has_missing_translations %}
            $('#add_menuitem_translation').show();
        {% else %}
            $('#add_menuitem_translation').hide();
        {% endif %}

        {% if menuitem.can_move_out %}
            $('#menuitem_move_out').show();
        {% else %}
            $('#menuitem_move_out').hide();
        {% endif %}

        {% if menuitem.can_move_up %}
            $('#menuitem_move_up').show();
        {% else %}
            $('#menuitem_move_up').hide();
        {% endif %}

        {% if menuitem.can_move_down %}
            $('#menuitem_move_down').show();
        {% else %}
            $('#menuitem_move_down').hide();
        {% endif %}
    });
</script>

<div class="node" id="{{menuitem.id}}">
    <h2> MenuItem Info for: {{menu.name|safe}} </h2>

    <h2> MenuItem{% if default_translation %}: {{translation.name}}{% endif %} 
    (id={{menuitem.id}})
    </h2>

    <ul>
        <li>
            Created: {{menuitem.created}}
        </li>
        <li>
            Last Updated: {{menuitem.updated}}
        </li>
        <li>
            MenuItem ID: {{menuitem.id}}
        </li>
        <li>
            Owning Menu: {{menuitem.menu.name}} (id={{menuitem.menu.id}})
        </li>
        <li>
            MetaPage: 
            {% if menuitem.metapage %}
                {{menuitem.metapage.default_title}}&nbsp; 
                (id={{menuitem.metapage.id}})
            {% else %}
                <i>None</i>
            {% endif %}
        </li>
        <li>
            Link: 
            {% if menuitem.link %}
                {{menuitem.link}}
            {% else %}
                <i>None</i>
            {% endif %}
        </li>
        <li>
            Requires Login: {{menuitem.requires_login}} 
            <a href="javascript:void(0);" 
                onclick="toggle_requires_login({{menuitem.id}})">
                (toggle)</a>
        </li>
        <li>
            Requires Admin: {{menuitem.requires_admin}} 
            <a href="javascript:void(0);" 
                onclick="toggle_requires_admin({{menuitem.id}})">
                (toggle)</a>
        </li>
    </ul>

    <h3>Contents</h3>

    <ul>
        <li> 
            {% if default_translation %}
                "{{default_translation.name}}" 
                    ({{default_translation.language.code}})
                {% if default_translation.menuitem.metapage %}
                  {% if default_translation.page.uri %}
                      <a href="{{default_translation.page.uri}}">(view)</a>
                      &nbsp;
                      <a href="javascript:void(0);"
      onclick="remove_menuitem_translation({{default_translation.id}}, '{{default_translation.name|escapejs}}')">
                          (delete)&nbsp;</a>
                  {% else %}
                      (<i>unreachable</i>)&nbsp;
                  {% endif %}
                {% endif %}
            {% else %}
                    <i>No Default Translation 
                        ({{menuitem.menu.site.default_language.code}})</i>
            {% endif %}
            <a href="javascript:void(0);"
onclick="rename_dialog({{default_translation.id|default:"''"}}, '{{default_translation.name|escapejs}}', '{{menuitem.menu.site.default_language.code|escapejs}}')">
                (rename)</a>
        </li>
        {% for item in translated_items %}
            <li> 
                "{{item.name}}" ({{item.language.code}})
                {% if item.menuitem.metapage %}
                  {% if item.page.uri %}
                      <a href="{{item.page.uri}}">(view)</a>&nbsp;
                      <a href="javascript:void(0);"
  onclick="remove_menuitem_translation({{item.id}}, '{{item.name|escapejs}}')">
                          (delete)</a>
                  {% else %}
                      (<i>unreachable</i>)
                  {% endif %}
                {% endif %}
                <a href="javascript:void(0);"
                onclick="rename_dialog({{item.id|default:"''"}}, '{{item.name|escapejs}}', '{{item.language.code|escapejs}}')">
                    (rename)</a>
            </li>

        {% empty %}
        {% endfor %}
    </ul>
</div>
