<!DOCTYPE html>
{% load staticfiles %}

{# TODO: change lang? #}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
    <title>{% block title %}Celutz, a panorama viewer{% endblock title %}</title>

    <link type="image/x-icon" rel="shortcut icon" href="{% static "panorama/img/tsf.png" %}"/>

    <link href="{% static "panorama/css/bootstrap.css" %}" rel="stylesheet" media="screen">
    <link href="{% static "panorama/css/sb-admin.css" %}" rel="stylesheet" media="screen">
    <link href="{% static "panorama/css/plugins/morris.css" %}" rel="stylesheet" media="screen">
    <link href="{% static "panorama/font-awesome/css/font-awesome.min.css" %}" rel="stylesheet" type="text/css">
    {% block css %}{% endblock css %}

    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  </head>

  <body>
    {# Add base structure here, menu, etc... #}

   <div id="wrapper">
        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="{% url 'panorama:main' %}">Celutz</a>
            </div>
            <!-- Top Menu Items -->
            <ul class="nav navbar-right top-nav">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-envelope"></i> <b class="caret"></b></a>
                    <ul class="dropdown-menu message-dropdown">
                        <li class="message-preview">
                            <a href="#">
                                <div class="media">
                                    <span class="pull-left">
                                        <img class="media-object" src="http://placehold.it/50x50" alt="">
                                    </span>
                                    <div class="media-body">
                                        <h5 class="media-heading"><strong>John Smith</strong>
                                        </h5>
                                        <p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
                                        <p>Lorem ipsum dolor sit amet, consectetur...</p>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="message-preview">
                            <a href="#">
                                <div class="media">
                                    <span class="pull-left">
                                        <img class="media-object" src="http://placehold.it/50x50" alt="">
                                    </span>
                                    <div class="media-body">
                                        <h5 class="media-heading"><strong>John Smith</strong>
                                        </h5>
                                        <p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
                                        <p>Lorem ipsum dolor sit amet, consectetur...</p>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="message-preview">
                            <a href="#">
                                <div class="media">
                                    <span class="pull-left">
                                        <img class="media-object" src="http://placehold.it/50x50" alt="">
                                    </span>
                                    <div class="media-body">
                                        <h5 class="media-heading"><strong>John Smith</strong>
                                        </h5>
                                        <p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
                                        <p>Lorem ipsum dolor sit amet, consectetur...</p>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="message-footer">
                            <a href="#">Read All New Messages</a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bell"></i> <b class="caret"></b></a>
                    <ul class="dropdown-menu alert-dropdown">
                        <li>
                            <a href="#">Alert Name <span class="label label-default">Alert Badge</span></a>
                        </li>
                        <li>
                            <a href="#">Alert Name <span class="label label-primary">Alert Badge</span></a>
                        </li>
                        <li>
                            <a href="#">Alert Name <span class="label label-success">Alert Badge</span></a>
                        </li>
                        <li>
                            <a href="#">Alert Name <span class="label label-info">Alert Badge</span></a>
                        </li>
                        <li>
                            <a href="#">Alert Name <span class="label label-warning">Alert Badge</span></a>
                        </li>
                        <li>
                            <a href="#">Alert Name <span class="label label-danger">Alert Badge</span></a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">View All</a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> À propos<b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li>
                           <p>Celutz is a tool for managing and referencing panoramic photos.
                           <a href="https://code.ffdn.org/FFDN/celutz/">Project homepage</a>
                        </li>
                    </ul>
                </li>
            </ul>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <div class="collapse navbar-collapse navbar-ex1-collapse">
              <ul class="nav navbar-nav side-nav">
                <li>
                  <a href="{% url 'panorama:main' %}"><i class="fa fa-fw fa-home"></i> Map</a>
                </li>
                    <li>
                      <a href="javascript:;" data-toggle="collapse" data-target="#panos"><i class="fa fa-fw fa-arrows-v"></i> Panoramas<i class="fa fa-fw fa-caret-down"></i></a>
                      <ul id="panos" class="collapse">
                        {% for pano in panoramas %}
                        <li><a href="{% url 'panorama:view_pano' pano.id %}"><i class="fa fa-fw fa-eye"></i> {{ pano.name }}</a></li>
                        {% endfor %}
                      </ul>
                    </li>
                    <li>
                        <a href="javascript:;" data-toggle="collapse" data-target="#locate-existing"><i class="fa fa-fw fa-arrows-v"></i> Locate existing point<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="locate-existing" class="collapse">
                            <li>
                                <form action="{% url 'panorama:locate_refpoint' %}" enctype="multipart/form-data" method="post">{% csrf_token %}
                                  {{ refpoints_form.as_p }}
                                  <input type="submit" value="Locate" />
                                </form>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a href="javascript:;" data-toggle="collapse" data-target="#locate-gps"><i class="fa fa-fw fa-arrows-v"></i> Locate GPS point<i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="locate-gps" class="collapse">
                            <li>
                                <form action="{% url 'panorama:locate_custompoint' %}" enctype="multipart/form-data" method="post">{% csrf_token %}
                                  {{ custom_point_form.as_p }}
                                  <input type="submit" value="Locate" />
                                </form>
                            </li>
                        </ul>
                    </li>
                    <li>
                      <a href="{% url 'panorama:new' %}"><i class="fa fa-fw fa-edit"></i> Add new panorama</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </nav>
        <div id="page-wrapper">

            <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
            <div id="map" style="height: 500px; "></div>
            <style>
            body{overflow : scroll;}
            </style>
            <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
            <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
            <script>
              var map;
              var ajaxRequest;
              var plotlist;
              var plotlayers=[];
            
              function initmap() {
                // set up the map
                map = new L.Map('map');
            
                // create the tile layer with correct attribution
                var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
                var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
                var osm = new L.TileLayer(osmUrl, {attribution: osmAttrib});
                // start the map in Grenoble
                map.setView(new L.LatLng(45.1842, 5.7218),13);
                map.addLayer(osm);
            
                // Add in a crosshair for the map
                var crosshairIcon = L.icon({
                    iconUrl: 'images/crosshair.png',
                    iconSize:     [20, 20], // size of the icon
                    iconAnchor:   [10, 10], // point of the icon which will correspond to marker's location
                  });
                crosshair = new L.marker(map.getCenter(), {clickable:false});
                crosshair.addTo(map);
            
                // Move the crosshair to the center of the map when the user pans
                map.on('move', function(e) {
                    crosshair.setLatLng(map.getCenter());
                  });
            
                map.on('moveend', function(e) {
                    var lat = map.getCenter().lat;
                    var lng = map.getCenter().lng;
                    $('#id_latitude').val(lat);
                    $('#id_longitude').val(lng);
                    $.get("http://api.geonames.org/astergdem?lat="+lat+"&lng="+lng+"&username=celutz&style=full" ).done(
                        function(data) {
                            $('#id_altitude').val(parseInt(data));
                            });
                    });
              }
              initmap();
            </script>
          {% block content %}{% endblock content %}
        </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->

    {% block js %}{% endblock js %}

    <script src="{% static "panorama/js/jquery.js" %}"></script>
    <script src="{% static "panorama/js/bootstrap.min.js" %}"></script>

  </body>
</html>
