use mobileclient.set_user_data() whenever needed/possible
This commit is contained in:
parent
84d849413e
commit
a7f0717869
10 changed files with 54 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
|||
{% extends 'site/base.html' %}
|
||||
{% load i18n %}
|
||||
{% load compress %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}{% trans 'c3nav control panel' %}{% endblock %}
|
||||
{% block header_title %}<span id="subheader">{% trans 'control panel' %}</span>{% endblock %}
|
||||
|
@ -27,4 +29,15 @@
|
|||
{% block subcontent %}
|
||||
{% endblock %}
|
||||
</main>
|
||||
{% compress js %}
|
||||
<script type="text/javascript" src="{% static 'jquery/jquery.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
if (window.mobileclient) {
|
||||
var $body = $('body');
|
||||
if ($body.is('[data-user-data]')) {
|
||||
mobileclient.set_user_data(JSON.parse($body.attr('data-user-data')));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endcompress %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -22,7 +22,13 @@ editor = {
|
|||
editor.map.doubleClickZoom.enable();
|
||||
});
|
||||
|
||||
if (window.mobileclient) $('body').addClass('mobileclient');
|
||||
if (window.mobileclient) {
|
||||
var $body = $('body');
|
||||
$body.addClass('mobileclient');
|
||||
if ($body.is('[data-user-data]')) {
|
||||
editor._inform_mobile_client($body);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fix scroll wheel zoom on precise scrolling devices
|
||||
|
@ -57,6 +63,13 @@ editor = {
|
|||
editor.init_geometries();
|
||||
editor.init_wificollector();
|
||||
},
|
||||
_inform_mobile_client: function(elem) {
|
||||
if (!window.mobileclient || !elem.length) return;
|
||||
var data = JSON.parse(elem.attr('data-user-data'));
|
||||
data.changes_count_display = elem.attr('data-count-display');
|
||||
data.direct_editing = elem.is('[data-direct-editing]');
|
||||
mobileclient.set_user_data(data);
|
||||
},
|
||||
_onbeforeunload: function(e) {
|
||||
if ($('#sidebar').find('[data-onbeforeunload]').length) {
|
||||
e.returnValue = true;
|
||||
|
@ -161,6 +174,8 @@ editor = {
|
|||
$('#navbar-collapse').find('.nav').html(nav.html());
|
||||
}
|
||||
|
||||
editor._inform_mobile_client(content.find('[data-user-data]'));
|
||||
|
||||
var group;
|
||||
if (content.find('[name=fixed_x]').length) {
|
||||
$('[name=name]').change(editor._source_name_selected).change();
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
<link href="{% static 'editor/css/editor.scss' %}" rel="stylesheet" type="text/x-scss">
|
||||
{% endcompress %}
|
||||
</head>
|
||||
<body{% if mobileclient %} data-user-data="{{ user_data_json }}" data-count-display="{{ request.changeset.count_display }}"{% if request.changeset.direct_editing%} data-direct-editing{% endif %}{% endif %}>
|
||||
<body{% if request.mobileclient %} data-user-data="{{ user_data_json }}" data-count-display="{{ request.changeset.count_display }}"{% if request.changeset.direct_editing%} data-direct-editing{% endif %}{% endif %}>
|
||||
|
||||
{% if not mobileclient %}
|
||||
{% if not request.mobileclient %}
|
||||
<nav class="navbar navbar-static-top navbar-default">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<div data-user-data="{{ user_data_json }}" data-count-display="{{ request.changeset.count_display }}"{% if request.changeset.direct_editing%} data-direct-editing{% endif %}></div>
|
|
@ -56,6 +56,8 @@ def sidebar_view(func=None, select_related=None, api_hybrid=False):
|
|||
return render(request, 'editor/redirect.html', {'target': response['location']})
|
||||
if not isinstance(response, HttpResponseNotModified):
|
||||
response.write(render(request, 'editor/fragment_nav.html', {}).content)
|
||||
if request.mobileclient:
|
||||
response.write(render(request, 'editor/fragment_mobileclientdata.html', {}).content)
|
||||
response['Cache-Control'] = 'no-cache'
|
||||
patch_vary_headers(response, ('X-Requested-With', ))
|
||||
return response
|
||||
|
|
|
@ -225,6 +225,7 @@ MIDDLEWARE = [
|
|||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'c3nav.mapdata.middleware.UserDataMiddleware',
|
||||
'c3nav.site.middleware.MobileclientMiddleware',
|
||||
'c3nav.control.middleware.UserPermissionsMiddleware',
|
||||
'c3nav.api.middleware.JsonRequestBodyMiddleware',
|
||||
]
|
||||
|
@ -297,7 +298,6 @@ TEMPLATES = [
|
|||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'c3nav.site.context_processors.logos',
|
||||
'c3nav.site.context_processors.mobileclient',
|
||||
'c3nav.site.context_processors.user_data_json',
|
||||
],
|
||||
'loaders': template_loaders
|
||||
|
|
|
@ -15,12 +15,6 @@ def logos(request):
|
|||
return logos_result
|
||||
|
||||
|
||||
def mobileclient(request):
|
||||
return {
|
||||
'mobileclient': 'c3navclient' in request.META['HTTP_USER_AGENT'],
|
||||
}
|
||||
|
||||
|
||||
def user_data_json(request):
|
||||
return {
|
||||
'user_data_json': lambda: json.dumps(dict(request.user_data), separators=(',', ':'), cls=DjangoJSONEncoder),
|
||||
|
|
10
src/c3nav/site/middleware.py
Normal file
10
src/c3nav/site/middleware.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
class MobileclientMiddleware:
|
||||
"""
|
||||
This middleware adds request.mobileclient
|
||||
"""
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
request.mobileclient = 'c3navclient' in request.META['HTTP_USER_AGENT']
|
||||
return self.get_response(request)
|
|
@ -43,9 +43,13 @@ c3nav = {
|
|||
});
|
||||
|
||||
if (window.mobileclient) {
|
||||
var $body = $('body');
|
||||
$('#attributions').find('a:not([href^="http"]):not([href^="//"])').removeAttr('target');
|
||||
$('body').addClass('mobileclient');
|
||||
$body.addClass('mobileclient');
|
||||
c3nav._set_user_location(null);
|
||||
if ($body.is('[data-user-data]')) {
|
||||
mobileclient.set_user_data(JSON.parse($body.attr('data-user-data')));
|
||||
}
|
||||
}
|
||||
},
|
||||
load_searchable_locations: function() {
|
||||
|
@ -1233,7 +1237,7 @@ c3nav = {
|
|||
c3nav.last_site_update = data.last_site_update;
|
||||
c3nav._maybe_load_site_update(c3nav.state);
|
||||
}
|
||||
c3nav._set_user_data(data.user);
|
||||
c3nav._set_user_data_set_user_data(data.user);
|
||||
},
|
||||
_maybe_load_site_update: function(state) {
|
||||
if (c3nav.new_site_update && !state.modal && (!state.routing || !state.origin || !state.destination)) {
|
||||
|
@ -1252,6 +1256,7 @@ c3nav = {
|
|||
var $user = $('header #user');
|
||||
$user.find('span').text(data.title);
|
||||
$user.find('small').text(data.subtitle || '');
|
||||
if (window.mobileclient) mobileclient.set_user_data(data);
|
||||
},
|
||||
|
||||
_last_wifi_scant: 0,
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
<link href="{% static 'site/css/c3nav.scss' %}" rel="stylesheet" type="text/x-scss">
|
||||
{% endcompress %}
|
||||
</head>
|
||||
<body{% if mobileclient %} data-user-data="{{ user_data_json }}"{% endif %}>
|
||||
{% if not embed and not mobileclient %}
|
||||
<body{% if request.mobileclient %} data-user-data="{{ user_data_json }}"{% endif %}>
|
||||
{% if not embed and not request.mobileclient %}
|
||||
<header>
|
||||
<h1><a href="{% block header_title_url %}/{% endblock %}">
|
||||
{% if header_logo %}<img src="{% static header_logo %}">{% else %}c3nav {% endif %}{% spaceless %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue