From a7f0717869ab3f7a2202d2ac24e28b42b1e5b348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Mon, 26 Nov 2018 01:18:42 +0100 Subject: [PATCH] use mobileclient.set_user_data() whenever needed/possible --- src/c3nav/control/templates/control/base.html | 13 +++++++++++++ src/c3nav/editor/static/editor/js/editor.js | 17 ++++++++++++++++- src/c3nav/editor/templates/editor/base.html | 4 ++-- .../editor/fragment_mobileclientdata.html | 1 + src/c3nav/editor/views/base.py | 2 ++ src/c3nav/settings.py | 2 +- src/c3nav/site/context_processors.py | 6 ------ src/c3nav/site/middleware.py | 10 ++++++++++ src/c3nav/site/static/site/js/c3nav.js | 9 +++++++-- src/c3nav/site/templates/site/base.html | 4 ++-- 10 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 src/c3nav/editor/templates/editor/fragment_mobileclientdata.html create mode 100644 src/c3nav/site/middleware.py diff --git a/src/c3nav/control/templates/control/base.html b/src/c3nav/control/templates/control/base.html index 3b3c9666..82e74aaa 100644 --- a/src/c3nav/control/templates/control/base.html +++ b/src/c3nav/control/templates/control/base.html @@ -1,5 +1,7 @@ {% extends 'site/base.html' %} {% load i18n %} +{% load compress %} +{% load static %} {% block title %}{% trans 'c3nav control panel' %}{% endblock %} {% block header_title %}{% trans 'control panel' %}{% endblock %} @@ -27,4 +29,15 @@ {% block subcontent %} {% endblock %} + {% compress js %} + + + {% endcompress %} {% endblock %} diff --git a/src/c3nav/editor/static/editor/js/editor.js b/src/c3nav/editor/static/editor/js/editor.js index 22ef810e..73a0ce7f 100644 --- a/src/c3nav/editor/static/editor/js/editor.js +++ b/src/c3nav/editor/static/editor/js/editor.js @@ -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(); diff --git a/src/c3nav/editor/templates/editor/base.html b/src/c3nav/editor/templates/editor/base.html index a1ddb561..4f4fca5b 100644 --- a/src/c3nav/editor/templates/editor/base.html +++ b/src/c3nav/editor/templates/editor/base.html @@ -17,9 +17,9 @@ {% endcompress %} - + - {% if not mobileclient %} + {% if not request.mobileclient %}