{% load seahub_tags avatar_tags group_avatar_tags i18n staticfiles %}
{% load url from future %}

<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">
<head>
<title>{% block sub_title %}{% endblock %}{{ site_title }}</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="keywords" content="{% trans "File Collaboration Team Organization" %}" />
{% block viewport %}
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
{% endblock %}
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<link rel="shortcut icon" href="{{ MEDIA_URL }}{{ favicon_path }}" />
<link rel="stylesheet" type="text/css" href="{% static "css/bootstrap.min.css" %}"/>
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/jstree_default_theme/style.min.css" />
<link rel="stylesheet" type="text/css" href="{% static "css/magnific-popup.css" %}" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/seahub.min.css?t=1516678381" />
{% block extra_style %}{% endblock %}
{% if branding_css != '' %}<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}{{ branding_css }}" />{% endif %}
</head>

<body>
    <div id="wrapper" class="{{ LANGUAGE_CODE }}">
        {% block info_bar_message %}
        {% if request.user.is_authenticated and request.cur_note %}
        <div id="info-bar">
            <p id="info-bar-info">{{ request.cur_note.message|urlize }}</p>
            <span class="close sf2-icon-x1 op-icon" data="{{ request.cur_note.id }}" title="{% trans "Close" %}"></span>
        </div>
        {% endif %}
        {% endblock info_bar_message %}

        <div id="header" class="navbar {% block header_css_class %}navbar-fixed-top{% endblock %}">
            <div id="header-inner">
                {% block notice_panel %}{% endblock %}
                <a href="{{ SITE_ROOT }}" id="logo" class="fleft">
                    {% if seacloud_mode %}
                    <img src="{{ MEDIA_URL }}img/seacloud_logo.png?t=1516678381" title="Seacloud" alt="logo" width="186" height="31" />
                    {% else %}
                    <img src="{{ MEDIA_URL }}{{ logo_path }}" title="{{ site_title }}" alt="logo" width="{{logo_width}}" height="{{logo_height}}" />
                    {% endif %}
                </a>
                <button class="sf2-icon-list-view side-nav-toggle hidden-md-up hide" title="{% trans "Side Nav Menu" %}" id="js-toggle-side-nav" aria-label="{% trans "Side Nav Menu" %}"></button>

                {% block header_right %}
                {% if request.user.is_authenticated %}
                <div class="fright">

                {% block top_search %}
                {% if has_file_search %}
                    {% include 'snippets/search_form.html' %}
                {% endif %}
                {% endblock %}


                <div id="account" class="fright">
                    <a id="my-info" href="#" class="no-deco" aria-label="{% trans "View profile and more" %}">
                        {% avatar request.user 36 %} <span class="icon-caret-down vam"></span>
                    </a>
                    <div id="user-info-popup" class="account-popup sf-popover hide">
                        <div class="outer-caret up-outer-caret"><div class="inner-caret"></div></div>
                        <div class="sf-popover-con">
                            <div class="item ovhd">
                                {% avatar request.user 36 %}
                                <div class="txt">
                                    {{ request.user.username|email2nickname }} <br />
                                    {{ request.user.username|email2contact_email}}
                                </div>
                            </div>
                            <span class="loading-icon loading-tip"></span>
                            <div id="space-traffic" class="hide" data-url="{% url 'space_and_traffic' %}"></div>
                            <a class="item" href="{{ SITE_ROOT }}profile/">{% trans "Settings" %}</a>
                            {% block admin_link %}
                            {% if request.user.is_staff %}
                            <a href="{% url 'sys_useradmin' %}" title="{% trans "System Admin" %}" class="item">{% trans "System Admin" %}</a>
                            {% endif %}
                            {% if request.user.org and request.user.org.is_staff %}
                            <a href="{% url 'org_user_admin'%}" title="{% trans "Admin" %}" class="item">{% trans "Organization Admin" %}</a>
                            {% endif %}
                            {% if request.user.inst_admin %}
                            <a href="{% url "institutions:useradmin" %}" title="{% trans "Admin" %}" class="item">{% trans "Admin" %}</a>
                            {% endif %}
                            {% endblock %}
                            <a href="{{ SITE_ROOT }}accounts/logout/" class="item" id="logout">{% trans "Log out" %}</a>
                        </div>
                    </div>
                </div>
                </div>
                {% else %} {# for non-logged-in user #}
                <div class="fright" id="lang">
                    <a href="#" id="lang-context" data-lang="{{ LANGUAGE_CODE }}">{{ LANGUAGE_CODE|language_name_local }} <span class="icon-caret-down"></span></a>
                    <div id="lang-context-selector" class="sf-popover hide">
                        <ul class="sf-popover-con">
                            {% for LANG in LANGUAGES %}
                            <li><a href="{% url 'i18n' %}?lang={{ LANG.0 }}">{{ LANG.1 }}</a></li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>
                {% endif %}
                {% endblock %}
            </div>
        </div>

        <div id="main" class="clear container-fluid {% block main_css_class %}top-padding{% endblock %}">
            {% block main_content %}
            <div class="row">
                <div id="main-panel" class="w100 ovhd">
                    {% block main_panel %}{% endblock %}
                </div>
            </div>
            {% endblock %}

            {% if messages %}
            <ul class="messages">
                {% for message in messages %}
                <li class="{{ message.tags }}">
                    {% if 'safe' in message.tags %}
                        {{ message|safe }}
                    {% else %}
                        {{ message }}
                    {% endif %}
                </li>
                {% endfor %}
            </ul>
            {% endif %}
            <div id="confirm-popup" class="hide">
                <div id="confirm-con"></div>
                <button id="confirm-yes">{% trans "Yes" %}</button>
                <button class="simplemodal-close">{% trans "No" %}</button>
            </div>
        </div>

</div><!-- wrapper -->

<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery-1.12.1.min.js" id="jquery"></script>{# 'id="jquery"' is for pdf file view with pdf2html #}
<script type="text/javascript" src="{% static "scripts/lib/jquery.simplemodal.js" %}"></script>
<script type="text/javascript" src="{% static "scripts/lib/jquery.ui.tabs.js" %}"></script>
<script type="text/javascript" src="{% static "scripts/lib/jstree.min.js" %}"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/jq.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/base.js?t=1516678381"></script>
<script type="text/javascript">
function ajaxErrorHandler(xhr, textStatus, errorThrown) {
    if (xhr.responseText) {
        feedback($.parseJSON(xhr.responseText).error||$.parseJSON(xhr.responseText).error_msg, 'error');
    } else {
        feedback("{% trans "Failed. Please check the network." %}", 'error');
    }
}
{% if request.user.is_authenticated %}
{% if request.cur_note %}
$('#info-bar .close').click(function() {
    $('#info-bar').addClass('hide');
    if (navigator.cookieEnabled) {
        var date = new Date(),
            cookies = document.cookie.split('; '),
            info_id_exist = false,
            new_info_id = $(this).attr('data') + '_';
        date.setTime(date.getTime() + 14*24*60*60*1000);
        new_info_id += '; expires=' + date.toGMTString() + '; path=' + '{{ SITE_ROOT }}';
        for (var i = 0, len = cookies.length; i < len; i++) {
            if (cookies[i].split('=')[0] == 'info_id') {
                info_id_exist = true;
                document.cookie = 'info_id=' + cookies[i].split('=')[1] + new_info_id;
                break;
            }
        }
        if (!info_id_exist) {
            document.cookie = 'info_id=' + new_info_id;
        }
    }
});
{% endif %}

{% if has_file_search %}
    {% include 'snippets/search_js.html' %}
{% endif %}

{% else %} {# for non-logged-in user #}
(function() {
    var lang_context = $('#lang-context'),
        lang_selector = $('#lang-context-selector');

    lang_context.parent().css({'position':'relative'});

    if ($('#header').is(':visible')) { // for login page
        lang_selector.css({
            'top': lang_context.position().top + lang_context.height() + 5,
            'right': 0
        });
    }

    var setLangSelectorMaxHeight = function() {
        if ($('#header').is(':visible')) { // for login page
            $('.sf-popover-con', lang_selector).css({
                'max-height': $(window).height() - lang_selector.offset().top - 12
            });
        }
    };
    $(window).resize(function() {
        if (lang_selector.is(':visible')) {
            setLangSelectorMaxHeight();
        }
    });

    lang_context.click(function() {
        lang_selector.toggleClass('hide');
        if (lang_selector.is(':visible')) {
            setLangSelectorMaxHeight();
        }
        return false;
    });

    $(document).click(function(e) {
        var element = e.target || e.srcElement;
        if (element.id != 'lang-context-selector' && element.id != 'lang-context') {
            lang_selector.addClass('hide');
        }
    });
})();
{% endif %}

if ($('.side-nav').length) {
    $('#logo').addClass('hidden-sm-down');
    $('#js-toggle-side-nav').removeClass('hide');
}
$('#js-toggle-side-nav').click(function() {
    $('.side-nav').css({'left': 0});
    return false;
});
$('.js-close-side-nav').click(function() {
    $('.side-nav').css({'left': '-300px'});
    return false;
});
$(window).resize(function() {
    if ($(window).width() >= 768) {
        $('.side-nav').css({'left': 0});
    }
});
</script>
{% block extra_script %}{% endblock %}
</body>
</html>
