{#{% load i18n %}#}<!DOCTYPE html>
<html>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>

<head>
    <meta charset="utf-8">
    <title>  {{ settings.TITLE }} - {{ settings.VERSION }} {% if request.user.id < 0 %}渠道 - {% endif %} 后台 </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">


    <script type="text/javascript" src="/static/assets/jquery/jquery-1.11.1.min.js"></script>
    <script src="/static/assets/bootstrap-tagsinput-latest/dist/bootstrap-tagsinput.min.js"></script>
    <script type="text/javascript" src="/i18n/js?format=html&v={{ settings.VERSION }}"></script>
    <script src="/static/assets/daterangepicker/moment.min.js"></script>
    <script type="text/javascript" src="/static/framework/js/common.js?v={{ settings.VERSION }}"></script>
    <script type="text/javascript" src="/static/framework/js/ui.js?v={{ settings.VERSION }}"></script>
    <script type="text/javascript" src="/static/framework/js/ajaxSetup.js?v={{ settings.VERSION }}"></script>
    <script type="text/javascript" src="/static/framework/js/select-input.js?v={{ settings.VERSION }}"></script>

    <script type="text/javascript" src="/i18n/js?format=html&v={{ settings.VERSION }}"></script>
    <link rel="stylesheet" href="/static/assets/layuiadmin/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/assets/layuiadmin/layuiadmin/style/admin.css" media="all">

    <style>

        .layui-side-menu .layui-nav .layui-nav-item i {
            position: absolute;
            top: 50%;
            left: 20px;
            margin-top: -9px;
        }

    </style>
</head>

<body class="layui-layout-body">
<div id="LAY_app">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <!-- 头部区域 -->
            <ul class="layui-nav layui-layout-left">
                <li class="layui-nav-item layadmin-flexible" lay-unselect>
                    <a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">
                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
                    </a>
                </li>
            </ul>


            <ul class="layui-nav layui-layout-right" lay-filter="layadmin-layout-right">


                {#                <li class="layui-nav-item" lay-unselect>#}
                {##}
                {#                    <a href="javascript:;">#}
                {#                        {% for m in data.root_menu_list %}#}
                {#                            {% if m.id == data.parent_id %}#}
                {#                                <label>{{ m.label }}</label>#}
                {#                            {% endif %}#}
                {#                        {% endfor %}#}
                {##}
                {##}
                {#                    </a>#}
                {#                    <dl class="layui-nav-child " lay-unselect>#}
                {#                        {% for m in data.root_menu_list %}#}
                {#                            <dd style="text-align: center;"><a href="?parent_id={{ m.id }}">{{ m.label }}</a></dd>#}
                {#                        {% endfor %}#}
                {##}
                {#                    </dl>#}
                {#                </li>#}


                <!--<li class="layui-nav-item" lay-unselect>-->
                <!--<a lay-href="app/message/index.html" layadmin-event="message" lay-text="消息中心">-->
                <!--<i class="layui-icon layui-icon-notice"></i>-->

                <!--&lt;!&ndash; 如果有新消息，则显示小圆点 &ndash;&gt;-->
                <!--<span class="layui-badge-dot"></span>-->
                <!--</a>-->
                <!--</li>-->


                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:;" layadmin-event="refresh" title="刷新">
                        <i class="layui-icon layui-icon-refresh-3"></i>
                    </a>
                </li>

                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <a href="javascript:;" layadmin-event="theme" title="切换主题">
                        <i class="layui-icon layui-icon-theme"></i>
                    </a>
                </li>
                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <a href="javascript:;" layadmin-event="note" title="便签">
                        <i class="layui-icon layui-icon-note"></i>
                    </a>
                </li>
                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <a href="javascript:;" layadmin-event="fullscreen" title="全屏">
                        <i class="layui-icon layui-icon-screen-full"></i>
                    </a>
                </li>
                <li class="layui-nav-item" lay-unselect>

                    <a href="javascript:;">
                        {% for l in LANGUAGES %}
                            {% if l.0 == request.language %}
                                {{ l.1 }}
                            {% endif %}
                        {% endfor %}

                    </a>
                    <dl class="layui-nav-child">

                        {% for lang in LANGUAGES %}
                            <dd style="text-align: center;"><a class="language-btn"
                                                               data-language="{{ lang.0 }}">{{ lang.1 }}</a></dd>
                        {% endfor %}

                    </dl>
                </li>
                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:;">
                        <cite>{{ request.user.alias }}</cite>
                    </a>
                    <dl class="layui-nav-child">

                        {% if request.session.previous_user_id %}
                            <dd lay-unselect="">
                                <a
                                        href="/myadmin/user/impersonate?change_previous=1"
                                        windowname='切换回旧账号'
                                        data-width='600px'
                                        data-height='500px'>
                                    切换回旧账号
                                </a>
                            </dd>
                        {% elif request.user.is_root %}
                            <dd lay-unselect="">
                                <a
                                        href="/myadmin/user/impersonate"
                                        windowname='切换管理员'
                                        data-width='600px'
                                        data-height='500px'>
                                    切换管理员
                                </a>
                            </dd>
                        {% endif %}


                        <dd><a lay-href="/myadmin/user_info/edit_self">基本资料</a></dd>


                        <dd><a id="edit-admin-self-btn"
                               class="openDialog"
                               data-width='500px'
                               data-height='500px'
                               lay-href="/myadmin/user/change_password">修改密码</a>
                        </dd>


                        <hr>
                        <dd layadmin-event="logout" style="text-align: center;"><a href="/myadmin/logout">退出</a></dd>

                    </dl>
                </li>


                {#                <li class="layui-nav-item layui-hide-xs" lay-unselect>#}
                {#                    <a href="/index_old" title="返回旧版主页"><i class="icon-lightbulb"></i></a>#}
                {#                </li>#}


                <li class="layui-nav-item layui-show-xs-inline-block " lay-unselect>
                    <a href="javascript:;" layadmin-event="more"><i class="layui-icon layui-icon-more-vertical"></i></a>

                </li>

            </ul>
        </div>
        <!-- 侧边菜单 -->
        <div class="layui-side layui-side-menu">
            <div class="layui-side-scroll">
                <div class="layui-logo " id="houtai_title">
                    {#                     <a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">#}
                    {#                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>#}
                    {#                    </a>#}

                    <span>{{ settings.TITLE }} - {% if request.user.id < 0 %}渠道
                        - {% endif %} {{ settings.VERSION }} </span>


                </div>

                <ul class="layui-nav layui-nav-tree"
                    lay-shrink="all"
                    id="LAY-system-side-menu"
                    lay-filter="layadmin-system-side-menu">

                    <li data-name="home" class="layui-nav-item">
                        <a href="javascript:;" lay-tips="Loading...." lay-direction="2">
                            <i class="layui-icon layui-icon-home"></i>
                            <cite>Loading....</cite>
                        </a>
                        <dl class="layui-nav-child">
                            <dd data-name="console" class="layui-this">
                                <a lay-href="home/console.html">控制台</a>
                            </dd>
                            <dd data-name="console">
                                <a lay-href="home/homepage1.html">主页一</a>
                            </dd>
                            <dd data-name="console">
                                <a lay-href="home/homepage2.html">主页二</a>
                            </dd>
                        </dl>
                    </li>


                </ul>
            </div>
        </div>
        <!-- 页面标签 -->
        <div class="layadmin-pagetabs" id="LAY_app_tabs">
            <div class="layui-icon layadmin-tabs-control layui-icon-prev" layadmin-event="leftPage"></div>
            <div class="layui-icon layadmin-tabs-control layui-icon-next" layadmin-event="rightPage"></div>
            <div class="layui-icon layadmin-tabs-control layui-icon-down">
                <ul class="layui-nav layadmin-tabs-select" lay-filter="layadmin-pagetabs-nav">
                    <li class="layui-nav-item" lay-unselect>
                        <a href="javascript:;"></a>
                        <dl class="layui-nav-child layui-anim-fadein">
                            <dd layadmin-event="closeThisTabs"><a href="javascript:;">关闭当前标签页</a></dd>
                            <dd layadmin-event="closeOtherTabs"><a href="javascript:;">关闭其它标签页</a></dd>
                            <dd layadmin-event="closeAllTabs"><a href="javascript:;">关闭全部标签页</a></dd>
                        </dl>
                    </li>
                </ul>
            </div>
            <div class="layui-tab" lay-unauto lay-allowClose="true" lay-filter="layadmin-layout-tabs">
                <ul class="layui-tab-title" id="LAY_app_tabsheader">

                    <li lay-id="home/console.html" lay-attr="{{ request.user.home_index }}" class="layui-this">
                        <i class="layui-icon layui-icon-home"></i></li>
                </ul>

            </div>
        </div>
        <!-- 主体内容 -->
        <div class="layui-body" id="LAY_app_body">
            <div class="layadmin-tabsbody-item layui-show">
                <iframe src="{{ role_index_url }}" frameborder="0" class="layadmin-iframe"></iframe>
            </div>
        </div>
        <!-- 辅助元素，一般用于移动设备下遮罩 -->
        <div class="layadmin-body-shade" layadmin-event="shade"></div>
    </div>
</div>
<script src="/static/assets/layuiadmin/layuiadmin/layui/layui.js"></script>
<script>

    var tab_concent = null
    var history_menu = null
    var menu_list = []
    var root_menu_id = '{{ data.parent_id }}'

    function Menu(menu_list) {
        var This = this
        var main_menu_ul = $('#LAY-system-side-menu')
        this.make_menu_list = function (parent_id) {
            if (typeof (menu_list) == 'undefined')
                return;
            var str = "";

            for (var i = 0; i < menu_list.length; i++) {
                var item = menu_list[i];
                item.name = item.label
                if (!item.name || item.parent_id != parent_id)
                    continue;
                // 第一个元素的 父id 为跟id

                var is_root_item = item.parent_id == root_menu_id

                str += is_root_item ? '<li data-name=' + item.name + ' class="layui-nav-item" >' : '<dl class="layui-nav-child">'


                if (!item.icon && is_root_item) {
                    item.icon = 'layui-icon layui-icon-template-1'
                }


                var icon = item.icon ? '<i class="   ' + item.icon + '"></i>' : ''
                var item_name = icon + item.name

                var sub_menu_str = This.make_menu_list(item.id)
                var item_a = ''
                var href = item.url ? 'lay-href="' + item.url + '"' : 'href="javascript:;"'
                if (is_root_item) {
                    item_a += '<a  ' + href + ' lay-tips="' + item.name + '" lay-direction="2">' + icon + '<cite>' + item.name + '</cite></a>'
                }
                if (sub_menu_str != '') {
                    if (is_root_item) {
                        item_a += sub_menu_str
                    } else {

                        item_a += '<dd data-name="' + item.name + ' ">'
                        item_a += '<a title="双击打开多个窗口" item_id="' + item.id + '" pid="' + item.parent_id + '" style="' + item.css + '"  title="' + item.name + '"   >' + item_name + '</a>' + sub_menu_str;
                        item_a += '</dd>'
                    }
                } else {
                    if (!is_root_item) {
                        //item_a = ' <dd data-name="mobile"><a item_id="'+ item.id + '" pid="' + item.parent_id + '" style="float: right;padding-right: 21px;z-index: 1000;max-width: 1px;padding-left: 8px;" copy=1 href="' +  item.url + '" title="多开一个窗口" tab_name="' + item.name + '">&gt;</a>'
                        item_a += '<dd data-name="' + item.name + '">'
                        item_a += '<a title="双击打开多个窗口" item_id="' + item.id + '" pid="' + item.parent_id + '" style="' + item.css + '" lay-href="' + item.url + '"  title="' + item.name + '" >' + item_name + '</a>';
                        item_a += '</dd>'
                    }

                }
                str += item_a
                str += is_root_item ? '</li>' : '</dl>'
            }
            return str;
        }
        this.load_menu_list = function () {
            main_menu_ul.html(This.make_menu_list(root_menu_id))
        }

    }

    function TabConcent() {
        this.add_tab = function (a_obj) {
            var _a_obj = $(a_obj)
            var _url = _a_obj.attr('href') ? _a_obj.attr('href') : _a_obj.attr('url')
            _url = _url ? _url : '#'
            var height = '100%'
            var _text = _a_obj.attr('tab_name') ? _a_obj.attr('tab_name') : _a_obj.text()
            if (_url != '#' && _url && _url.indexOf('javascript') < 0) {
                var _url_id = _url.replace(/[:\/\?&=#"'\.]/g, "_");
                layui.element.tabAdd('layadmin-layout-tabs', {
                    title: _text,
                    id: _url_id,
                    attr: _url_id
                })

                layui.$('#LAY_app_body').append(['<div class="layadmin-tabsbody-item layui-show">', '<iframe src="' + _url + '" frameborder="0" class="layadmin-iframe"></iframe>', "</div>"].join(""))
                layui.element.tabChange('layadmin-layout-tabs', _url_id)
                layui.user.tabsBodyChange(layui.user.tabsPage.index, {url: _url, text: _text})
                return true
            }
            return false
        }
    }


    $('.language-btn').click(function (e) {
        e.preventDefault()
        $.post("/i18n/set_language", {
            csrfmiddlewaretoken: '{{ csrf_input }}',
            language: $(this).attr('data-language')
        }, function (data) {
            window.location.reload()
        })
    })
    $(document).on('click', '.bootswatch-btn', function (e) {
        stopEevent(e)
        var theme_name = $(this).attr('data-theme')
        $('iframe').each(function (i, ele) {
            if (ele.contentWindow.setTheme) {
                ele.contentWindow.setTheme(theme_name)
            }
        })
        setTheme(theme_name)
        return false
    })

    // 手机浏览器兼容，在手机浏览器上使用新窗口方式打开栏目

    try {

        $.getJSON('/myadmin/menu/list', {is_show__exact: 1, page_size: 1000}, function (rsp) {
            if (rsp.code != 0) {

                alert('get menu error: ' + rsp.msg)
            } else {
                menu_list = rsp.data.results
                m = new Menu(menu_list)
                m.load_menu_list()
                tab_concent = new TabConcent('tab_ul', 'iframe_content');
                layui.config({
                    base: '/static/assets/layuiadmin/layuiadmin/' //静态资源所在路径
                }).extend({
                    index: 'lib/index' //主入口模块
                }).use('index');
            }

        })


    } catch (e) {
        console.dir(e)
    }
    {% if request.user.is_not_active %}
        alert("{{ _('账号未激活,请联系管理员') }}")
    {% endif %}
    $(".layui-nav-child a").on("click", function () {
        if (browser.versions.mobile || browser.versions.ios || browser.versions.android ||
            browser.versions.iPhone || browser.versions.iPad) {
            var href = $(this).attr("lay-href");
            window.open(href, "_blank"); //注意第二个参数
            return false;
        }
    })

</script>
</body>

</html>