{% extends "admin/change_form.html" %}
{% load i18n admin_modify cms_tags cms_admin %}
{% load url from future %}
{% block title %}{% trans "Change a page" %}{% endblock %}

{% block extrahead %}
{{ block.super }}
<script type="text/javascript" src="{{ STATIC_URL }}cms/js/csrf.js"></script>
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>

{% if not add %}
<script type="text/javascript" src="{{ STATIC_URL }}cms/js/change_form.js"></script>
{% endif %}
<script type="text/javascript" src="{% admin_static_url %}js/urlify.js"></script>

{% if add %}
<script type="text/javascript">
//<![CDATA[

	jQuery(document).ready(function (){
        var title= jQuery('#id_title');
        var slug = jQuery('#id_slug');
        var update = function(){
            var value = title.val();
            if (window.UNIHANDECODER){
                value = UNIHANDECODER.decode(value);
            }
            slug.val(URLify(value, 64));
        };
		title.keyup(update);
        update();
	});

//]]>
</script>
{% endif %}

<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}suit/css/djangocms.css">
<script type="text/javascript" src="{{ STATIC_URL }}suit/js/djangocms.js"></script>
{#{% block jqyery %}{% endblock %}#}
{% endblock %}


{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumb">
  <li><a href="../../../">{% trans "Home" %}</a>
       <span class="divider">&raquo;</span></li>

  <li><a href="../../">{{ app_label|capfirst|escape }}</a>
    <span class="divider">&raquo;</span></li>
    <li>{% if can_change %}<a href="../">{{ 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.get_title|truncatewords:"18" }}{% endif %}</li>
</div>
{% endif %}{% endblock %}

{% block content_title %}

	{% if delete_requested %}
    <div class="alert alert-block alert-error confirm-delete clearfix">
      <div class="pull-right">
        <input type="hidden" name="post" value="yes">

        {% if delete_requested %}<a href="confirm-delete/" class="btn btn-danger">{% trans "Confirm delete" %}</a>{% endif %}
        {% if delete_requested %}<a href="remove-delete-state/" class="btn btn-info">{% trans "Remove delete request" %}</a>{% endif %}

      </div>
      <h4 class="alert-heading">{% trans "Confirm page deletion" %}!</h4>
    </div>
	{% endif %}

{% endblock %}

{% block content %}

<div id="content-main" class="inner-two-columns">

  <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="?language={{ language }}{%if request.GET.target %}&amp;target={{ request.GET.target }}{% endif %}&amp;{%if request.GET.target %}position={{ request.GET.position }}{% endif %}" method="post" id="page_form" class="form-horizontal">{% csrf_token %}{% block form_top %}{% endblock %}
    {{ adminForm.fields.parent }}

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

    <div class="box save-box">
      {% if add %}
        {% submit_row %}
      {% else %}
        {% if not moderation_delete_request %}{% page_submit_row %}{% endif %}
      {% endif %}
    </div>

    {% block object-tools %}
    {% if change %}{% if not is_popup %}
      <h4 class="italic-title">{% trans 'actions'|capfirst %}</h4>
      {% if can_publish or can_change and page.published and page.is_dirty %}
      <ul class="box menu-box">
      {% if can_publish %}
      <li>{% if not delete_requested %}<a href="publish/" class="publishlink"><i class="{% if page.published and page.is_dirty %}icon-ok-sign{% else %}icon-ok{% endif %} icon-alpha75"></i>{% trans "Publish" %} {% trans "draft" %}</a>{% endif %}</li>
      <li><a href="preview/?language={{ language }}" class="previewdraftlink"><i class="icon-eye-open icon-alpha75"></i>{% trans "Preview" %} {% trans "draft" %}</a></li>
      {% endif %}
      {% if can_change and page.published and page.is_dirty %}<li><a href="revert/" class="revertlink"><i class="icon-repeat icon-alpha75"></i>{% trans "Revert to public" %}</a></li>{% endif %}
      </ul>
      {% endif %}
      <ul class="box menu-box">
        {% if page.publisher_public %}<li><a href="preview/?public=1&language={{ language }}"><i class="icon-globe icon-alpha75"></i>{% trans "View on site" %}</a></li>{% endif%}
      <li><a href="history/" class="historylink"><i class="icon-time icon-alpha75"></i>{% trans "History" %}</a></li>
        {% 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 %}
      </ul>
    {% endif %}{% endif %}
    {% endblock %}

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

    <div style="display: none;"><input type="hidden" name="language" value="{{language}}" id="id_language"/></div>

    {% if show_language_tabs %}
      <ul class="nav nav-tabs nav-tabs-suit" data-tab-prefix="tab-content">
        {% for lang_code, lang_name in language_tabs %}
        <li class="{% ifequal lang_code language %}active{% else %}{% if not lang_code in filled_languages %} notfilled{% endif %}{% endifequal %}"><a href="javascript:;" onclick="trigger_lang_button(this,'./?language={{lang_code}}');">{{lang_name}}</a></li>
        {% endfor %}
      </ul>
    {% endif %}


    <div id="lang_tab_content">
    {#{% if show_language_tabs %}#}
    {#<h2 class="header"></h2>#}
    {#{% endif %}#}
    {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
    {% if errors %}
        <p class="errornote">
        {% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
        </p>
        <ul class="errorlist">{% for error in adminform.form.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
    {% endif %}

    {% for fieldset in adminform %}
      {% include "admin/cms/page/includes/fieldset.html" %}
    {% endfor %}


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


    {% if not add %}
      {% if CMS_PERMISSION and can_change_permissions %}
        <div class="inline-group">
          <div class="tabular inline-related">
            <fieldset id="inherited_permissions" class="module aligned collapse">
              <h2>{% trans 'All permissions' %}</h2>
              <div class="loading">{% trans 'Loading...' %}</div>
              <div class="load">./permissions/</div>
            </fieldset>
          </div>
        </div>
      {% endif %}

        <div class="inline-group">
            <div class="tabular inline-related">
                <fieldset id="page_states" class="module aligned collapse">
                  <h2 class="load_remote">{% trans 'Page states' %}</h2>
                  <div class="loading">{% trans 'Loading...' %}</div>
                  <div class="load">./moderation-states/</div>
                </fieldset>
            </div>
        </div>

      {% if delete_requested %}<script type="text/javascript">
      (function namespacing($) {
        $(function(){
          // disable all fields
          function lockControls(){
            $('input,select,textarea').attr("disabled", "disabled");
            $('a[id^=add_],span[class^=add-plugin],a[class^=selector-],p[class^=selector-]').remove();
          }
          $('fieldset[class=collapsed]').remove();
          lockControls();
          setTimeout(lockControls,200);
        });
      })(window.CMS.$);
      </script>{% endif %}

    {% endif %}

    {% block after_related_objects %}{% endblock %}

    {% if add %}
    <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>

    {% endif %}
    {% for url in unihandecode_urls %}
    <script type="text/javascript" src="{{ url }}"></script>
    {% endfor %}
    {% if unihandecode_urls %}
    <script type="text/javascript">
        var UNIHANDECODER = unihandecode.Unihan('{{ unihandecode_lang }}');
    </script>
    {% endif %}

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

    </div>
   </div>
  </form>
</div>

{% endblock %}

{% block extrajs %}
  <script type="text/javascript">
    (function ($) {
      var $menu = $('#left-nav');
      var menu_bottom = $menu.offset().top + $menu.height();
      var $plugin_holder = $('.plugin-holder').first();
      if ($plugin_holder.length) {
        var pl_top = $plugin_holder.offset().top;
        if (menu_bottom > pl_top) {
          var margin = parseInt($plugin_holder.css('margin-top').replace('px', ''));
          $plugin_holder.css('margin-top', (menu_bottom - pl_top + margin)+'px');
        }
      }
    }(Suit.$));
  </script>
{% endblock %}
