fix locating aka call scanNow()
This commit is contained in:
parent
229b4d5ac9
commit
7cf59dab23
3 changed files with 54 additions and 31 deletions
|
@ -208,7 +208,7 @@ class LocationViewSet(ViewSet):
|
||||||
def wifilocate(self, request):
|
def wifilocate(self, request):
|
||||||
stations = json.loads(request.POST['stations'])[:200]
|
stations = json.loads(request.POST['stations'])[:200]
|
||||||
if not stations:
|
if not stations:
|
||||||
return Response({})
|
return Response({'location': None})
|
||||||
|
|
||||||
bssids = get_bssid_areas_cached()
|
bssids = get_bssid_areas_cached()
|
||||||
stations = sorted(stations, key=lambda l: l['level'])
|
stations = sorted(stations, key=lambda l: l['level'])
|
||||||
|
|
|
@ -127,36 +127,9 @@ c3nav = {
|
||||||
var location_title = location_group.find('.title').text();
|
var location_title = location_group.find('.title').text();
|
||||||
c3nav.qr_modal.find('strong').text(window.location.origin+'/l/'+location_id+'/');
|
c3nav.qr_modal.find('strong').text(window.location.origin+'/l/'+location_id+'/');
|
||||||
c3nav.qr_modal.find('img').attr('src', '/qr/'+location_id+'.png');
|
c3nav.qr_modal.find('img').attr('src', '/qr/'+location_id+'.png');
|
||||||
c3nav.qr_modal.data('title', location_title)
|
c3nav.qr_modal.data('title', location_title);
|
||||||
c3nav.qr_modal.show();
|
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: 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) {
|
_locationselect_activate_map: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var location_group = $(this).closest('.location-group');
|
var location_group = $(this).closest('.location-group');
|
||||||
|
@ -208,6 +181,51 @@ c3nav = {
|
||||||
$('.location-group:visible:not(.selected) .locationselect-input .tt-input').first().focus();
|
$('.location-group:visible:not(.selected) .locationselect-input .tt-input').first().focus();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
_last_scan: 0,
|
||||||
|
_scan_for: [],
|
||||||
|
_scan_now: function() {
|
||||||
|
if (c3nav._last_scan < (new Date().getTime() / 1000 - 3000)) {
|
||||||
|
c3nav._last_scan = new Date().getTime() / 1000;
|
||||||
|
mobileclient.scanNow();
|
||||||
|
} else {
|
||||||
|
nearby_stations_available();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_locationselect_click_locate: function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var location_group = $(this).closest('.location-group');
|
||||||
|
location_group.addClass('loading').addClass('selected');
|
||||||
|
c3nav._scan_for.push(location_group.attr('data-name'));
|
||||||
|
c3nav._scan_now();
|
||||||
|
},
|
||||||
|
nearby_stations_available: function() {
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: '/api/locations/wifilocate/',
|
||||||
|
data: { stations: mobileclient.getNearbyStations() },
|
||||||
|
dataType: 'json',
|
||||||
|
success: c3nav._wifilocate_callback
|
||||||
|
});
|
||||||
|
},
|
||||||
|
_wifilocate_callback: function(data) {
|
||||||
|
var location_group, selected;
|
||||||
|
var location = data.location;
|
||||||
|
for(var i=0;i<c3nav._scan_for.length;i++) {
|
||||||
|
location_group = $('.location-group[data-name='+c3nav._scan_for[i]+']');
|
||||||
|
location_group.removeClass('loading');
|
||||||
|
selected = location_group.find('.locationselect-selected');
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c3nav._scan_for = [];
|
||||||
|
},
|
||||||
|
|
||||||
_click_route_from_here: function(e) {
|
_click_route_from_here: function(e) {
|
||||||
c3nav._click_route_x_here(e, $('.origin-select'));
|
c3nav._click_route_x_here(e, $('.origin-select'));
|
||||||
},
|
},
|
||||||
|
@ -288,4 +306,9 @@ c3nav = {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
function nearby_stations_available() {
|
||||||
|
c3nav.nearby_stations_available();
|
||||||
|
}
|
||||||
|
// mobileclient = { getNearbyStations: function() { return '[{"bssid": "00:00:00:00:00:01", "level": 10}]'; }, scanNow: function() { nearby_stations_available(); } };
|
||||||
|
|
||||||
$(document).ready(c3nav.init);
|
$(document).ready(c3nav.init);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<div class="col-md-{% if name == 'location' %}12{% else %}6{% endif %} location-group {{ name }}-select{% if location %} selected{% endif %}{% if active_field == name and map_level %} map{% endif %}">
|
<div class="col-md-{% if name == 'location' %}12{% else %}6{% endif %} location-group {{ name }}-select{% if location %} selected{% endif %}{% if active_field == name and map_level %} map{% endif %}" data-name="{{ name }}">
|
||||||
<div class="form-group{% if search == name and not search_results %} has-error{% endif %}" data-name="{{ name }}">
|
<div class="form-group{% if search == name and not search_results %} has-error{% endif %}">
|
||||||
<label for="{{ name }}_input">{{ heading }}</label>
|
<label for="{{ name }}_input">{{ heading }}</label>
|
||||||
{% if name == 'destination' %}
|
{% if name == 'destination' %}
|
||||||
{% if origin %}
|
{% if origin %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue