Commit 584fa7ec authored by Daniel STAN's avatar Daniel STAN

[wifimap] édition de bornes virtuelles

parent aa2c9c7c
......@@ -22,7 +22,8 @@ import views
urlpatterns = patterns('',
url('^$', views.index),
url('^get_xml$', views.get_xml)
url('^get_xml$', views.get_xml),
url('^update\((\w+),(\d+\.?\d+),(\d+\.?\d+)\)$', views.update),
)
......@@ -23,9 +23,11 @@ sys.path.append('/usr/scripts/wifi_new')
import django.shortcuts
from django.template import RequestContext
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from models import VirtAP
import xml.dom.minidom
#from django.contrib.auth.decorators import login_required, permission_required
......@@ -39,3 +41,12 @@ def get_xml(request):
def index(request):
return django.shortcuts.render_to_response('wifimap/index.html', context_instance=RequestContext(request))
def update(request,hostname, lon, lat):
ap = get_object_or_404(VirtAP, host__exact=hostname)
ap.lon = lon
ap.lat = lat
ap.save()
doc = xml.dom.minidom.Document()
doc.appendChild(ap.xmlRepr(doc))
return HttpResponse(doc.toxml('utf-8'),content_type='text/xml; coding=utf-8')
......@@ -110,6 +110,13 @@
color: red;
}
.borne .coords .recordCoord {
display: none;
}
.borne .coords.modified .recordCoord {
display: inline;
}
/* sorting */
.order {
......
......@@ -25,6 +25,7 @@ window.addEventListener('load',function () { WifiMap.init(); });
//Wifi map !
WifiMap = {
'moved': null,
'init': function() {
var that = this;
this.map = new OpenLayers.Map({'div': 'map','controls':[]});
......@@ -93,17 +94,12 @@ WifiMap = {
}
});
this.map.events.register("click",this,function (e) {
WifiMap.map.events.register("click",this ,function (e) {
var pos = this.map.getLonLatFromViewPortPx(this.map.events.getMousePosition(e));
var gps = pos.clone().transform(this.projections.map,this.projections.gps);
$('x').value = gps.lon;
$('y').value = gps.lat;
if( this.moved) {
this.moved.moveTo(gps);
this.moved = false;
}
});
if( this.moved )
this.moved.moveTo(pos);
this.moved = null;
});
//Event select: tout déselectionner
this.map.events.register('click', undefined, this.highlight.bind(this,undefined));
......@@ -149,6 +145,7 @@ WifiMap = {
'autres': 'marker-gold'};
borne.update_info = function(xml) {
//Clean up last marker
this.xml = xml;
var old = this.marker;
this.xml = xml;
var highlighted = this.highlighted;
......@@ -179,11 +176,9 @@ WifiMap = {
return;
}
//mapPosition sera stockée dans les coordonnées de la map
this.mapPosition = new OpenLayers.LonLat(x,y);
this.mapPosition.transform(that.projections.gps,that.projections.map);
}
this.mapPosition.transform(that.projections.gps,that.projections.map);
//On va compter le nombre de client et en déduire la taille
var counts = xml.getElementsByTagName('client_count');
......@@ -237,8 +232,11 @@ WifiMap = {
this.update_marker_size();
};
borne.moveTo = function (gps) {
this.mapPosition = gps;
borne.moveTo = function (mapPos) {
this.mapPosition = mapPos.clone();
var gps = mapPos.clone();
gps.transform(that.projections.map, that.projections.gps);
console.debug("Move to " + gps.lon + "; " + gps.lat );
this.mapPosition.modified = true;
this.update_info(this.xml);
};
......@@ -349,15 +347,54 @@ WifiMap = {
this.wifiMap.moved = this;
event.preventDefault();
}).bind(this));
coords = getElementsByClassName(html, 'coords')[0];
if( this.mapPosition) {
var gps = this.mapPosition.clone();
gps.transform(that.projections.map, that.projections.gps);
setInnerText(coords, gps.lon + ' ' + gps.lat)
this.mapPosition.modified && coords.setAttribute('class', 'coords modified');
templates.fillSpanClass(html, 'coords', gps.lon + ' ' + gps.lat)
this.mapPosition.modified && getElementsByClassName(html, 'coords')[0].setAttribute('class','coords modified')
}
else
setInnerText(coords, 'N/A');
templates.fillSpanClass(html, 'coords', 'N/A');
getElementsByClassName(html, 'recordCoord')[0].addEventListener('click',
(function (event) {
event.preventDefault();
var gps = this.mapPosition.clone();
gps.transform(that.projections.map, that.projections.gps);
//console.debug(gps.lon + ' ' + gps.lat + ' ' + this.hostname);
var req = new XMLHttpRequest();
req.open('GET', '/wifimap/update(' + this.hostname + ',' + gps.lon + ',' + gps.lat + ')', true);
var borne = this;
req.onreadystatechange = function() {
if( this.readyState != 4) return;
if( this.status != 200 ) {
if( this.status == 0)
return; //0 signifie que l'on quitte la page en cours
console.debug("La mise à jour a échouée");
return;
}
//Else: status == 200
borne.mapPosition=null;
borne.update_info(this.responseXML.documentElement);
}
req.send(null);
//that.show_bornes(xhr.responseXML);
//console.debug(xhr.responseText);
/*
this.update_date(doc);
var bornes = doc.getElementsByTagName('borne')
for( var i=0; i<bornes.length; i++) {
var xml = bornes[i];
var hostname = getInnerText(xml.getElementsByTagName('hostname')[0]);
if( !this.listeBornes[hostname])
this.listeBornes[hostname] = this.make_borne(hostname);
this.listeBornes[hostname].update_info(xml);
}
this.sort();*/
}).bind(this));
//On fixe la nouvelle bar d'info
if(this.html_list)
......@@ -460,7 +497,7 @@ WifiMap = {
var delta = 10; // ~= le temps que le script interroge toutes les bornes
var wait = (5*60+delta+min)*1000 - (new Date()).getTime();
if( wait > 0) //No refresh is already outdated (possible server problem)
setTimeout(WifiMap.get_all.bind(WifiMap), wait);
true || setTimeout(WifiMap.get_all.bind(WifiMap), wait);
//Mise à jour régulière
this.update_date.timer && clearInterval(this.update_date.timer);
......
......@@ -26,7 +26,8 @@ Dernière mise à jour il y a <label id="last_update"> </label>
<span class="uptime template">Uptime: <span class="content"></span></span>
<ul>
<li class="comment template">Liste commentaire</li>
<li class="coord">Lon/Lat <span class="coords">N/A</span>
<li class="coords">Lon/Lat <span class="content">N/A</span>
<a href="#" class="recordCoord">Enregistrer</a>
<a href="#" class="setCoord">Placer</a></li>
<li class="prise template">Prise: <span class="content"></span></li>
</ul>
......@@ -44,6 +45,4 @@ Dernière mise à jour il y a <label id="last_update"> </label>
</div>
<div id="map">
</div>
<input type="text" id="x">
<input type="text" id="y">
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment