{% load i18n l10n sekizai_tags admin_static cms_tags %}

{% addtoblock "css" %}<link rel="stylesheet" href="{% static "cms/css/cms.base.css" %}" />{% endaddtoblock %}

{% addtoblock "js" %}
<script>
var _jQuery = window.jQuery || undefined;
var _$ = window.$ || undefined;
</script>
<script src="{% static "cms/js/libs/jquery.min.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/libs/class.min.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/jquery.ui.custom.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/jquery.ui.nestedsortable.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/cms.base.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/cms.modal.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/cms.sideframe.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/cms.clipboard.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/cms.plugins.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/cms.structureboard.js" %}" type="text/javascript"></script>
<script src="{% static "cms/js/modules/cms.toolbar.js" %}" type="text/javascript"></script>
{% language request.toolbar.toolbar_language %}
<script>
(function($) {
// CMS.$ will be passed for $
$(document).ready(function () {
	// this is a global shared configuration
	CMS.config = {
		'mode': {% if request.toolbar.edit_mode %}'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': '{{ request.GET.language }}',
			'model': '{{ request.toolbar.get_object_model }}',
			'page_id': '{% if request.current_page.publisher_is_draft %}{{ request.current_page.pk }}{% else %}{{ request.current_page.publisher_public_id }}{% endif %}',
			'pk': '{{ request.toolbar.get_object_pk }}',
			'url': '{% language request.toolbar.language %}{% cms_admin_url "cms_page_resolve" %}{% endlanguage %}',
			'tree': '{% language request.toolbar.language %}{% cms_admin_url "cms_page_changelist" %}{% endlanguage %}'
		},
		'lang': {
			'debug': '{% blocktrans %}Development version using django CMS {{ cms_version }}{% endblocktrans %}',
			'cancel': '{% trans "Cancel" %}',
			'error': '<strong>{% trans "The following error occured:" %}</strong> ',
			'success': '{% trans "Action successfull... reloading." %}',
			'confirm': '{% trans "Are you sure you want to delete this plugin?" %}',
			'publish': '{% trans "Are you sure you want to publish this page?" %}'
		},
		'urls': {
			'settings': '{% cms_admin_url "cms_usersettings_session_store" %}', // url to save settings
			'static': '{{ STATIC_URL }}'
		},
		'settings': {
			'version': '{{ cms_version }}',
			'toolbar': 'expanded',
			'mode': 'edit',
			'sideframe': { 'url': '' },
			'states': []
		},
		'clipboard': {
			'id': '{{ request.toolbar.clipboard.pk|unlocalize }}',
			'url': '{% if request.toolbar.clipboard.pk %}{% cms_admin_url "cms_page_clear_placeholder" request.toolbar.clipboard.pk %}{% endif %}'
		},
		'messages': '{% if messages %}{% for message in messages %}{{ message }}{% endfor %}{% endif %}',
		'error': '{% if request.toolbar.login_form.errors or cms_toolbar_login_error %}{% blocktrans %}<strong>Login failed.</strong> Please check your credentials and try again.{% endblocktrans %}{% endif %}',
		'publisher': '{% 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 %}'
	};
	CMS.settings = CMS.API.Helpers.getSettings();

	// extends API
	$.extend(CMS.API, {
		'Toolbar': new CMS.Toolbar(),
		'Clipboard': new CMS.Clipboard(),
		'StructureBoard': new CMS.StructureBoard()
	});
});
})(CMS.$);
</script>
{% endlanguage %}
<script>
window.jQuery = _jQuery;
window.$ = _$;
</script>

{% endaddtoblock %}


{% addtoblock "css" %}<link rel="stylesheet" href="{% static "djangocms_livedraftswitch/toggle-switch.css" %}" />{% endaddtoblock %}
{% addtoblock "css" %}
    <style type="text/css">
        @media only screen {
            #cms_toolbar .cms_toolbar-item_switch_save-edit {
                float: right !important;
            }
            #cms_toolbar .cms_toolbar-item_switch_save-edit * {
                outline: none !important;
            }
            #cms_toolbar .cms_toolbar-item_switch_save-edit .switch-candy {
                min-height: 22px;
                width: 120px;
                background-color: #EBEBEB;
            }
            #cms_toolbar .cms_toolbar-item_switch_save-edit .switch-candy label {
                height: 22px;
                line-height: 20px;
                vertical-align: bottom;
                font-size: 11px;
                text-shadow: none;
                color: #666666;
                cursor: pointer;
            }
            #cms_toolbar .switch-toggle input:checked + label {
                color: #FFFFFF;
                cursor: default;
            }
            #cms_toolbar .cms_toolbar-item_switch_save-edit .switch-candy a {
                border-radius: 3px !important;
            }
            #cms_toolbar .switch-toggle input:last-of-type:checked ~ a {
                border: 1px solid #BD9A7C !important;
                box-shadow: inset #F5C49D 0 1px 0;
                /* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ff8e15+0,de6400+100 */
                background: #ff8e15; /* Old browsers */
                background: -moz-linear-gradient(top,  #ff8e15 0%, #de6400 100%); /* FF3.6+ */
                background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ff8e15), color-stop(100%,#de6400)); /* Chrome,Safari4+ */
                background: -webkit-linear-gradient(top,  #ff8e15 0%,#de6400 100%); /* Chrome10+,Safari5.1+ */
                background: -o-linear-gradient(top,  #ff8e15 0%,#de6400 100%); /* Opera 11.10+ */
                background: -ms-linear-gradient(top,  #ff8e15 0%,#de6400 100%); /* IE10+ */
                background: linear-gradient(to bottom,  #ff8e15 0%,#de6400 100%); /* W3C */
                filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff8e15', endColorstr='#de6400',GradientType=0 ); /* IE6-9 */
            }
        }
    </style>
{% endaddtoblock %}
{% addtoblock "js" %}
    <script>

        $(function() {
            var $item_wrap = $('.cms_toolbar-item_switch_save-edit');
            var $original_button = $item_wrap.children('a.cms_btn');
            var public_checked, draft_checked;
            var $draft_radio;
            if ($original_button.hasClass('cms_btn-switch-edit')) {
                public_checked = 'checked';
                draft_checked = '';
            } else {
                public_checked = '';
                draft_checked = 'checked';
            }
            $original_button.css({'display': 'none'});
            var $switch = $(''
 + '<div class="switch-toggle switch-candy">'
 + '  <input id="livedraftswitch_public" name="view" type="radio" ' + public_checked+ '>'
 + '  <label for="livedraftswitch_public" onclick="">Live</label>'
 + '  <input id="livedraftswitch_draft" name="view" type="radio" ' + draft_checked+ ' data-initial="' + draft_checked + '">'
 + '  <label for="livedraftswitch_draft" onclick="">Draft</label>'
 + '  <a class="cms_btn-action"></a>'
 + '</div>'
            );
            $switch.appendTo($item_wrap);
            $draft_radio = $switch.find('#livedraftswitch_draft');
            $switch.on('click', function() {
                if ($switch.hasClass('switched')) return;
                if ($draft_radio.is(':checked') !== ($draft_radio.data('initial') === 'checked')) {
                    $switch.addClass('switched');
                    setTimeout(function(){
                        window.location = $original_button.attr('href');
                    }, 300);
                }
            });
        });
    </script>
{% endaddtoblock %}
