{% import "TopxiaWebBundle::macro.html.twig" as web_macro %}
{% import "TopxiaAdminBundle::macro.html.twig" as admin_macro %}
<!DOCTYPE html>
{% set menu = menu|default(null) %}
{% set menu_breadcrumb = menu_breadcrumb('admin', menu) %}
{% set menu_current = menu_breadcrumb|last %}
{% set menu_nav = menu_breadcrumb[0]|default(null) %}
{% set menu_sidebar = menu_breadcrumb[1]|default(null) %}
{% set menu_main = menu_breadcrumb[2]|default(null) %}
{% set menu_hiddens = setting('menu_hiddens', []) %}
<!--[if lt IE 7]>      <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class=""> <!--<![endif]-->
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="renderer" content="webkit">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta content="{{ csrf_token('site') }}" name="csrf-token" />
  <title>
    {% block title %}
      {% for m in menu_breadcrumb|reverse %}
        {% if loop.index == menu_breadcrumb|length %}
          {{ m.name }}
        {% else %}
          {{ m.name }} -
        {% endif %}
      {% endfor %}
    {% endblock %}
    {% if not setting('copyright.owned') %} | EduSoho{% endif %}
  </title>

  {% if setting('site.favicon') %}
  <link href="{{ asset(setting('site.favicon')) }}" rel="shortcut icon" />
  {% endif %}
  <link href="{{ asset('assets/libs/gallery2/bootstrap/3.1.1/css/bootstrap.css') }}" rel="stylesheet" />
  <link href="{{ asset('assets/css/common.css') }}" rel="stylesheet" />
  <link href="{{ asset('bundles/topxiaadmin/css/admin.css') }}" rel="stylesheet" />
  <link href="{{ asset('bundles/topxiaadmin/css/admin_v2.css') }}" rel="stylesheet" />
  {% block javascripts %}{% endblock %}
  <!--[if lt IE 9]>
    <script src="{{ asset('assets/libs/html5shiv.js') }}"></script>
    <script src="{{ asset('assets/libs/respond.min.js') }}"></script>
  <![endif]-->
</head>

