make sure user data is always available and updated in js when needed
This commit is contained in:
parent
fa6ddfa3ff
commit
15016b9a77
3 changed files with 15 additions and 7 deletions
|
@ -49,6 +49,7 @@
|
||||||
|
|
||||||
c3nav = {
|
c3nav = {
|
||||||
init_completed: false,
|
init_completed: false,
|
||||||
|
user_data: null,
|
||||||
init: function () {
|
init: function () {
|
||||||
c3nav.load_material_icons_if_needed();
|
c3nav.load_material_icons_if_needed();
|
||||||
c3nav.load_searchable_locations();
|
c3nav.load_searchable_locations();
|
||||||
|
@ -72,16 +73,17 @@ c3nav = {
|
||||||
$('.app-ads').remove();
|
$('.app-ads').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var $body = $('body');
|
||||||
if (window.mobileclient) {
|
if (window.mobileclient) {
|
||||||
var $body = $('body');
|
|
||||||
$body.addClass('mobileclient');
|
$body.addClass('mobileclient');
|
||||||
c3nav._set_user_location(null);
|
c3nav._set_user_location(null);
|
||||||
if ($body.is('[data-user-data]')) {
|
|
||||||
mobileclient.setUserData($body.attr('data-user-data'));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
document.addEventListener('visibilitychange', c3nav.on_visibility_change, false);
|
document.addEventListener('visibilitychange', c3nav.on_visibility_change, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($body.is('[data-user-data]')) {
|
||||||
|
c3nav._set_user_data(JSON.parse($body.attr('data-user-data')));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_searchable_locations_timer: null,
|
_searchable_locations_timer: null,
|
||||||
load_searchable_locations: function(firstTime) {
|
load_searchable_locations: function(firstTime) {
|
||||||
|
@ -1237,7 +1239,12 @@ c3nav = {
|
||||||
history.back();
|
history.back();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c3nav._set_modal_content($('<div>'+data+'</div>').find('main').html());
|
var html = $('<div>'+data.replace('<body', '<div')+'</div>');
|
||||||
|
var user_data = html.find('[data-user-data]');
|
||||||
|
if (user_data.length) {
|
||||||
|
c3nav._set_user_data(JSON.parse(user_data.attr('data-user-data')));
|
||||||
|
}
|
||||||
|
c3nav._set_modal_content(html.find('main').html());
|
||||||
},
|
},
|
||||||
_modal_error: function(data) {
|
_modal_error: function(data) {
|
||||||
$('#modal').removeClass('loading').find('#modal-content').html('<h3>Error '+data.status+'</h3>');
|
$('#modal').removeClass('loading').find('#modal-content').html('<h3>Error '+data.status+'</h3>');
|
||||||
|
@ -1365,7 +1372,6 @@ c3nav = {
|
||||||
_click_anywhere_load: function(nearby) {
|
_click_anywhere_load: function(nearby) {
|
||||||
if (!c3nav._click_anywhere_popup) return;
|
if (!c3nav._click_anywhere_popup) return;
|
||||||
var latlng = c3nav._click_anywhere_popup.getLatLng();
|
var latlng = c3nav._click_anywhere_popup.getLatLng();
|
||||||
console.log(latlng);
|
|
||||||
c3nav._click_anywhere_popup.remove();
|
c3nav._click_anywhere_popup.remove();
|
||||||
var popup = L.popup().setLatLng(latlng).setContent('<div class="loader"></div>'),
|
var popup = L.popup().setLatLng(latlng).setContent('<div class="loader"></div>'),
|
||||||
level = c3nav._levelControl.currentLevel,
|
level = c3nav._levelControl.currentLevel,
|
||||||
|
@ -1611,6 +1617,7 @@ c3nav = {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
},
|
},
|
||||||
_set_user_data: function (data) {
|
_set_user_data: function (data) {
|
||||||
|
c3nav.user_data = data;
|
||||||
var $user = $('header #user');
|
var $user = $('header #user');
|
||||||
$user.find('span').text(data.title);
|
$user.find('span').text(data.title);
|
||||||
$user.find('small').text(data.subtitle || '');
|
$user.find('small').text(data.subtitle || '');
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
<link href="{% static 'site/css/c3nav.scss' %}" rel="stylesheet" type="text/x-scss">
|
<link href="{% static 'site/css/c3nav.scss' %}" rel="stylesheet" type="text/x-scss">
|
||||||
{% endcompress %}
|
{% endcompress %}
|
||||||
</head>
|
</head>
|
||||||
<body{% if request.mobileclient %} data-user-data="{{ user_data_json }}"{% endif %}>
|
<body data-user-data="{{ user_data_json }}">
|
||||||
{% if not embed and not request.mobileclient %}
|
{% if not embed and not request.mobileclient %}
|
||||||
<header>
|
<header>
|
||||||
<h1><a href="{% block header_title_url %}/{% endblock %}">
|
<h1><a href="{% block header_title_url %}/{% endblock %}">
|
||||||
|
|
|
@ -489,6 +489,7 @@ def report_detail(request, pk, secret=None):
|
||||||
def position_list(request):
|
def position_list(request):
|
||||||
return render(request, 'site/position_list.html', {
|
return render(request, 'site/position_list.html', {
|
||||||
'positions': Position.objects.filter(owner=request.user),
|
'positions': Position.objects.filter(owner=request.user),
|
||||||
|
'user_data_json': json.dumps(get_user_data(request), cls=DjangoJSONEncoder),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue