subsection selector

This commit is contained in:
Laura Klünder 2017-06-11 00:00:25 +02:00
parent b4862b0062
commit 3e02958b37
5 changed files with 57 additions and 20 deletions

View file

@ -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;

View file

@ -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<sections.length;i++) {
var section = $(sections[i]);
editor._section_control.addSection(section.text(), section.attr('href'), section.is('.current'));
}
if (sections.length > 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('<h3>Error '+data.status+'</h3>'+data.statusText);
editor._section_control.hide();
editor._subsection_control.hide();
},
_sidebar_link_click: function(e) {
// listener for link-clicks in the sidebar.

View file

@ -2,13 +2,23 @@
<ul data-sections>
{% for s in sections %}
<li>
<a href="{% if section_as_pk %}{% url section_url pk=s.id %}{% else %}{% url section_url section=s.id %}{% endif %}"{% if section == s %} class="current"{% endif %}>{{ s.title }}</a>
<a href="{% if section_as_pk %}{% url section_url pk=s.id %}{% else %}{% url section_url section=s.id %}{% endif %}"{% if section.primary_section == s %} class="current"{% endif %}>{{ s.title }}</a>
</li>
{% endfor %}
</ul>
<ul data-subsections>
{% for s in section.primary_section.subsections %}
<li>
<a href="{% if section_as_pk %}{% url section_url pk=s.id %}{% else %}{% url section_url section=s.id %}{% endif %}"{% if section == s %} class="current"{% endif %}>{{ s.subsection_title }}</a>
</li>
{% endfor %}
</ul>
{% elif section %}
<ul data-sections>
<li><a href="" class="current">{{ section.title }}</a></li>
<li><a href="" class="current">{{ section.primary_section.title }}</a></li>
</ul>
<ul data-subsections>
<li><a href="" class="current">{{ section.subsection_title }}</a></li>
</ul>
{% endif %}
{% if geometry_url %}

View file

@ -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),

View file

@ -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