{% load i18n l10n sekizai_tags static cms_tags cms_js_tags cms_static %}
{% addtoblock "css" %}
    <link rel="stylesheet" href="{% static_with_version "cms/css/cms.base.css" %}" />
{% endaddtoblock %}
{% for css in cms_toolbar.media.render_css %}
    {% addtoblock "css" %}
        {{ css }}
    {% endaddtoblock %}
{% endfor %}
{% addtoblock "js" %}
    <script data-cms src="{% static_with_version "cms/js/dist/bundle.toolbar.min.js" %}" type="text/javascript"></script>
    <script data-cms>
CMS._plugins = CMS._plugins || [];
// this is a global shared configuration
CMS.config = {
    'mode': {% if cms_toolbar.edit_mode_active %}'draft'{% else %}'live'{% endif %},
    'auth': {% if user.is_authenticated %}true{% else %}false{% endif %},
    'debug': {% if debug %}true{% else %}false{% endif %},
    'csrf': '{{ csrf_token }}',
    'request': {
        'language': '{{ cms_toolbar.request_language }}',
        'model': '{{ cms_toolbar.get_object_model }}',
        'page_id': '{% if request.current_page.publisher_is_draft %}{{ request.current_page.pk|unlocalize }}{% else %}{{ request.current_page.publisher_public_id|unlocalize }}{% endif %}',
        'pk': '{{ cms_toolbar.get_object_pk|unlocalize }}',
        'url': '{% language cms_toolbar.request_language %}{% cms_admin_url "cms_page_resolve" %}{% endlanguage %}',
        'toolbar': '{% language cms_toolbar.request_language %}{% cms_admin_url "cms_usersettings_get_toolbar" %}{% endlanguage %}'
    },
    'lang': {
        {% if user.is_authenticated %}
        'debug': '{% filter escapejs %}{% blocktrans %}Development version using django CMS {{ cms_version }}, Django {{ django_version }}, Python {{ python_version }}{% endblocktrans %}{% endfilter %}',
        {% endif %}
        'cancel': '{% filter escapejs %}{% trans "Cancel" %}{% endfilter %}',
        'error': '<strong>{% filter escapejs %}{% trans "The following error occured:" %}{% endfilter %}</strong> ',
        'success': '{% filter escapejs %}{% trans "Action successful." %}{% endfilter %}',
        'confirm': '{% filter escapejs %}{% trans "Are you sure you want to delete this plugin?" %}{% endfilter %}',
        'publish': '{% filter escapejs %}{% trans "Are you sure you want to publish this page?" %}{% endfilter %}',
        'addPluginPlaceholder': '{% filter escapejs %}{% trans "Plugin will be added here" %}{% endfilter %}',
        'confirmDirty': '{% filter escapejs %}{% trans "You have unsaved changes." %}{% endfilter %}',
        'loading': '{% filter escapejs %}{% trans "Loading" %}{% endfilter %}',
        'confirmDirtyESC': '{% filter escapejs %}{% trans "Are you sure you want to abandon these changes?" %}{% endfilter %}',
        'errorLoadingEditForm': '{% filter escapejs %}{% trans "The form could not be loaded. Please check that the server is running correctly." %}{% endfilter %}',
        'mostUsed': '{% filter escapejs %}{% trans "Most used" %}{% endfilter %}',
        'shortcuts': '{% filter escapejs %}{% trans "Shortcuts" %}{% endfilter %}',
        'unhandledPageChange': '{% filter escapejs %}{% trans "The page was changed in the meantime, reloading..." %}{% endfilter %}',
        'shortcutAreas': [
            {
                'title': '{% filter escapejs %}{% trans "CMS-wide Shortcuts" %}{% endfilter %}',
                'shortcuts': {
                    'help': {
                        'shortcut': '?',
                        'desc': '{% filter escapejs %}{% trans "Bring up this help dialog" %}{% endfilter %}'
                    },
                    'esc': {
                        'shortcut': 'ESC',
                        'desc': '{% filter escapejs %}{% trans "Close/cancel" %}{% endfilter %}'
                    },
                    'toggle-structure-board': {
                        'shortcut': 'space',
                        'desc': '{% filter escapejs %}{% trans "Toggle structure mode" %}{% endfilter %}'
                    },
                    'toggle-structure-board-using-hovered-plugin': {
                        'shortcut': 'shift+space',
                        'desc': '{% filter escapejs %}{% trans "Toggle structure mode and highlight hovered-over plugin" %}{% endfilter %}'
                    },
                    'create-dialog': {
                        'shortcut': 'alt+c',
                        'desc': '{% filter escapejs %}{% trans 'Open "Create" dialog' %}{% endfilter %}'
                    },
                    'toolbar': {
                        'shortcut': 'f > t / alt+t',
                        'desc': '{% filter escapejs %}{% trans "Focus on Toolbar" %}{% endfilter %}'
                    },
                }
            },
            {
                'title': '{% filter escapejs %}{% trans "Structureboard" %}{% endfilter %}',
                'shortcuts': {
                    'placeholders': {
                        'shortcut': 'f > p / alt+p',
                        'desc': '{% filter escapejs %}{% trans "Focus on placeholders" %}{% endfilter %}'
                    },
                    'traversing': {
                        'shortcut': 'tab / shift+tab',
                        'desc': '{% filter escapejs %}{% trans "Move to next/previous element" %}{% endfilter %}'
                    },
                    'enter': {
                        'shortcut': 'enter',
                        'desc': '{% filter escapejs %}{% trans "Focus on plugins of placeholder" %}{% endfilter %}'
                    },
                    'edit': {
                        'shortcut': 'e',
                        'desc': '{% filter escapejs %}{% trans "Edit plugin" %}{% endfilter %}'
                    },
                    'add': {
                        'shortcut': '+ / a',
                        'desc': '{% filter escapejs %}{% trans "Add plugin" %}{% endfilter %}'
                    },
                    'settings': {
                        'shortcut': '! / s',
                        'desc': '{% filter escapejs %}{% trans "Open actions menu" %}{% endfilter %}'
                    },
                    'collapse': {
                        'shortcut': 'x',
                        'desc': '{% filter escapejs %}{% trans "Expand/collapse" %}{% endfilter %}'
                    }
                }
            }
        ]
    },
    'urls': {
        'settings': '{% cms_admin_url "cms_usersettings_session_store" %}', // url to save settings
        'static': '{{ STATIC_URL }}'
    },
    'settings': {
        'version': '{{ cms_version }}',
        'toolbar': 'expanded',
        'mode': {% if cms_toolbar.structure_mode_active %}'structure'{% else %}'edit'{% endif %},
        'sideframe': { 'url': '' },
        'states': [],
        'edit': '{{ cms_edit_on }}',
        'edit_off': '{{ cms_edit_off }}',
        'structure': '{{ cms_structure_on }}',
        'legacy_mode': {{ cms_toolbar.uses_legacy_structure_mode|yesno:'true,false' }}
    },
    'clipboard': {
        'id': '{{ cms_toolbar.clipboard.pk|unlocalize }}',
        'url': '{% if cms_toolbar.clipboard.pk %}{% cms_admin_url "cms_page_clear_placeholder" cms_toolbar.clipboard.pk %}{% endif %}'
    },
    'messages': '{% filter escapejs %}{% if messages %}{% for message in messages %}{{ message }}{% endfor %}{% endif %}{% endfilter %}',
    'error': '{% filter escapejs %}{% if cms_toolbar.login_form.errors or cms_toolbar_login_error %}{% blocktrans %}<strong>Login failed.</strong> Please check your credentials and try again.{% endblocktrans %}{% endif %}{% endfilter %}',
    'publisher': '{% filter escapejs %}{% if not request.current_page.publisher_is_draft and request.current_page.publisher_draft.is_dirty and user.is_authenticated %}{% trans "This page has unpublished changes." %}{% endif %}{% endfilter %}'
};
CMS.$(function () {
    CMS.settings = CMS.API.Helpers.getSettings();

    // extends API
    CMS.API.Clipboard = new CMS.Clipboard();
    CMS.API.StructureBoard = new CMS.StructureBoard();
    CMS.API.Messages = new CMS.Messages();
    CMS.API.Tooltip = new CMS.Tooltip();
    CMS.API.Toolbar = new CMS.Toolbar();

    CMS.Plugin._initializeTree();
});
    </script>
{% endaddtoblock %}
{% if cms_toolbar.clipboard_plugin %}{% render_plugin_init_js cms_toolbar.clipboard_plugin %}{% endif %}
{% for js in cms_toolbar.media.render_js %}
    {% addtoblock "js" %}{{ js }}{% endaddtoblock %}
    {% endfor %}
