diff --git a/src/c3nav/editor/static/editor/css/editor.css b/src/c3nav/editor/static/editor/css/editor.css index b03c6964..c461ffae 100644 --- a/src/c3nav/editor/static/editor/css/editor.css +++ b/src/c3nav/editor/static/editor/css/editor.css @@ -102,7 +102,7 @@ legend { right: 8px; top: 8px; } -[data-sections] { +[data-sections], [data-subsections] { display:none; } form button.invisiblesubmit { @@ -204,6 +204,9 @@ form button.invisiblesubmit { /* leaftlet sections control */ +.leaflet-control-sections { + overflow:hidden; +} .leaflet-control-sections a, .leaflet-control-sections a:hover { width: auto; font-size: 14px; diff --git a/src/c3nav/editor/static/editor/js/editor.js b/src/c3nav/editor/static/editor/js/editor.js index 36a96d75..c4a1b53b 100644 --- a/src/c3nav/editor/static/editor/js/editor.js +++ b/src/c3nav/editor/static/editor/js/editor.js @@ -39,6 +39,7 @@ editor = { }); editor._section_control = new SectionControl().addTo(editor.map); + editor._subsection_control = new SectionControl().addTo(editor.map); editor.init_geometries(); }, @@ -102,9 +103,26 @@ editor = { _sidebar_unload: function() { // unload the sidebar. called on sidebar_get and form submit. editor._section_control.disable(); + editor._subsection_control.disable(); $('#sidebar').addClass('loading').find('.content').html(''); editor._cancel_editing(); }, + _fill_section_control: function (section_control, sections) { + if (sections.length) { + for (var i = 0; i < sections.length; i++) { + var section = $(sections[i]); + section_control.addSection(section.text(), section.attr('href'), section.is('.current')); + } + if (sections.length > 1) { + section_control.enable(); + } else { + section_control.disable(); + } + section_control.show() + } else { + section_control.hide(); + } + }, _sidebar_loaded: function(data) { // sidebar was loaded. load the content. check if there are any redirects. call _check_start_editing. var content = $('#sidebar').removeClass('loading').find('.content');; @@ -133,30 +151,20 @@ editor = { ); $('body').addClass('map-enabled'); editor._section_control.clearSections(); + editor._subsection_control.clearSections(); - var sections = content.find('[data-sections] a'); - if (sections.length) { - for(var i=0;i 1) { - editor._section_control.enable(); - } else { - editor._section_control.disable(); - } - editor._section_control.show() - } else { - editor._section_control.hide(); - } + editor._fill_section_control(editor._section_control, content.find('[data-sections] a')); + editor._fill_section_control(editor._subsection_control, content.find('[data-subsections] a')); } else { $('body').removeClass('map-enabled').removeClass('show-map'); editor._section_control.hide(); + editor._subsection_control.hide(); } }, _sidebar_error: function(data) { $('#sidebar').removeClass('loading').find('.content').html('

Error '+data.status+'

'+data.statusText); editor._section_control.hide(); + editor._subsection_control.hide(); }, _sidebar_link_click: function(e) { // listener for link-clicks in the sidebar. diff --git a/src/c3nav/editor/templates/editor/fragment_sections.html b/src/c3nav/editor/templates/editor/fragment_sections.html index 629c4594..3a6bd10f 100644 --- a/src/c3nav/editor/templates/editor/fragment_sections.html +++ b/src/c3nav/editor/templates/editor/fragment_sections.html @@ -2,13 +2,23 @@ + {% elif section %} + {% endif %} {% if geometry_url %} diff --git a/src/c3nav/editor/views.py b/src/c3nav/editor/views.py index d1111f89..42b7673b 100644 --- a/src/c3nav/editor/views.py +++ b/src/c3nav/editor/views.py @@ -52,7 +52,7 @@ def section_detail(request, pk): section = get_object_or_404(Section.objects.select_related('on_top_of'), pk=pk) return render(request, 'editor/section.html', { - 'sections': Section.objects.all(), + 'sections': Section.objects.filter(on_top_of__isnull=True), 'section': section, 'section_url': 'editor.sections.detail', 'section_as_pk': True, @@ -245,7 +245,7 @@ def list_objects(request, model=None, section=None, space=None, explicit_edit=Fa ctx.update({ 'back_url': reverse('editor.sections.detail', kwargs={'pk': section.pk}), 'back_title': _('back to section'), - 'sections': Section.objects.all(), + 'sections': Section.objects.filter(on_top_of__isnull=True), 'section': section, 'section_url': request.resolver_match.url_name, 'geometry_url': '/api/editor/geometries/?section='+str(section.primary_section_pk), diff --git a/src/c3nav/mapdata/models/section.py b/src/c3nav/mapdata/models/section.py index e7aa6948..f3a4ec97 100644 --- a/src/c3nav/mapdata/models/section.py +++ b/src/c3nav/mapdata/models/section.py @@ -1,3 +1,5 @@ +from itertools import chain + from django.conf import settings from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -36,6 +38,20 @@ class Section(SpecificLocation, EditorFormMixin, models.Model): raise TypeError return Section.objects.filter(altitude__gt=self.altitude, on_top_of__isnull=True).order_by('altitude') + @property + def subsections(self): + if self.on_top_of is not None: + raise TypeError + return chain((self, ), self.sections_on_top.all()) + + @property + def subsection_title(self): + return '-' if self.on_top_of_id is None else self.title + + @property + def primary_section(self): + return self if self.on_top_of_id is None else self.on_top_of + @property def primary_section_pk(self): return self.pk if self.on_top_of_id is None else self.on_top_of_id