<body>
  <div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="{{ url('admin') }}">{% if not setting('copyright.owned') %}EduSoho{% endif %}管理后台</a>
      </div>
      <div class="navbar-collapse collapse">

        <ul class="nav navbar-nav">
          {% for m in menu_children('admin', 'admin', 1) %}

            {% if m.code == "admin_app"%}
               {% if not is_granted('ROLE_SUPER_ADMIN') %}
                {% set parameter = {'postStatus':'all'} %}
                {% set m = m|array_merge({'router_params':parameter,'router_name':'admin_app_center'}) %}
               {% endif %}
            {% endif %}

            {% if m.code != "admin_system" %}
                <li {% if m.code == menu_nav.code|default(null) %}class="active"{% endif %}>
                  {{ _self.menu_link_html(_context, m) }}
                </li>  
            {% else %}    
                {% if is_granted('ROLE_SUPER_ADMIN') %}
                  <li {% if m.code == menu_nav.code|default(null) %}class="active"{% endif %}>
                  {{ _self.menu_link_html(_context, m) }}
                  </li>
                {% endif %}
            {% endif %}

          {% endfor %}
        </ul>

        <ul class="nav navbar-nav navbar-right">
          <li data-url="{{path('admin_common_admin')}}">
            <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" ><span class="glyphicon glyphicon-list admin-star"></span> 常用</a>
            <ul class="dropdown-menu shortcuts">
              {{ render(controller('TopxiaAdminBundle:CommonAdmin:commonAdmin')) }}
            </ul>
          </li>
          <li><a href="{{ path('homepage') }}"><i class="glyphicon glyphicon-home"></i> 回首页</a></li>

          <li class="dropdown">
                <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"><i class="glyphicon glyphicon-user"></i> {{ app.user.nickname }} <span class="glyphicon glyphicon-chevron-down"></span></a>
                <ul class="dropdown-menu main-list">
                  <li><a href="{{ path('logout') }}"><i class="glyphicon glyphicon-off"></i> 退出</a></li>
                </ul>
              </li>
        </ul>

      </div><!--/.navbar-collapse -->
    </div>
  </div>

  <div class="container">
    <div class="row">
      {% block content %}

        <div class="col-md-2">
          {% block sidebar %}
            {% for groupedMenus in menu_children('admin', menu_nav.code|default(null)) %}

              <div class="list-group">
                {% for m in groupedMenus %}
                {% set array = {'0':'admin_my_cloud','1':'admin_setting_cloud_video','2':'admin_setting_cloud'} %}
                 {% if m.code not in  array or is_granted('ROLE_SUPER_ADMIN') %}
                            
                  {% if not menu_hiddens[m.code]|default(false)  %}
                    {% set menuClass = m.code == menu_sidebar.code|default(null) ? 'list-group-item active' : 'list-group-item' %}
                    {{ _self.menu_link_html(_context, m, menuClass) }}
                  {% endif %}
                      
                  {% endif %}

                {% endfor %}
              </div>
            {% endfor %}
          {% endblock %}
        </div>

        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">{% block page_title %}{{ menu_current.fullname|default(menu_current.name) }}{% endblock %}</h1>
            <div class="pull-right">

              {% block page_buttons %}
                {% for m in menu_children('admin', menu_current.code, 2) %}
                  {% if not menu_hiddens[m.code]|default(false) %}
                    {{ _self.menu_link_html(_context, m, 'btn btn-success btn-sm') }}
                  {% endif %}
                {% endfor %}
              {% endblock %}

            </div>
          </div>

          {% set menu_breadcrumb_length = menu_breadcrumb|length %}

          {% if menu_breadcrumb_length >= 3 %}
            {% set tabMenus = menu_children('admin', menu_breadcrumb[1].code|default(null), 1) %}
          {% endif %}

          {% if menu_breadcrumb_length >= 4 %}
            {% set subTabMenus = menu_children('admin', menu_breadcrumb[2].code|default(null), 1) %}
          {% endif %}

          {% if tabMenus|default(null) and menu_current.group == 1 %}
            <ul class="nav nav-tabs mbm">
              {% for m in tabMenus %}
                <li {% if m.code == menu_main.code|default(null) %}class="active"{% endif %}>
                  {% if not menu_hiddens[m.code]|default(false) %}
                    {{ _self.menu_link_html(_context, m, m.class|default('')) }}
                  {% endif %}
                </li>
              {% endfor %}
            </ul>
          {% endif %}

          {% if subTabMenus|default(null) and menu_current.group == 1 %}
            <ul class="nav nav-pills mbl small">
              {% for m in subTabMenus %}
                <li {% if m.code == menu_breadcrumb[3].code|default(null) %}class="active"{% endif %}>
                  {% if not menu_hiddens[m.code]|default(false) %}
                    {{ _self.menu_link_html(_context, m) }}
                  {% endif %}
                </li>
              {% endfor %}
            </ul>
          {% endif %}

          {% block main %}{% endblock %}
        </div>

      {% endblock %}
    </div>
  </div>

  {% block footer %}{% endblock %}

  {% include 'TopxiaWebBundle::script_boot.html.twig' with {script_main: asset('bundles/topxiaadmin/js/admin-app.js')} %}
  <div id="modal" class="modal" ></div>
</body>
</html>

{% macro menu_link_html(_context, menu, class) %}
  <a 
  {% if class %}
    class="{{ class }}"
  {% endif %}
  {% if menu.mode|default(null) == 'modal' %}
    data-url="{{ menu_path(menu) }}"
    data-toggle="modal"
    data-target="#modal"
  {% else %}
    href="{{ menu_path(menu) }}"
  {% endif %}
  {% if menu.blank|default(false) %}
    target="blank"
  {% endif %}
  >{{ menu.name }}</a>
{% endmacro %}