{# layout.html.twig #}
{# Base layout #}

{% if app['combodo.current_user'] is defined and app['combodo.current_user'] is not null %}
	{% set bUserConnected = true %}
    {% set bUserCanLogOff = app['combodo.current_user'].CanLogOff() %}
	{% set sUserFullname = app['combodo.current_user'].Get('first_name') ~ ' ' ~ app['combodo.current_user'].Get('last_name') %}
	{% set sUserEmail = app['combodo.current_user'].Get('email') %}
	{% set sUserPhotoUrl = app['combodo.current_contact.photo_url'] %}
{% else %}
	{% set bUserConnected = false %}
    {% set bUserCanLogOff = false %}
	{% set sUserFullname = '' %}
	{% set sUserEmail = '' %}
	{% set sUserPhotoUrl = app['combodo.portal.base.absolute_url'] ~ 'img/user-profile-default-256px.png' %}
{% endif %}

<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	{# This block can be used to add your own meta tags by extending the default template #}
	{% block pPageExtraMetas %}
	{% endblock %}
	<title>{% block pPageTitle %}{% if sPageTitle is defined and sPageTitle is not null %}{{ sPageTitle }} - {{ constant('ITOP_APPLICATION_SHORT') }}{% else %}{{ 'Page:DefaultTitle'|dict_format(constant('ITOP_APPLICATION_SHORT')) }}{% endif %}{% endblock %}</title>
    <link rel="shortcut icon" href="{{ app['combodo.portal.instance.conf'].properties.favicon|add_itop_version }}"/>

	{% block pPageStylesheets %}
        {# First bootstrap core, lib themes, then bootstrap theme, portal adjustements #}
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/bootstrap/css/bootstrap.min.css'|add_itop_version }}" rel="stylesheet">
        {# - Bootstrap Datetime picker #}
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css'|add_itop_version }}" rel="stylesheet">
        {# - Datatables #}
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/datatables/css/dataTables.bootstrap.min.css'|add_itop_version }}" rel="stylesheet">
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/datatables/css/fixedHeader.bootstrap.min.css'|add_itop_version }}" rel="stylesheet">
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/datatables/css/responsive.bootstrap.min.css'|add_itop_version }}" rel="stylesheet">
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/datatables/css/scroller.bootstrap.min.css'|add_itop_version }}" rel="stylesheet">
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/datatables/css/select.bootstrap.min.css'|add_itop_version }}" rel="stylesheet">
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/datatables/css/select.dataTables.min.css'|add_itop_version }}" rel="stylesheet">
        {# - Font OpenSans #}
        <link href="{{ app['combodo.absolute_url'] ~ 'css/font-open-sans/font-open-sans.css'|add_itop_version }}" rel="stylesheet">
        {# - Font Combodo #}
        <link href="{{ app['combodo.absolute_url'] ~ 'css/font-combodo/font-combodo.css'|add_itop_version }}" rel="stylesheet">
        {# - Font awesome #}
        <link href="{{ app['combodo.absolute_url'] ~ 'css/font-awesome/css/all.min.css'|add_itop_version }}" rel="stylesheet">
        {# - Misc libs #}
        <link href="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/typeahead/css/typeaheadjs.bootstrap.css'|add_itop_version }}" rel="stylesheet">
        <link href="{{ app['combodo.absolute_url'] ~ 'css/selectize.default.css'|add_itop_version }}" rel="stylesheet">
        <link href="{{ app['combodo.absolute_url'] ~ 'node_modules/magnific-popup/dist/magnific-popup.css'|add_itop_version }}" rel="stylesheet">
		<link href="{{ app['combodo.absolute_url'] ~ 'node_modules/c3/c3.min.css'|add_itop_version }}" rel="stylesheet">
		{# - Bootstrap theme #}
		<link href="{{ app['combodo.absolute_url'] ~ app['combodo.portal.instance.conf'].properties.themes.bootstrap|add_itop_version }}" rel="stylesheet" id="css_bootstrap_theme">
		{# - Portal adjustments for BS theme #}
		<link href="{{ app['combodo.absolute_url'] ~ app['combodo.portal.instance.conf'].properties.themes.portal|add_itop_version }}" rel="stylesheet" id="css_portal">
		{# Tippy for tooltips and Popper for their placement #}
		<link href="{{ app['combodo.absolute_url'] ~ 'node_modules/tippy.js/dist/tippy.css'|add_itop_version }}" rel="stylesheet">
		<link href="{{ app['combodo.absolute_url'] ~ 'node_modules/tippy.js/animations/shift-away-subtle.css'|add_itop_version }}" rel="stylesheet">
		{# UI Extensions CSS, in an undefined order #}
        {% if app['ui_extensions_helper'].css_files is defined %}
            {% for css_file in app['ui_extensions_helper'].css_files %}
				<link href="{{ css_file|add_itop_version }}" rel="stylesheet">
            {% endfor %}
        {% endif %}
		{# Custom CSS that is supposed to do adjustments to the portal #}
		{% if app['combodo.portal.instance.conf'].properties.themes.custom is defined %}
			<link href="{{ app['combodo.absolute_url'] ~ app['combodo.portal.instance.conf'].properties.themes.custom|add_itop_version }}" rel="stylesheet">
		{% endif %}
		{# Others CSS that will come after the theme/portal/custom, in an undefined order #}
		{% if app['combodo.portal.instance.conf'].properties.themes.others is defined %}
			{% for theme in app['combodo.portal.instance.conf'].properties.themes.others %}
				<link href="{{ app['combodo.absolute_url'] ~ theme|add_itop_version }}" rel="stylesheet">
			{% endfor %}
		{% endif %}
	{% endblock %}

	{% block pStyleinline %}
        {# UI Extensions inline CSS #}
        {% if app['ui_extensions_helper'].css_inline is not null %}
            <style>
                {{ app['ui_extensions_helper'].css_inline|raw }}
            </style>
        {% endif %}
	{% endblock %}

	{% block pPageScripts %}
		<script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/jquery/dist/jquery.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/ajax_hook.js'|add_itop_version }}"></script>
		{% if is_development_environment() %}
				<script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/jquery-migrate/dist/jquery-migrate.js'|add_itop_version }}"></script>
		{% else %}
				<script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/jquery-migrate/dist/jquery-migrate.min.js'|add_itop_version }}"></script>
        {% endif %}
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/jquery-ui-dist/jquery-ui.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/magnific-popup/dist/jquery.magnific-popup.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/blueimp-file-upload/js/jquery.iframe-transport.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/blueimp-file-upload/js/jquery.fileupload.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/utils.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/toolbox.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/d3/d3.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/c3/c3.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/bootstrap/js/bootstrap.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/bootstrap-patches.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/bootstrap-portal-modal.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/latinise/latinise.min.js'|add_itop_version }}"></script>
        {# Tippy for tooltips and Popper for their placement #}
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/@popperjs/core/dist/umd/popper.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/tippy.js/dist/tippy-bundle.umd.js'|add_itop_version }}"></script>
        {# Visible.js to check if an element is visible on screen #}
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/jquery-visible/js/jquery.visible.min.js'|add_itop_version }}"></script>
        {# Base64.js #}
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/jquery-base64/js/jquery.base64.min.js'|add_itop_version }}"></script>
        {# Moment.js with locales #}
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/moment/min/moment-with-locales.min.js'|add_itop_version }}"></script>
        {# Datatables #}
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/datatables.net/js/jquery.dataTables.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/datatables/js/dataTables.bootstrap.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/datatables.net-responsive/js/dataTables.responsive.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/datatables.net-scroller/js/dataTables.scroller.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/datatables.net-select/js/dataTables.select.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/datatables/js/datetime-moment.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/dataTables.accentNeutraliseForFilter.js'|add_itop_version }}"></script>
        {# Export for Datatables #}
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/export.js'|add_itop_version }}"></script>
        {# CKEditor files for HTML WYSIWYG #}
        {{ inject_ckeditor_resources()|raw }}
        {# - Highlighter for code snippets created with CKEditor #}
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/highlight/highlight.min.js'|add_itop_version }}"></script>
        {# Date-time picker for Bootstrap #}
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'|add_itop_version }}"></script>
        {# Typeahead files for autocomplete #}
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/typeahead/js/typeahead.bundle.min.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'lib/handlebars/js/handlebars.min-768ddbd.js'|add_itop_version }}"></script>

        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/leave_handler.js'|add_itop_version }}"></script>

        {# Selectize for sets #}
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/selectize.js'|add_itop_version }}"></script>
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/jquery.itop-set-widget.js'|add_itop_version }}"></script>
        {# Form files #}
        <script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/form_handler.js'|add_itop_version }}"></script>
		<script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/form_field.js'|add_itop_version }}"></script>
		<script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/subform_field.js'|add_itop_version }}"></script>
		<script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/field_set.js'|add_itop_version }}"></script>
		{# Form files for portal #}
		<script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/portal_form_handler.js'|add_itop_version }}"></script>
		<script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/portal_form_field.js'|add_itop_version }}"></script>
		<script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/portal_form_field_html.js'|add_itop_version }}"></script>
		<script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/portal_form_field_set.js'|add_itop_version }}"></script>
		{# Clipboard helper #}
		<script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'node_modules/clipboard/dist/clipboard.min.js'|add_itop_version }}"></script>
		<script type="text/javascript" src="{{ app['combodo.absolute_url'] ~ 'js/clipboardwidget.js'|add_itop_version }}"></script>
		<script type="text/javascript" src="{{ app['combodo.portal.base.absolute_url'] ~ 'js/portal-clipboard.js'|add_itop_version }}"></script>

		{# UI Extensions JS, in an undefined order #}
		{% if app['ui_extensions_helper'].js_files is defined %}
			{% for js_file in app['ui_extensions_helper'].js_files %}
				<script type="text/javascript" src="{{ js_file|add_itop_version }}"></script>
			{% endfor %}
        {% endif %}
	{% endblock %}
</head>
<body class="{% block pPageBodyClass %}{% endblock %}" data-gui-type="portal">
	{% block pPageBodyWrapper %}
		{% block pEnvBannerWrapper %}
			{% if app['combodo.current_environment'] != 'production' %}
				<div id="envbanner" class="alert alert-danger" role="alert">
					{{ 'Portal:EnvironmentBanner:Title'|dict_format( app['combodo.current_environment']|upper )|raw }}
					<button type="button" onclick="window;location.href='{{ app['url_generator'].generate('p_home', {'switch_env': 'production'}) }}'">
						{{ 'Portal:EnvironmentBanner:GoToProduction'|dict_s|raw }}
					</button>
				</div>
			{% endif %}
		{% endblock %}
		
		{% block pNavigationWrapper %}
			{# Topbar navigation menu for mobile screens #}
			{% block pNavigationTopMenuWrapper %}
				<nav class="navbar navbar-fixed-top navbar-default visible-xs" id="topbar" role="navigation">
					<div class="container-fluid">
						<div class="navbar-header">
							<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
								<span class="icon-bar"></span>
								<span class="icon-bar"></span>
								<span class="icon-bar"></span>
							</button>
							{% block pNavigationTopMenuLogo %}
								<a class="navbar-brand pull-right" href="{{ app['combodo.conf.app_icon_url'] }}">
									{% if app['combodo.portal.instance.conf'].properties.logo is not null %}
										<img src="{{ app['combodo.portal.instance.conf'].properties.logo }}" alt="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}" />
									{% else %}
										iTop
									{% endif %}
								</a>
							{% endblock %}
							<p class="navbar-text">
								<a class="navbar-link user_infos" href="{{ app.url_generator.generate('p_user_profile_brick') }}">
									<span class="user_photo" style="background-image: url('{{ sUserPhotoUrl }}');"></span>
									<span class="user_fullname">{{ sUserFullname }}</span>
								</a>
							</p>
						</div>
						<div class="collapse navbar-collapse" id="navbar">
							<ul class="nav navbar-nav">
								{% block pNavigationTopBricks %}
									<li class="brick_menu_item {% if oBrick is not defined %}active{% endif %}">
										<a href="{{ app.url_generator.generate('p_home') }}">
											<span class="brick_icon fas fa-home fa-2x"></span>
											{{ 'Page:Home'|dict_s }}
										</a>
									</li>
									{% for brick in app['brick_collection'].navigation_menu_ordering %}
										{% if brick.GetActive and brick.GetVisibleNavigationMenu and brick.GetRouteName is not null %}
											<li class="brick_menu_item {% if oBrick is defined and brick.id == oBrick.id %}active{% endif %}" data-brick-id="{{ brick.GetId }}">
												<a href="{{ app.url_generator.generate(brick.GetRouteName, {sBrickId: brick.GetId}) }}{% if app['combodo.portal.instance.routes'][brick.GetRouteName]['hash'] is defined %}#{{ app['combodo.portal.instance.routes'][brick.GetRouteName]['hash'] }}{% endif %}" {% if app['combodo.portal.instance.routes'][brick.GetRouteName]['navigation_menu_attr'] is defined %}{% for key, value in app['combodo.portal.instance.routes'][brick.GetRouteName]['navigation_menu_attr'] %} {{ key }}="{{ value }}"{% endfor %}{% endif %} {% if brick.GetModal %}data-toggle="modal" data-target="#modal-for-all"{% endif %}>
													<span class="brick_icon {{ brick.GetDecorationClassNavigationMenu }}"></span>
													{{ brick.GetTitleNavigationMenu|dict_s }}
												</a>
											</li>
										{% endif %}
									{% endfor %}
								{% endblock %}
								{% if bUserConnected %}
									<li role="separator" class="divider"></li>
                                    <li><a href="{{ app.url_generator.generate('p_user_profile_brick') }}"><span class="brick_icon fas fa-user fa-2x fa-fw"></span>{{ 'Brick:Portal:UserProfile:Navigation:Dropdown:MyProfil'|dict_s }}</a></li>
									{% for aPortal in allowed_portals %}
										{% if aPortal.id != app['combodo.portal.instance.conf'].properties.id %}
											{% set sIconClass = (aPortal.id == 'backoffice') ? 'far fa-list-alt' : 'fas fa-external-link-alt' %}
											<li><a href="{{ aPortal.url }}" target="_blank"><span class="brick_icon {{ sIconClass }} fa-2x fa-fw"></span>{{ aPortal.label|dict_s }}</a></li>
										{% endif %}
									{% endfor %}
                                    {% if bUserCanLogOff %}
                                        {# We display the separator only if the user has more then 1 portal. Meaning default portal + console or several portal at least #}
									    {% if allowed_portals|length > 1 %}
                                            <li role="separator" class="divider"></li>
                                        {% endif %}
									    <li><a href="{{ app['combodo.absolute_url'] }}pages/logoff.php"><span class="brick_icon fas fa-sign-out-alt fa-2x fa-fw"></span>{{ 'Brick:Portal:UserProfile:Navigation:Dropdown:Logout'|dict_s }}</a></li>
                                    {% endif %}
								{% endif %}
							</ul>
						</div>

                        {% block pPageUIExtensionNavigationMenuTopbar %}
                            {% if app['ui_extensions_helper'].html[constant('iPortalUIExtension::ENUM_PORTAL_EXT_UI_NAVIGATION_MENU')] is defined %}
                                {{ app['ui_extensions_helper'].html[constant('iPortalUIExtension::ENUM_PORTAL_EXT_UI_NAVIGATION_MENU')]|raw }}
                            {% endif %}
                        {% endblock %}
					</div>
				</nav>
			{% endblock %}

			{# Sidebar navigation menu for normal screens #}
			{% block pNavigationSideMenuWrapper %}
				<nav class="navbar-default hidden-xs col-sm-3 col-md-2" id="sidebar" role="navigation">
					<div class="user_card bg-primary">
						<div class="user_photo" style="background-image: url('{{ sUserPhotoUrl }}');">
						</div>
						<div class="user_infos">
							<div class="user_fullname">{{ sUserFullname }}</div>
							<div class="user_email dropdown">
								<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="user_options">
									{{ sUserEmail }}
									<span class="caret"></span>
								</a>
								<ul class="dropdown-menu user_options" aria-labelledby="user_options">
									<li><a href="{{ app.url_generator.generate('p_user_profile_brick') }}"><span class="brick_icon fas fa-user fa-lg fa-fw"></span>{{ 'Brick:Portal:UserProfile:Navigation:Dropdown:MyProfil'|dict_s }}</a></li>
									{% for aPortal in allowed_portals %}
										{% if aPortal.id != app['combodo.portal.instance.conf'].properties.id %}
											{% set sGlyphiconClass = (aPortal.id == 'backoffice') ? 'far fa-list-alt' : 'fas fa-external-link-alt' %}
											<li><a href="{{ aPortal.url }}" {% if app['combodo.portal.instance.conf'].properties.allowed_portals.opening_mode == 'tab' %}target="_blank"{% endif %} title="{{ aPortal.label|dict_s }}"><span class="brick_icon {{ sGlyphiconClass }} fa-lg fa-fw"></span>{{ aPortal.label|dict_s }}</a></li>
										{% endif %}
									{% endfor %}
                                    {% if bUserCanLogOff %}
                                        {# We display the separator only if the user has more then 1 portal. Meaning default portal + console or several portal at least #}
									    {% if allowed_portals|length > 1 %}
                                            <li role="separator" class="divider"></li>
                                        {% endif %}
									    <li><a href="{{ app['combodo.absolute_url'] }}pages/logoff.php"><span class="brick_icon fas fa-sign-out-alt fa-lg fa-fw"></span>{{ 'Brick:Portal:UserProfile:Navigation:Dropdown:Logout'|dict_s }}</a></li>
                                    {% endif %}
								</ul>
							</div>
						</div>
					</div>
					<div class="menu">
						{% block pNavigationSideMenu %}
							<ul class="nav navbar-nav">
								<li class="brick_menu_item {% if oBrick is not defined %}active{% endif %}">
									<a href="{{ app.url_generator.generate('p_home') }}">
										<span class="brick_icon fas fa-home fa-2x"></span>
										{{ 'Page:Home'|dict_s }}
									</a>
								</li>
								{% for brick in app['brick_collection'].navigation_menu_ordering %}
									{% if brick.GetActive and brick.GetVisibleNavigationMenu and brick.GetRouteName is not null %}
										<li class="brick_menu_item {% if oBrick is defined and brick.id == oBrick.id %}active{% endif %}" data-brick-id="{{ brick.GetId }}">
											<a href="{{ app.url_generator.generate(brick.GetRouteName, {sBrickId: brick.GetId}) }}{% if app['combodo.portal.instance.routes'][brick.GetRouteName]['hash'] is defined %}#{{ app['combodo.portal.instance.routes'][brick.GetRouteName]['hash'] }}{% endif %}" {% if app['combodo.portal.instance.routes'][brick.GetRouteName]['navigation_menu_attr'] is defined %}{% for key, value in app['combodo.portal.instance.routes'][brick.GetRouteName]['navigation_menu_attr'] %} {{ key }}="{{ value }}"{% endfor %}{% endif %} {% if brick.GetModal %}data-toggle="modal" data-target="#modal-for-all"{% endif %}>
												<span class="brick_icon {{ brick.GetDecorationClassNavigationMenu }}"></span>
												{{ brick.GetTitleNavigationMenu|dict_s }}
											</a>
										</li>
									{% endif %}
								{% endfor %}
							</ul>
						{% endblock %}
					</div>

                    {% block pPageUIExtensionNavigationMenuSidebar %}
                        {% if app['ui_extensions_helper'].html[constant('iPortalUIExtension::ENUM_PORTAL_EXT_UI_NAVIGATION_MENU')] is defined %}
                            {{ app['ui_extensions_helper'].html[constant('iPortalUIExtension::ENUM_PORTAL_EXT_UI_NAVIGATION_MENU')]|raw }}
                        {% endif %}
                    {% endblock %}

					{% if app['combodo.portal.instance.conf'].properties.logo is not null %}
						<div class="logo">
							{% block pNavigationSideMenuLogo %}
								{# This is a debug helper to know in which screen size we are #}
								{% if app['kernel'].debug == true %}
									<div style="position: fixed; bottom: 0px; left: 0px; z-index: 9999;">Debug: Screen size <span class="hidden-sm hidden-md hidden-lg">XS</span><span class="hidden-xs hidden-md hidden-lg">SM</span><span class="hidden-xs hidden-sm hidden-lg">MD</span><span class="hidden-xs hidden-sm hidden-md">LG</span></div>
								{% endif %}
								<a href="{{ app['combodo.conf.app_icon_url'] }}" title="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}">
									<img src="{{ app['combodo.portal.instance.conf'].properties.logo }}" alt="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}" />
								</a>
							{% endblock %}
						</div>
					{% endif %}
				</nav>
			{% endblock %}
		{% endblock %}
		
		{% block pMainWrapper %}
		<div class="container-fluid" id="main-wrapper">
			<div class="row">
				<div class="col-xs-12 col-sm-9 col-md-10 col-sm-offset-3 col-md-offset-2">
                    <section class="row">
						<div class="col-xs-12">
                            {% include template('session_messages') %}
						</div>
					</section>
					<section class="row" id="main-header">
						{% block pMainHeader %}
						{% endblock %}
					</section>
					<section class="row" id="main-content">
						{% block pMainContent %}
						{% endblock %}
					</section>
				</div>
			</div>

			{% block pPageUIExtensionMainContent %}
                {% if app['ui_extensions_helper'].html[constant('iPortalUIExtension::ENUM_PORTAL_EXT_UI_MAIN_CONTENT')] is defined %}
                    {{ app['ui_extensions_helper'].html[constant('iPortalUIExtension::ENUM_PORTAL_EXT_UI_MAIN_CONTENT')]|raw }}
                {% endif %}
			{% endblock %}
		</div>
		{% endblock %}
		
		<footer id="footer-wrapper">
			{% block pPageFooter%}
				{#<a href="http://www.combodo.com">iTop &copy; {{ "now"|date('Y') }}</a>#}
			{% endblock %}
		</footer>
	
		{% block pModalForAllWrapper %}
			<div class="modal fade" id="modal-for-all" role="dialog" tabindex="-1">
				<div class="modal-dialog modal-lg" role="document">
					<div class="modal-content">
                        {% include template('loader') %}
					</div>
				</div>
			</div>
		{% endblock %}
		{% block pModalForAlert %}
			<div class="modal fade" id="modal-for-alert" role="dialog" tabindex="-1">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="{{ 'Portal:Button:Close'|dict_s }}"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title"></h4>
						</div>
						<div class="modal-body">
							<div class="alert">
							</div>
							<div class="text-right">
								<button type="button" class="btn btn-primary" data-dismiss="modal">{{ 'Portal:Button:Close'|dict_s }}</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		{% endblock %}

		{% block pPageOverlay %}
			<div id="page_overlay" class="global_overlay">
				<div class="overlay_content">
                    {% include template('loader') %}
				</div>
			</div>
		{% endblock %}

		{% block pPageUIExtensionBody %}
			{% if app['ui_extensions_helper'].html[constant('iPortalUIExtension::ENUM_PORTAL_EXT_UI_BODY')] is defined %}
				{{ app['ui_extensions_helper'].html[constant('iPortalUIExtension::ENUM_PORTAL_EXT_UI_BODY')]|raw }}
			{% endif %}
		{% endblock %}
	{% endblock %}
	
	{% block pPageLiveScripts %}
		<script type="text/javascript">
			{% block pPageLiveScriptHelpers %}
				// Helper to get the application root url
				var GetAbsoluteUrlAppRoot = function()
				{
					return '{{ app['combodo.absolute_url'] }}';
				};
				// Note: We might want to expose URLs instead of this kind of stuff... 🤔
				var GetAddSessionMessageUrl = function()
				{
					return '{{ app['url_generator'].generate('p_session_message_add')|raw }}';
				};
				/**
				 * @param sUrl {string} The URL to append the new param to
				 * @param sParamName {string} Name of the parameter
				 * @param sParamValue {string} Value of the param, needs to be already URL encoded
				 * @return {string} The sUrl parameters with the sParamName / sParamValue append at the right place
				 * @deprecated 3.0.0 N°4176
				 */
				var AddParameterToUrl = function(sUrl, sParamName, sParamValue)
				{
					sUrl += (sUrl.split('?')[1] ? '&':'?') + sParamName + '=' + sParamValue;
					return sUrl;
				};
				// Test is sString is a valid JSON string
				// TODO 3.0.0: Move to CombodoGlobalToolbox and deprecate this one
				var IsJSONString = function(sString)
				{
					try {
						JSON.parse(sString);
					} catch (oException) {
						return false;
					}
					return true;
				};
				// TODO 3.0.0: Move to CombodoPortalToolbox and deprecate this one
				var GetContentLoaderTemplate = function()
				{
					return '<div class="content_loader"><div class="icon glyphicon glyphicon-refresh"></div><div class="message">{{ 'Page:PleaseWait'|dict_s }}</div></div>';
				};
				// TODO 3.0.0: Move to CombodoPortalToolbox and deprecate this one
				var ShowLoginDialog = function()
				{
                    var oModalElem = $('#modal-for-alert').clone();
                    oModalElem.attr('id', '');
                    oModalElem.find('.modal-content .modal-header .modal-title').html('{{ 'Error:HTTP:401'|dict_s|escape('js') }}');
                    oModalElem.find('.modal-content .modal-body .alert').addClass('alert-danger').html('{{ 'Portal:ErrorUserLoggedOut'|dict_s|escape('js') }}');

                    oModalElem.find('.modal-content .modal-body button').replaceWith( $('<button type="button" class="btn btn-primary" onclick="javascript:window.location.reload();">{{ 'UI:LogOff:ClickHereToLoginAgain'|dict_s|escape('js') }}</button>') );

                    oModalElem.appendTo('body');
                    oModalElem.modal('show');
				};
				// TODO 3.0.0: Move to CombodoPortalToolbox and deprecate this one
				var ShowErrorDialog = function(sBody, sTitle)
				{
				    if(sTitle === undefined)
					{
					    sTitle = '{{ 'Error:HTTP:500'|dict_s|escape('js') }}';
					}
				    if(sBody === undefined)
					{
                        sBody = '{{ 'Error:XHR:Fail'|dict_format(constant('ITOP_APPLICATION_SHORT'))|escape('js') }}';
					}
					var oModalElem = $('#modal-for-alert');
                    oModalElem.find('.modal-content .modal-header .modal-title').text(sTitle);
                    oModalElem.find('.modal-content .modal-body .alert').addClass('alert-danger').text(sBody);
                    oModalElem.modal('show');
				};
			{% endblock %}

            $(document).ready(function ()
            {
                const oBodyElem = $('body');

                {% block pPageReadyScripts %}
					// Add proprietary header to identify our XHR calls
					$(document).ajaxSend(function(oEvent, oXHR, oOptions) {
						oXHR.setRequestHeader('X-Combodo-Ajax', 'true');
					});
					// Handle AJAX errors (exceptions (500), logout (401), ...)
					$(document).ajaxError(function(oEvent, oXHR, oSettings, sError){
					    if(oXHR.status === 401)
						{
						    ShowLoginDialog();
						}
                        else if(oXHR.status === 404)
                        {
                            ShowErrorDialog('{{ 'UI:ObjectDoesNotExist'|dict_s|escape('js') }}', '{{ 'Error:HTTP:404'|dict_s|escape('js') }}');
                        }
                      else if(oXHR.status === 0 && oXHR.readyState === 0)
                        {
                            //DO NOTHING the ajax call has been aborted
                        }
                        else if(oXHR.responseText !== undefined && IsJSONString(oXHR.responseText) === true)
                        {
                            var oData = JSON.parse(oXHR.responseText);
                            // Catching AJAX exception with detailed error.
                            if( (oData.error_message !== undefined) && (oData.error_title !== undefined) )
                            {
                                ShowErrorDialog(oData.error_message, oData.error_title);
                            } else
                            {
                                ShowErrorDialog();
                            }
                        } else
                        {
                            ShowErrorDialog();
                        }
                    });
                // All processing that should be done on an ajax return
                $(document).ajaxSuccess(function ()
                {
                    // Init tooltips from async. markup, small timeout to allow markup to be built if necessary
                    setTimeout(function ()
                    {
                        CombodoTooltip.InitAllNonInstantiatedTooltips();
                    }, 1000);
                });

                // Enable tooltips based on existing HTML markup, for markup added dynamically after DOM ready (AJAX, ...) see .ajaxSuccess()...
                CombodoTooltip.InitAllNonInstantiatedTooltips();
                // ... object form which are handled with the following
                oBodyElem.on('form_built', function (oEvent)
                {
                    CombodoTooltip.InitAllNonInstantiatedTooltips($(oEvent.target), true);
                });
                // ... refresh of the dataTables
                oBodyElem.on('init.dt draw.dt', function (oEvent)
                {
                    CombodoTooltip.InitAllNonInstantiatedTooltips($(oEvent.target), true);
                });

                // Initialize confirmation message handler when a form with touched fields is closed
                oBodyElem.leave_handler({
                    'message': '{{ 'Portal:Form:Close:Warning'|dict_s }}',
                    'extra_events': {
                        'body': ['hide.bs.modal']
                    }
                });
                {% endblock %}
			});
		</script>
	{% endblock %}

	{% block pPageExtensionsScripts %}
        {# UI Extensions inline JS #}
        {% if app['ui_extensions_helper'].js_inline is not null %}
			<script type="text/javascript">
				{{ app['ui_extensions_helper'].js_inline|raw }}
			</script>
        {% endif %}
	{% endblock %}
</body>
</html>
