add wifi locating

This commit is contained in:
Laura Klünder 2016-12-28 10:32:54 +01:00
parent 0ceb6fb263
commit 90b54e67d1
4 changed files with 58 additions and 8 deletions

View file

@ -107,5 +107,5 @@ def get_bssid_areas_cached():
bssids = {}
for area in AreaLocation.objects.filter(~Q(bssids='')):
for bssid in area.bssids.split('\n'):
bssids[bssid] = area.name
bssids[bssid.strip()] = area.name
return bssids

View file

@ -16,15 +16,18 @@ body, .btn {
.locationselect > div {
position:relative;
}
.locationselect .locationselect-selected {
.locationselect .locationselect-selected, .locationselect .locationselect-error {
display:none;
}
.location-group.selected .locationselect-selected {
display:block;
}
.location-group.selected .locationselect-input {
.location-group.selected .locationselect-input, .location-group.error .locationselect-input {
display:none;
}
.location-group.error .locationselect-error {
display:block;
}
.locationselect .icons {
height:48px;
position:absolute;
@ -37,7 +40,7 @@ body, .btn {
width:48px;
height:48px;
}
.locationselect .icons .reset {
.locationselect .icons .reset, .locationselect .icons .errorreset {
background-image:url('../img/icons/cross.svg');
}
.locationselect .icons .link {
@ -56,6 +59,9 @@ body, .btn {
.location-group.selected .only-if-selected {
display:block;
}
.location-group.selected.loading .only-if-selected {
display:none;
}
.locationselect-map {
display:none;
@ -261,7 +267,7 @@ circle.pos {
}
.locationselect-selected.loading .location,
.location-group.selected.loading .locationselect-selected .location,
.locationselect-map .map-container {
background-image:url('/static/img/loader.gif');
background-repeat:no-repeat;

View file

@ -45,8 +45,10 @@ c3nav = {
c3nav.locationselect_focus();
$('.locationselect .icons .reset').click(c3nav._locationselect_reset);
$('.locationselect .icons .errorreset').click(c3nav._locationselect_errorreset);
$('.locationselect .icons .map').click(c3nav._locationselect_activate_map);
$('.locationselect .icons .link').click(c3nav._locationselect_click_link);
$('.locationselect .icons .locate').click(c3nav._locationselect_click_locate);
$('.locationselect .close-map').click(c3nav._locationselect_close_map);
$('.locationselect .level-selector a').click(c3nav._locationselect_click_level);
$('.locationselect .map-container').on('click', 'img', c3nav._locationselect_click_image);
@ -112,6 +114,12 @@ c3nav = {
location_group.find('.tt-suggestion').remove();
c3nav._locations_changed();
},
_locationselect_errorreset: function(e) {
e.preventDefault();
var location_group = $(this).closest('.location-group');
location_group.removeClass('error').find('.tt-input').focus();
location_group.find('.tt-suggestion').remove();
},
_locationselect_click_link: function(e) {
e.preventDefault();
var location_group = $(this).closest('.location-group');
@ -122,6 +130,33 @@ c3nav = {
c3nav.qr_modal.data('title', location_title)
c3nav.qr_modal.show();
},
_locationselect_click_locate: function(e) {
e.preventDefault();
var location_group = $(this).closest('.location-group');
location_group.addClass('selected').addClass('loading');
var selected = location_group.find('.locationselect-selected');
selected.find('.title').text('');
selected.find('.subtitle').text('');
selected.find('.id-field').val('');
$.ajax({
type: "POST",
url: '/api/locations/wifilocate/',
data: { stations: JSON.stringify(mobileclient.getNearbyStations()) },
dataType: 'json',
success: function(data) {
location_group.removeClass('loading');
var location = data.location;
if (location === null) {
location_group.addClass('error').removeClass('selected');
} else {
selected.find('.id-field').val(location.id);
selected.find('.title').text(location.title);
selected.find('.subtitle').text(location.subtitle);
}
}
});
},
_locationselect_activate_map: function(e) {
e.preventDefault();
var location_group = $(this).closest('.location-group');
@ -156,16 +191,15 @@ c3nav = {
var level = $(e.delegateTarget).attr('data-level');
var coords = 'c:'+level+':'+parseInt(e.offsetX/6*100)+':'+parseInt((c3nav.svg_height-e.offsetY)/6*100);
var location_group = $(this).closest('.location-group');
location_group.removeClass('map').addClass('selected');
location_group.removeClass('map').addClass('selected').addClass('loading');
var selected = location_group.find('.locationselect-selected');
selected.find('.title').text('');
selected.find('.subtitle').text('');
selected.find('.id-field').val(coords);
selected.addClass('loading');
$.getJSON('/api/locations/'+coords, function(data) {
selected.find('.title').text(data.title);
selected.find('.subtitle').text(data.subtitle);
selected.removeClass('loading');
selected.closest('.location-group').removeClass('loading');
});
c3nav._locations_changed();
c3nav.locationselect_focus();

View file

@ -71,6 +71,16 @@
</div>
<input type="hidden" name="{{ name }}" value="{{ location.location_id }}" class="id-field">
</div>
<div class="locationselect-error">
<div class="location form-control input-lg">
<span class="title">{% trans 'Sorry, we could not detect your position.' %}</span>
<small class="subtitle">{% trans 'Wifi mapping may not yet be available in the entire building.' %}</small>
</div>
<div class="icons">
<a href="{{ reset_url }}" class="errorreset"></a>
</div>
</div>
</div>
{% if search == name and not search_results %}
<span class="help-block">{% trans 'No location matched your search query.' %}</span>