{% extends "admin/base.html" %}
{% load mezzanine_tags i18n static static %}

{% block title %}{{ title }} | Mezzanine{% endblock %}

{% block extrahead %}
{% if user.is_staff %}<script src="{% url 'admin:jsi18n' %}"></script>{% endif %}
<script src="{% static "mezzanine/js/"|add:settings.JQUERY_FILENAME %}"></script>

<script>
    {% url "static_proxy" as static_proxy_url %}
    {% url "fb_browse" as fb_browse_url %}
    {% url "displayable_links_js" as link_list_url %}
    {% url "admin:index" as admin_index_url %}
    {% get_current_language as LANGUAGE_CODE %}
    window.__home_link = '<a href="{% url "home" %}">{% trans "View site" %}</a>';
    window.__csrf_token = '{{ csrf_token }}';
    window.__admin_keywords_submit_url = '{% url "admin_keywords_submit" %}';
    window.__filebrowser_url = '{{ fb_browse_url }}';
    window.__link_list_url = '{{ link_list_url }}';
    window.__tinymce_css = '{% static "mezzanine/css/tinymce.css" %}';
    window.__admin_url = '{{ admin_index_url }}';
    window.__static_proxy = '{{ static_proxy_url }}';
    window.__admin_media_prefix__ = '{% get_static_prefix %}/admin';
    window.__grappelli_installed = {{ settings.GRAPPELLI_INSTALLED|lower }};
    window.__admin_menu_collapsed = {{ settings.ADMIN_MENU_COLLAPSED|lower }};
    window.__language_code = '{{ LANGUAGE_CODE }}';
</script>

{{ media }}
{% endblock extrahead %}

{% block stylesheets %}
{{ block.super }}
<link rel="stylesheet" href="{% static "mezzanine/css/admin/global.css" %}">
<style>
    /* These are set in PageAdmin's view methods, and mezzanine.utils.admin.SingletonAdmin */
    {% if hide_delete_link or singleton %}.submit-row .deletelink {display:none !important;}{% endif %}
    {% if hide_slug_field %}.slug {display:none !important;}{% endif %}
    {% if singleton %}.change-view-save-another {display:none !important;}{% endif %}
</style>
{% endblock %}

{% block rtl_styles %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "mezzanine/css/admin/rtl.css" %}" />
{% endblock %}

{% block before_content %}
{% if user.is_staff and not is_popup and not request.GET.pop %}
{% admin_dropdown_menu %}
{% endif %}
{% endblock %}

{% block footer %}
{% if form.this_is_the_login_form %}
    <script src="{% static "mezzanine/js/admin/login.js" %}"></script>
{% else %}
    {% if user.is_staff %}
        {% if not is_popup and not request.GET.pop %}
        <link rel="stylesheet" href="{% static "mezzanine/chosen/chosen.css" %}">
        <script src="{% static "mezzanine/chosen/chosen-0.9.12.jquery.js" %}"></script>
        <script src="{% static "mezzanine/js/admin/navigation.js" %}"></script>
        {% endif %}

        <script src="{% static "mezzanine/js/admin/ajax_csrf.js" %}"></script>
    {% endif %}
{% endif %}
<script>
    $('.admin-title').on('click', () => location = '{% url "admin:index" %}')

    // Set the Description field as readonly if the "Generate description" box is checked
    const $gen_desc = $('#id_gen_description')
    const $desc = $('#id_description')
    const set_readonly = () => $gen_desc.is(':checked') ? $desc.attr('readonly', '') : $desc.removeAttr('readonly')
    $gen_desc.on('change', set_readonly)
    set_readonly()
</script>
{% endblock footer %}
