{% macro menu_block(lst_menu) %}
	{% for item1 in lst_menu %}
		{% if item1 | is_menu_visible %}
			<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
			{{_(item1.name)}}<b class="caret"></b></a>
		        <ul class="dropdown-menu">
			{% for item2 in item1.childs %}
				{% if item2.childs %}
					<li class="dropdown">
                        	        <a tabindex="-1" href="{{item2.href}}">
                        	        <span class="glyphicon glyphicon-{{item2.icon}}"></span> - {{_(item2.name)}}</a>
					</li>
				{% else %}
					{% if item2.name == '-' %}
                                        	<li class="divider"></li>
                                	{% else %}
						{% if item2 | is_menu_visible %}
						<li><a tabindex="-1" href="{{item2.href}}">
						<span class="glyphicon glyphicon-{{item2.icon}}"></span> - {{_(item2.name)}}</a></li>
						{% endif %}
					{% endif %}
				{% endif %}
			{% endfor %}
			</ul></li>
		{% endif %}
        {% endfor %}
{% endmacro %}

{% macro locale_menu(languages) %}
{% set locale = session['locale'] %}
{% if not locale %}
	{% set locale = 'en' %}
{% endif %}
<li class="dropdown">
	<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
	<ul class="f16"><li class="flag {{languages[locale].get('flag')}}"></li></ul>
	</a>
	<ul class="dropdown-menu">
	<li class="dropdown">
		{% for lang in languages %}
			{% if lang != locale %}
        		<a tabindex="-1" href="/lang/{{lang}}?next={{request.path}}">
        		<ul class="f16"><li class="flag {{languages[lang].get('flag')}}"></li> - {{languages[lang].get('name')}}</ul>
        		</a>
        		{% endif %}
        	{% endfor %}
        </li>
        </ul>
</li>
{% endmacro %}       

{% macro navbar_block(app_name, lst_menu, languages) %}
<div class="navbar navbar-inverse" role="navigation">
   <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>
                <span class="navbar-brand">{{app_name}}</span>
        </div>
        <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                        <li><a href="/">Home</a></li>
                        {{ menu_block(lst_menu) }}
                </ul>
                <ul class="nav navbar-nav navbar-right">
                {{ locale_menu(languages) }}
                {% if not current_user.is_anonymous() %}
				<li><a href="/logout">Logout</a></li>
                                <li><a class="pull-right" href="/users/userinfo">User: {{g.user.get_full_name()}}</a></li>
                {% else %}
                                <li><a href="/login">Login</a></li>
                {% endif %}
                </ul>
        </div>
   </div>
</div>

{% endmacro %}
