{% extends "admin/base_site.html" %}
{% load i18n admin_static admin_modify suit_tags admin_urls %}
{% load url from future %}

{% block extrahead %}{{ block.super }}
  {% url 'admin:jsi18n' as jsi18nurl %}
  <script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>

  {{ media }}

{% endblock %}


{% block extrajs %}
  {{ block.super }}

  {% if 'CONFIRM_UNSAVED_CHANGES'|suit_conf %}
    <!-- Warn on leaving unsaved form -->
    <script src="{% static 'suit/js/suit-form-confirm.js' %}"></script>
    <script type="text/javascript">
      confirmExitIfModified('{{ opts.module_name }}_form', '{% trans 'You have unsaved changes' %}.');
    </script>
  {% endif %}

  {% if adminform.model_admin.suit_form_tabs %}
    <script type="text/javascript">
    (function ($) {
      $(function () {
        $('#suit_form_tabs').suit_form_tabs();
      });
    }(Suit.$))
    </script>
  {% endif %}

  <script>
    (function ($) {
      $(function () {
        $("#{{ opts.module_name }}_form").suit_form_debounce();
      });
    }(Suit.$))
  </script>

{% endblock %}

{% block extrastyle %}
  {{ block.super }}
{% endblock %}

{% block content_title_value %}
  {% trans 'Add' %} {{ opts.verbose_name }}
{% endblock %}

{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}

{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}

