{% extends "wagtailadmin/base.html" %}
{% load wagtailadmin_tags %}
{% load l10n %}
{% load core_tags %}
{% block titletag %}{% blocktrans with title=page.get_admin_display_title page_type=content_type.model_class.get_verbose_name %}Editing {{ page_type }}: {{ title }}{% endblocktrans %}{% endblock %}
{% block bodyclass %}page-editor {% if page.live %}page-is-live{% endif %} model-{{ content_type.model }} {% if page.locked %}page-locked{% endif %}{% endblock %}

{% block content %}
    {% page_permissions page as page_perms %}
    <header class="merged tab-merged">
        {% explorer_breadcrumb page %}

        <div class="row row-flush">
            <div class="left col9 header-title">
                <h1 class="icon icon-doc-empty-inverse">
                {% blocktrans with title=page.get_admin_display_title page_type=content_type.model_class.get_verbose_name %}Editing {{ page_type }} <span>{{ title }}</span>{% endblocktrans %}</h1>
            </div>
            <div class="right col3">
                {% trans "Status" %}
                {% include "wagtailadmin/shared/page_status_tag.html" with page=page_for_status %}

                {% include "wagtailadmin/pages/_privacy_switch.html" with page=page page_perms=page_perms only %}
                {% include "wagtailadmin/pages/_lock_switch.html" %}
            </div>
        </div>
    </header>

    <form id="page-edit-form" action="{% url 'wagtailadmin_pages:edit' page.id %}" method="POST" novalidate{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}>
        {% csrf_token %}

        <input type="hidden" name="next" value="{{ next }}">
        {{ edit_handler.render_form_content }}

        {% if is_revision %}
            <input type="hidden" name="revision" value="{{ revision.id|unlocalize }}" />
        {% endif %}

        <footer>
            <ul>
                <li class="actions">
                    <div class="dropdown dropup dropdown-button match-width {% if is_revision %}warning{% endif %}">
                        <button type="submit" class="button action-save button-longrunning {% if is_revision %}warning{% endif %}" tabindex="3" data-clicked-text="{% trans 'Saving...' %}" {% if page.locked %}disabled {% endif %}><span class="icon icon-spinner"></span><em>{% if page.locked %}{% trans 'Page locked' %}{% else %}{% if is_revision %}{% trans 'Replace current draft' %}{% else %}{% trans 'Save draft' %}{% endif %}{% endif %}</em></button>

                        {% if not page.locked %}
                            <div class="dropdown-toggle icon icon-arrow-up"></div>
                            <ul role="menu">
                                {% if not is_revision and page_perms.can_unpublish %}
                                    <li><a href="{% url 'wagtailadmin_pages:unpublish' page.id %}">{% trans 'Unpublish' %}</a></li>
                                {% endif %}
                                {% if not is_revision and page_perms.can_delete %}
                                    {% comment %}
                                    BEGIN CUSTOM TEMPLATE LOGIC
                                    Do not add delete button if Page should not be deleted
                                    This applies to all Pages that inherit from PreventDeleteMixin
                                    {% endcomment %}
                                    {% should_hide_delete_button page as delete_hidden %}
                                    {% if not delete_hidden %}
                                    {# END CUSTOM TEMPLATE LOGIC #}
                                        <li><a href="{% url 'wagtailadmin_pages:delete' page.id %}" class="shortcut">{% trans 'Delete' %}</a></li>
                                    {# BEGIN CUSTOM TEMPLATE LOGIC #}
                                    {% endif %}
                                    {# END CUSTOM TEMPLATE LOGIC #}
                                {% endif %}
                                {% if page_perms.can_publish %}
                                    <li>
                                        <button type="submit" name="action-publish" value="action-publish" class="button button-longrunning {% if is_revision %}warning{% endif %}" tabindex="3" data-clicked-text="{% trans 'Publishing...' %}" {% if page.locked %}disabled {% endif %}><span class="icon icon-spinner"></span><em>{% if is_revision %}{% trans 'Publish this revision' %}{% else %}{% trans 'Publish' %}{% endif %}</em></button>
                                    </li>
                                {% endif %}
                                {% comment %}
                                BEGIN CUSTOM TEMPLATE LOGIC
                                Commenting out the code to submit for moderation.
                                THIS SHOULD BE TEMPORARY!!
                                When the moderation is fixed this whole file must be removed
                                {% endcomment %}
                                <!-- {% if not is_revision %}
                                    <li><input type="submit" name="action-submit" value="{% trans 'Submit for moderation' %}" class="button" /></li>
                                {% endif %} -->
                                {# END CUSTOM TEMPLATE LOGIC #}
                            </ul>
                        {% endif %}
                    </div>
                </li>

                <li class="preview">
                    {% trans 'Preview' as preview_label %}
                    {% if preview_modes|length > 1 %}
                        <div class="dropdown dropup dropdown-button match-width">
                            {% include "wagtailadmin/pages/_preview_button_on_edit.html" with label=preview_label icon=1 %}
                            <div class="dropdown-toggle icon icon-arrow-up"></div>
                            <ul role="menu">
                                {% for mode_name, mode_display_name in preview_modes %}
                                    <li>
                                        {% include "wagtailadmin/pages/_preview_button_on_edit.html" with mode=mode_name label=mode_display_name %}
                                    </li>
                                {% endfor %}
                            </ul>
                        </div>
                    {% else %}
                        {% include "wagtailadmin/pages/_preview_button_on_edit.html" with label=preview_label icon=1 %}
                    {% endif %}
                </li>

                <li class="meta">
                    <p class="modified">
                        {% if page.get_latest_revision %}
                            {% blocktrans with last_mod=page.get_latest_revision.created_at %}Last modified: {{ last_mod }}{% endblocktrans %}
                            {% if page.get_latest_revision.user %}
                                {% blocktrans with modified_by=page.get_latest_revision.user.get_full_name|default:page.get_latest_revision.user.get_username %}by {{ modified_by }}{% endblocktrans %}
                                <span class="avatar small"><img src="{% avatar_url page.get_latest_revision.user size=25 %}" /></span>
                            {% endif %}
                            <a href="{% url 'wagtailadmin_pages:revisions_index' page.id %}" class="underlined">{% trans 'Revisions' %}</a>
                        {% endif %}
                    </p>
                </li>
                {% block extra_footer_actions %}
                {% endblock %}
            </ul>
        </footer>
    </form>

{% endblock %}

{% block extra_css %}
    {{ block.super }}
    {% include "wagtailadmin/pages/_editor_css.html" %}
    {{ edit_handler.form.media.css }}
{% endblock %}

{% block extra_js %}
    {{ block.super }}
    {% include "wagtailadmin/pages/_editor_js.html" %}

    {% comment %}
        Additional js from widgets media. Allows for custom widgets in admin panel.
    {% endcomment %}
    {{ edit_handler.form.media.js }}

    {% comment %}
        Additional HTML code that edit handlers define through 'html_declarations'. (Technically this isn't Javascript, but it will generally be data that exists for Javascript to work with...)
    {% endcomment %}
    {{ edit_handler.html_declarations }}

    <script>
        $(function() {
            /* Make user confirm before leaving the editor if there are unsaved changes */
            {% trans "This page has unsaved changes." as confirmation_message %}
            enableDirtyFormCheck(
                '#page-edit-form',
                {
                    confirmationMessage: '{{ confirmation_message|escapejs }}',
                    {% if has_unsaved_changes %}
                        alwaysDirty: true,
                    {% endif %}
                }
            );
        });
    </script>
{% endblock %}