<!-- Add here all common utils macros for Naaya Sites -->

<tal:comment condition="nothing">
<!--
Paginator
---------
- Uses NaayaCore.managers.paginator.ObjectPaginator to render list of objects on pages.

Required variables:
- objects: List of objects to apply paginator;
- num_per_page: number of objects per page;
- orphans: Number of orphans to avoid small final pages (see ObjectPaginator).

Optional:
- paginator: define paginator in upper template;
- label: Text to use before x - y of z, like: Results: 5 - 10 of 300
-->
</tal:comment>

<metal:block define-macro="paginator" tal:define="
	label label|string:;
	objects objects|python:[];
	num_per_page num_per_page|python:50;
	orphans orphans|python:-1;
	query python:dict(request.form);
	page python:query.pop('page', 0);
	query_string python:here.utUrlLibEncode(query);
	query_string python:test(query_string, '?' + query_string + '&amp;page=', '?page=');
	paginator paginator|python:here.getObjectPaginator(objects, num_per_page, orphans);
	curr_page python:paginator.validate_page_number(page);
	left python:paginator.left(curr_page);
	right python:paginator.right(curr_page);
">

<div class="paginator" tal:condition="paginator/hits">
		<div class="cleaner"></div>
	
	<div class="paginator-footer">
		<span i18n:translate="">Showing page</span>
		<!--<label i18n:translate="" tal:content="label" tal:condition="label" />-->
		<span tal:replace="python:curr_page+1" />
		<span i18n:translate="" tal:omit-tag="">of</span>
		<span tal:replace="paginator/pages" />
	</div>
		
	<div class="paginator-head">
		<span i18n:translate="">Showing</span>
		<!--<label i18n:translate="" tal:content="label" tal:condition="label" />-->
		<span tal:replace="python:paginator.first_on_page(curr_page)" /> - <span tal:replace="python:paginator.last_on_page(curr_page)" />
		<span i18n:translate="" tal:omit-tag="">of</span>
		<span tal:replace="paginator/hits" />
		&nbsp;/&nbsp;&nbsp;
	</div>

	<div class="paginator-body">
		<span class="paginator-previous" tal:condition="python:paginator.has_previous_page(curr_page)">
			<a tal:define="page python:curr_page-1" tal:attributes="href string:${query_string}${page}" title="Previous" i18n:attributes="title" i18n:translate="">&laquo;</a>
		</span>
		<span class="paginator-pages" tal:repeat="page python:paginator.page_range[left:right]" tal:condition="python:paginator.pages>1">
			<span tal:condition="python:page==curr_page" tal:content="python:page+1" />
			<a tal:attributes="href string:${query_string}${page}; title python:page+1"
				tal:condition="python:page!=curr_page" tal:content="python:page+1" />
		</span>
		
		<span class="paginator-next" tal:condition="python:paginator.has_next_page(curr_page)">
			<a tal:define="page python:curr_page+1" tal:attributes="href string:${query_string}${page}" title="Next" i18n:attributes="title" i18n:translate="">&raquo;</a>
		</span>
	</div>
</div>

<div class="cleaner">&nbsp;</div>

</metal:block>

<tal:comment condition="nothing">
<!--
AJAX Tree
---------
Uses jsTree (http://www.jstree.com/)
You can find the configuration in jquery.tree.init.js
-->
</tal:comment>

<metal:block define-macro="ajaxtree">
<!-- Styles -->
<metal:block define-slot="styles"></metal:block>

<!-- Scripts -->
<metal:block define-slot="scripts">
	<script type="text/javascript" tal:attributes="src string:${here/absolute_url}/jstree/jquery.tree.min.js"></script>
</metal:block>

<!-- Initialize tree -->

<metal:block define-slot="treeinit">
	<script type="text/javascript" tal:attributes="src string:${here/absolute_url}/jquery_tree_init"></script>
</metal:block>

<metal:block define-slot="treedefinitions">
	<script type="text/javascript"
	tal:define="tree_initial_node tree_initial_node|string:;
				tree_get_url tree_get_url|string:${here/absolute_url}/getNavigationSiteMap/;
				tree_container tree_container|string:.sitemap_tree"
	tal:content="string:
		$(document).ready(function(){
			load_js_tree({
				TREE_URL_PREFIX:'',
				TREE_GET_URL:'${tree_get_url}',
				TREE_INITIAL_NODE:'${tree_initial_node}',
				TREE_CONTAINER:'${tree_container}'
			});
		});"></script>
</metal:block>

</metal:block>