{% if not is_popup %}
  {% block breadcrumbs %}
    <ul class="breadcrumb">
      <li>
        <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
        <span class="divider">&raquo;</span>
      </li>
      <li>
        <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{% firstof opts.app_config.verbose_name app_label|capfirst|escape %}</a>
        <span class="divider">&raquo;</span>
      </li>
      <li>
        {% if has_change_permission %}
          <a href="{% url opts|admin_urlname:'changelist' %}">
            {{ opts.verbose_name_plural|capfirst }}</a>{% else %}
          {{ opts.verbose_name_plural|capfirst }}{% endif %}
        <span class="divider">&raquo;</span>
      </li>
      <li class="active">
        {% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
      </li>
    </ul>
  {% endblock %}
{% endif %}

{% block content %}
  <div id="content-main" class="inner-two-columns">

    <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post"
          id="{{ opts.module_name }}_form" class="form-horizontal">

      <div class="inner-right-column">

        <div class="box save-box">

          {% block submit_buttons_bottom %}{% submit_row %}{% endblock %}

        </div>

        {% block object-tools %}
          {% if change %}{% if not is_popup %}
            <h4 class="italic-title">{% trans 'tools'|capfirst %}</h4>
            <ul class="box menu-box">
              {% block object-tools-items %}
                <li><a href="history/" class="historylink"><i
                    class="icon-time icon-alpha75"></i>{% trans "History" %}</a>
                </li>
                {% if has_absolute_url %}
                  <li>
                    <a href="{{ original.get_absolute_url }}" class="viewsitelink"><i class="icon-eye-open icon-alpha75"></i>{% trans "View on site" %}</a>
                  </li>
                {% endif %}

                {% if has_add_permission %}
                  <li>
                    <a href="../add/"><i class="icon-plus-sign icon-alpha75"></i>{% blocktrans with opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
                    </a></li>
                  {# {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a>#}
                {% endif %}

              {% endblock %}
            </ul>
          {% endif %}{% endif %}

            {% if has_absolute_url %}
                <h4 class="italic-title">Share</h4>
                <ul class="box menu-box social-sharing-box">
                    <li>
                        <a target="_blank" href="https://www.facebook.com/sharer.php?u={% if request.is_secure %}https{% else %}http{% endif %}%3A%2F%2F{{ request.META.HTTP_HOST }}{{ original.get_absolute_url|urlencode }}">
                            Facebook
                        </a>
                    </li>

                    <li>
                        <a target="_blank" href="https://twitter.com/share?url={% if request.is_secure %}https{% else %}http{% endif %}%3A%2F%2F{{ request.META.HTTP_HOST }}{{ original.get_absolute_url|urlencode }}&amp;text={{ original.title|urlencode }}">
                            Twitter
                        </a>
                    </li>

                    <li>
                        <a target="_blank" href="https://www.linkedin.com/shareArticle?url={% if request.is_secure %}https{% else %}http{% endif %}%3A%2F%2F{{ request.META.HTTP_HOST }}{{ original.get_absolute_url|urlencode }}&amp;title={{ original.title|urlencode }} ">
                            LinkedIn
                        </a>
                    </li>
                </ul>
                <script>
                jQuery('.social-sharing-box li a').each(function() {
                    var $ = jQuery;
                    $(this).click(function(ev) {
                        ev.preventDefault();
                        var url = $(this).attr('href');
                        window.open(url, '_blank', 'height=400,width=600,menubar=no,status=no,toolbar=no');
                    })
                });
                </script>
            {% endif %}

        {% endblock %}

      {% block sidebar %}{% endblock %}

      </div>
      <div class="inner-center-column">

          {% if language_pages %}

              <ul id="suit_form_tabs" class="nav nav-tabs nav-tabs-suit" data-tab-prefix="suit-tab">
                  {% for page in language_pages %}
                      <li class="{% if original == page %}active{% endif %}">
                          <a href="/admin/pages/page/{{ page.pk }}">
                              {% if page.is_content_object == False %}
                                  Default
                              {% else %}
                                  {{ page.country_group }}
                              {% endif %}
                          </a>
                      </li>
                  {% endfor %}
                  <li class="{% if original == page %}active{% endif %}">
                      <a href="/admin/pages/page/{% if original.is_content_object %}{{ original.owner.pk }}{% else %}{{ original.pk }}{% endif %}/duplicate">Add</a>
                  </li>
              </ul>

          {% endif %}

        {% csrf_token %}{% block form_top %}{% endblock %}
        {% block suit_form_tabs %}
          {% if adminform.model_admin.suit_form_tabs %}
            <ul id="suit_form_tabs" class="nav nav-tabs nav-tabs-suit" data-tab-prefix="suit-tab">
              {% for tab in adminform.model_admin.suit_form_tabs %}
                <li><a href="#{{ tab.0 }}">{{ tab.1 }}</a></li>{% endfor %}
            </ul>
          {% endif %}
        {% endblock %}
        <div class="tab-content tab-content-main">
          {% if is_popup %}
            <input type="hidden" name="_popup" value="1"/>{% endif %}
          {% if errors %}
            <div class="alert alert-error">
              {% blocktrans count counter=errors|length %}Please correct the error below.{% plural %} Please correct the errors below.{% endblocktrans %}
              {{ adminform.form.non_field_errors }}
            </div>
          {% endif %}

          {# render suit_form_includes at top position #}
          {% include 'suit/includes/change_form_includes.html' with position='top' %}

          {% block field_sets %}
            {% for fieldset in adminform %}
              {% include "admin/includes/fieldset.html" %}
            {% endfor %}
          {% endblock %}

          {% block after_field_sets %}{% endblock %}

          {# render suit_form_includes at middle position #}
          {% include 'suit/includes/change_form_includes.html' with position='middle' %}

          {% block inline_field_sets %}
            {% for inline_admin_formset in inline_admin_formsets %}
              {% include inline_admin_formset.opts.template %}
            {% endfor %}
          {% endblock %}

        </div>

        {% block after_related_objects %}{% endblock %}

        {# render suit_form_includes at last position #}
        {% include 'suit/includes/change_form_includes.html' with position='bottom' %}

        {% if adminform and add %}
          <script type="text/javascript">
            (function ($) {
              $('form#{{ opts.module_name }}_form :input[type!=button][type!=submit]:visible:enabled:first').focus();
            })(django.jQuery);
          </script>
        {% endif %}

        {# JavaScript for prepopulated fields #}
        {% prepopulated_fields_js %}

      </div>
    </form>
  </div>
{% endblock %}

{# Empty centered sidebar as now we use sidebar in content block#}
{% block sidebar_content %}{% endblock %}
