       
{% block sonata_page_top_bar %}
    {% if sonata_page.isEditor or (app.security and app.security.token and is_granted('ROLE_PREVIOUS_ADMIN')) %}
        <div id="nz-sonata-admin-bar">
            <div class="hideable">

                {% if sonata_page.isEditor and sonata_page.isInlineEditionOn %}
                    <!-- CMS specific variables -->
                    <script>
                        jQuery(document).ready(function () {
                            Sonata.Page.init({
                                url: {
                                    block_save_position: '{{ sonata_admin.objectUrl('sonata.page.admin.page', 'edit', page) }}',
                                    block_edit: '{{ sonata_admin.url('sonata.page.admin.page|sonata.page.admin.block', 'edit', {'id': 'BLOCK_ID'}) }}'
                                }
                            });
                        });
                    </script>
                {% endif %}

                <header class="sonata-bc sonata-page-top-bar navbar navbar-inverse navbar-fixed-top" role="banner">
                    <div class="container">
                        <ul class="nav navbar-nav">
                            {% if app.security and app.security.token and is_granted('ROLE_SONATA_ADMIN') %}
                                <li><a href="{{ path('sonata_admin_dashboard') }}">{{ "header.sonata_admin_dashboard"|trans({}, 'SonataPageBundle') }}</a></li>
                                {% endif %}

                            {% if sonata_page.isEditor %}
                                {% set sites = sonata_page.siteavailables %}

                                {% if sites|length > 1 and site is defined %}
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ site.name }} <span class="caret"></span></a>
                                        <ul class="dropdown-menu">
                                            {% for site in sites %}
                                                <li><a href="{{ site.url }}">{{ site.name }}</a></li>
                                                {% endfor %}
                                        </ul>
                                    </li>
                                {% endif %}

                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Page <span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        {% if page is defined %}
                                            <li><a href="{{ sonata_admin.objectUrl('sonata.page.admin.page', 'edit', page) }}" target="_new">{{ "header.edit_page"|trans({}, 'SonataPageBundle') }}</a></li>
                                            <li><a href="{{ sonata_admin.objectUrl('sonata.page.admin.page|sonata.page.admin.snapshot', 'list', page) }}" target="_new">{{ "header.create_snapshot"|trans({}, 'SonataPageBundle') }}</a></li>
                                            <li class="divider"></li>
                                            {% endif %}

                                        <li><a href="{{ sonata_admin.url('sonata.page.admin.page', 'list') }}" target="_new">{{ "header.view_all_pages"|trans({}, 'SonataPageBundle') }}</a></li>

                                        {% if error_codes is defined and error_codes|length %}
                                            <li class="divider"></li>
                                            <li><a href="{{ path('sonata_page_exceptions_list') }}" target="_new">{{ "header.view_all_exceptions"|trans({}, 'SonataPageBundle') }}</a></li>
                                            {% endif %}
                                    </ul>
                                </li>

                                {% if page is defined %}
                                    <li>
                                        <a href="{{ sonata_admin.url('sonata.page.admin.page', 'compose', {'id': page.id}) }}">
                                            <i class="fa fa-magic"></i>
                                            {{ 'header.compose_page'|trans({}, 'SonataPageBundle')}}
                                        </a>
                                    </li>
                                {% endif %}

                                {% if page is defined and not page.enabled %}
                                    <li><span style="padding-left: 20px; background: red;"><strong><em>{{ 'header.page_is_disabled'|trans([], 'SonataPageBundle') }}</em></strong></span></li>
                                                {% endif %}

                                {% if sonata_page.isInlineEditionOn and page is defined %}
                                    <li>
                                        <form class="form-inline" style="margin: 0px">
                                            <label class="checkbox inline" for="page-action-enabled-edit"><input type="checkbox" id="page-action-enabled-edit">{{ 'header.show_zone'|trans({}, 'SonataPageBundle') }}</label>
                                            <input type="submit" class="btn" value="{{ 'btn_save_position'|trans({}, 'SonataPageBundle') }}" id="page-action-save-position">
                                        </form>
                                    </li>
                                {% endif %}
                            {% endif %}

                            {% if app.security and app.security.token and is_granted('ROLE_PREVIOUS_ADMIN') %}
                                <li><a href="{{ url('homepage', {'_switch_user': '_exit'}) }}">{{ "header.switch_user_exit"|trans({}, 'SonataPageBundle')}}</a></li>
                                {% endif %}

                        </ul>
                    </div>
                </header>
            </div>
            <style>
                .hideable .switch{
                    position: fixed;
                    right: 0;
                    top: 0;
                    background-color: red;
                    color: #EEE;
                    z-index: 1000000;
                }
            </style>
            <script>
                /*\
                 |*|
                 |*|  :: cookies.js ::
                 |*|
                 |*|  A complete cookies reader/writer framework with full unicode support.
                 |*|
                 |*|  Revision #1 - September 4, 2014
                 |*|
                 |*|  https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
                 |*|  https://developer.mozilla.org/User:fusionchess
                 |*|
                 |*|  This framework is released under the GNU Public License, version 3 or later.
                 |*|  http://www.gnu.org/licenses/gpl-3.0-standalone.html
                 |*|
                 |*|  Syntaxes:
                 |*|
                 |*|  * nzCookie.set(name, value[, end[, path[, domain[, secure]]]])
                 |*|  * nzCookie.get(name)
                 |*|  * nzCookie.remove(name[, path[, domain]])
                 |*|  * nzCookie.has(name)
                 |*|  * nzCookie.keys()
                 |*|
                 \*/

                var nzCookie = {
                    get: function (sKey) {
                        if (!sKey) {
                            return null;
                        }
                        return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
                    },
                    set: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
                        if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
                            return false;
                        }
                        var sExpires = "";
                        if (vEnd) {
                            switch (vEnd.constructor) {
                                case Number:
                                    sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
                                    break;
                                case String:
                                    sExpires = "; expires=" + vEnd;
                                    break;
                                case Date:
                                    sExpires = "; expires=" + vEnd.toUTCString();
                                    break;
                            }
                        }
                        document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
                        return true;
                    },
                    remove: function (sKey, sPath, sDomain) {
                        if (!this.has(sKey)) {
                            return false;
                        }
                        document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "");
                        return true;
                    },
                    has: function (sKey) {
                        if (!sKey) {
                            return false;
                        }
                        return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
                    },
                    keys: function () {
                        var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
                        for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) {
                            aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
                        }
                        return aKeys;
                    }
                };
                ;
                (function ($, window, document, undefined) {

                    "use strict";

                    var pluginName = "hideableBlock",
                            defaults = {
                            };

                    function Plugin(el, options) {
                        this.el = el;
                        this.$el = $(el);
                        /*this.$panel = $('<div class="panel"></div>');*/
                        /*this.$el.children().wrapAll(this.$panel);*/
                        /*this.$panel.hide();*/

                        this.settings = $.extend({}, defaults, options);
                        this._defaults = defaults;
                        this._name = pluginName;
                        this.init();
                    }

                    $.extend(Plugin.prototype, {
                        init: function () {
                            this.$panel = this.$el.children().wrapAll('<div class="panel"></div>');
                            this.$sbtn = $('<button class="switch">switch</button>');

                            this.$el.append(this.$sbtn);
                            this.bindEvents();
                            this.hidePanel();

                            /*if(nzCookie.has())*/
                        },
                        bindEvents: function () {
                            var self = this;
                            this.$sbtn.on('click', function () {
                                if (self.$panel.is(':visible')) {
                                    self.hidePanel();
                                } else {
                                    self.showPanel();
                                }
                            });
                        },
                        showPanel: function () {
                            this.$panel.show();
                        },
                        hidePanel: function () {
                            this.$panel.hide();

                        }
                    });

                    $.fn[ pluginName ] = function (options) {
                        return this.each(function () {
                            if (!$.data(this, "plugin_" + pluginName)) {
                                $.data(this, "plugin_" + pluginName, new Plugin(this, options));
                            }
                        });
                    };

                })(jQuery, window, document);

                $(".hideable").hideableBlock({});
            </script>
        </div>
    {% endif %}
{% endblock %}