{% extends "base.html" %}
{% load i18n %}
{% block local_css %}
<link rel="stylesheet" href="{% url twistranet_home %}static/css/tn_menu_builder.css" type="text/css" media="screen" />
{% endblock %}
{% block local_js %}
<script type="text/javascript" src="{% url twistranet_home %}static/js/tn_menu_builder.js" charset="utf-8"></script>
{% endblock %}
{% block content %}
  <div id="menu-builder">
    <div id="menu-management">
      {% comment%}
      <!-- Uncomment in future to work on multiple menus edition -->
      <div class="nav-tabs-nav">
        <div class="nav-tabs-arrow nav-tabs-arrow-left" style="display: none;"><a>&laquo;</a></div>
        <div class="nav-tabs-wrapper">
          {% for menu in topmenus %}
            <span class="nav-tab nav-tab-active">{{ menu.label }}</span>
          {% endfor %}
          <a class="nav-tab menu-add-new"
             href="{% url menu_create %}">
             <abbr title="Add a menu">+</abbr>
          </a>
        </div>
        <div class="nav-tabs-arrow nav-tabs-arrow-right" style="display: none;"><a>&raquo;</a></div>
      </div>
      {% endcomment%}
      <div id="menu_edit_left">
        <div id="add-custom-links" class="postbox ">
          <h3>{% trans 'Add custom link' %}</h3>
          <div class="inside">
            <form action="{{ path }}" 
                  method="post">
              {% for field in links_form %}
                  {% if not field.is_hidden %}
                      <div class="fieldWrapper">
                          {{ field.errors }}
                          {{ field.label_tag }} {{ field }}
                          {% if field.help_text %}
                              <span class="hint">{{ field.help_text }}
                                  <span class="hint-pointer">&nbsp;</span>
                              </span>
                          {% endif %}
                          <div class="clear"><!-- --></div>
                      </div>
                  {% else %}
                      {{ field }}
                  {% endif %}
              {% endfor %}
              <div class="postboxcontrol">
                <input type="submit" name="submit" value="{% trans 'Add to menu' %}" />
              </div>
            </form>
          </div>
        </div>
        <div id="add-view" class="postbox ">
          <h3>{% trans 'Add internal view' %}</h3>
          <div class="inside">
            <form action="{{ path }}"
                  method="post">
              {% for field in view_form %}
                  {% if not field.is_hidden %}
                      <div class="fieldWrapper">
                          {{ field.errors }}
                          {{ field.label_tag }} {{ field }}
                          {% if field.help_text %}
                              <span class="hint">{{ field.help_text }}
                                  <span class="hint-pointer">&nbsp;</span>
                              </span>
                          {% endif %}
                          <div class="clear"><!-- --></div>
                      </div>
                  {% else %}
                      {{ field }}
                  {% endif %}
              {% endfor %}
              <div class="postboxcontrol">
                <input type="submit" name="submit" value="{% trans 'Add to menu' %}" />
              </div>
            </form>
          </div>
        </div>
        <div id="add-community" class="postbox ">
          <h3>{% trans 'Add community' %}</h3>
          <div class="inside">
            <div id="community-list">
              {% comment%}
              <form id="community-search_form"
                    method="GET">
                <input
                    type="text"
                    autocomplete='off'
                    class="textfield"
                    value=""
                    name="q"
                    id="search-text" />
                <input
                    type="hidden"
                    value="twistapp.community"
                    name="models" />
              </form>
              {% endcomment%}
              {% for community in communities %}
                <div id="content-target-{{community.id}}" class="content-target">
                  <form id="content-item-form-{{community.id}}" class="content-item-form">
                    <input type="hidden" value="{{community.id}}" name="target_id">
                    <input type="hidden" value="{{community.title}}" name="label">
                  </form>
                  <a href="{{community.get_absolute_url}}">{{community.title}}</a>
                </div>
              {% endfor %}
            </div>
            <div id="content-item-model-form">
              {% comment %} The visible fields only for content form edition {% endcomment %}
              {% for field in content_form %}
                {% if not field.is_hidden %}
                    <div class="fieldWrapper">
                        {{ field.errors }}
                        {{ field.label_tag }} {{ field }}
                        {% if field.help_text %}
                            <span class="hint">{{ field.help_text }}
                                <span class="hint-pointer">&nbsp;</span>
                            </span>
                        {% endif %}
                        <div class="clear"><!-- --></div>
                    </div>
                {% endif %}
              {% endfor %}
            </div>
          </div>
        </div>
      </div>
      <div id="menu_edit_main">
        <form action="{{ path }}" 
              method="post"
              id="menu-edit-form"
              class="edit-form enableAutoFocus enableUnloadProtect">
            <fieldset>
            {% autoescape off %}
              {{ mainmenu }}
            {% endautoescape %}
            <ul id="menu-to-delete">
            </ul>
            <input type="hidden" id="menu-id" name="menu-id" value="{{menu.id}}" />
            {% csrf_token %}
            <div class="form-controls">
              <input type="submit" value="{% trans 'Save' %}" /> 
              <button type="button" class="reset">{% trans 'Undo' %}</button>
              <input type="hidden" id="referer_url" value="{{referer_url}}" name="referer_url" />
            </div>
            </fieldset>
        </form>
        <div id="item-model">
            {% autoescape off %}
              {{ item_model }}
            {% endautoescape %}
        </div>
      </div>
    </div>
  </div>
{% endblock %}
