{% extends "base.html" %}
{% load i18n %}
{% load misc %}
{% load staticfiles %}

{% block title %}connexion{% endblock %}

{% block disclaimer %}{% endblock %}

{% block head %}
    <!-- LeafLet http://leafletjs.com -->
    <link rel="stylesheet" href="{% static "leaflet/leaflet.css" %}"/>

    <!-- https://github.com/danzel/Leaflet.markercluster -->
    <link rel="stylesheet" href="{% static "leaflet.markercluster/MarkerCluster.css" %}" />
    <link rel="stylesheet" href="{% static "leaflet.markercluster/MarkerCluster.Default.css" %}" />
{% endblock %}

{% block content %}
      <div class="row-fluid">
        <div class="span5">

	  {% if disco_stores_read %}
          <div class="well sidebar-nav" id="discoidp">
            <ul class="nav nav-list">
	      <li data-entityid="">
		      <a id="discoidp" class="discoidp idplink" href="#">Discovery en cours...</a>
	      </li>
	    </ul>
          </div>
	  {% endif %}

	  {% if default_idp %}
          <div class="well sidebar-nav" id="defaultidp">
            <ul class="nav nav-list">
	      <li data-entityid="default_idp.entity_id">
		<a id="defaultidp" class="defaultidp idplink" data-entityid="{{ default_idp.entity_id }}"
			href="sso?entity_id={{ default_idp.entity_id|urlfullencode }}">{{ default_idp.name }}</a>
	      </li>
            </ul>
          </div>
	  {% endif %}

          <p>
            <input class="span12" id="search" type="text" placeholder="Chercher dans la liste…">
          </p>

          <div class="well sidebar-nav">
		  <ul id="idps" class="nav nav-list">{% block idps %}{% endblock %}

            </ul>
          </div><!--/.well -->
        </div><!--/span-->

        <div class="span7">
	  <div class="row-fluid">
	    <div id="map" class="span12">Si la carte ne s'affiche pas, sélectionnez votre établissement d'origine dans la liste.</div>
	  </div>
        </div><!--/span-->

      </div><!--/row-->

{% endblock %}

{% block end %}
<script src="{% static "leaflet/leaflet.js" %}"></script>
<!-- script src="{% static "univnautes/js/Leaflet-Control.Fit.js" %}"></script -->
<script src="{% static "leaflet.markercluster/leaflet.markercluster.js" %}"></script>

{% if disco_stores_read %}
<!-- discovery -->
<script type="text/javascript" src="{% static "simple-disco-store/jquery.qs.js" %}"></script>
<script type="text/javascript" src="{% static "simple-disco-store/discoquery.js" %}"></script>
<script type="text/javascript" src="{% static "simple-disco-store/debug.js" %}"></script>
<script>

	function disco_query() {
		{% for store in disco_stores_read %}
		$.disco_query(
			"https://{{https_hostname}}/authsaml2/metadata",
			"{{ store }}",
			"https://{{https_hostname}}{% static "simple-disco-store/response.html" %}",
			function (entity_id, store, auth) {
				if (entity_id != "{{default_idp.entity_id}}") {
					idp = $('a[data-entityid="' + entity_id + '"]')[0];
					$('div#discoidp a').text(idp.text);
					$('div#discoidp a').attr({
						href: idp.href,
						title: idp.text,
					});
					$("div#discoidp").show();
				}
			});
		{% endfor %}
		}

	function disco_set(idp_entity_id) {
		{% for store in disco_stores_write %}
		$.disco_set(
			"https://{{https_hostname}}/authsaml2/metadata",
			idp_entity_id,
			"{{ store }}",
			"https://{{https_hostname}}{% static "simple-disco-store/response.html" %}",
			function (entity_id, store, auth) {
			});
		{% endfor %}
	}

	$(document).ready(function() {
		$("div#discoidp").hide();
		disco_query();
	});

</script>
{% endif %}

<script>
	var start_bounds = {% if start_bounds %}{{ start_bounds }}{% else %}[[41.1, -5.53], [51.5, 9.91]]{% endif %};
	var start_zoom = 6;
</script>

<script src="{% static "univnautes/js/univnautes.js" %}"></script>

{% endblock %}
