subsection selector
This commit is contained in:
parent
b4862b0062
commit
3e02958b37
5 changed files with 57 additions and 20 deletions
|
@ -102,7 +102,7 @@ legend {
|
||||||
right: 8px;
|
right: 8px;
|
||||||
top: 8px;
|
top: 8px;
|
||||||
}
|
}
|
||||||
[data-sections] {
|
[data-sections], [data-subsections] {
|
||||||
display:none;
|
display:none;
|
||||||
}
|
}
|
||||||
form button.invisiblesubmit {
|
form button.invisiblesubmit {
|
||||||
|
@ -204,6 +204,9 @@ form button.invisiblesubmit {
|
||||||
|
|
||||||
|
|
||||||
/* leaftlet sections control */
|
/* leaftlet sections control */
|
||||||
|
.leaflet-control-sections {
|
||||||
|
overflow:hidden;
|
||||||
|
}
|
||||||
.leaflet-control-sections a, .leaflet-control-sections a:hover {
|
.leaflet-control-sections a, .leaflet-control-sections a:hover {
|
||||||
width: auto;
|
width: auto;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
|
|
@ -39,6 +39,7 @@ editor = {
|
||||||
});
|
});
|
||||||
|
|
||||||
editor._section_control = new SectionControl().addTo(editor.map);
|
editor._section_control = new SectionControl().addTo(editor.map);
|
||||||
|
editor._subsection_control = new SectionControl().addTo(editor.map);
|
||||||
|
|
||||||
editor.init_geometries();
|
editor.init_geometries();
|
||||||
},
|
},
|
||||||
|
@ -102,9 +103,26 @@ editor = {
|
||||||
_sidebar_unload: function() {
|
_sidebar_unload: function() {
|
||||||
// unload the sidebar. called on sidebar_get and form submit.
|
// unload the sidebar. called on sidebar_get and form submit.
|
||||||
editor._section_control.disable();
|
editor._section_control.disable();
|
||||||
|
editor._subsection_control.disable();
|
||||||
$('#sidebar').addClass('loading').find('.content').html('');
|
$('#sidebar').addClass('loading').find('.content').html('');
|
||||||
editor._cancel_editing();
|
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_loaded: function(data) {
|
||||||
// sidebar was loaded. load the content. check if there are any redirects. call _check_start_editing.
|
// sidebar was loaded. load the content. check if there are any redirects. call _check_start_editing.
|
||||||
var content = $('#sidebar').removeClass('loading').find('.content');;
|
var content = $('#sidebar').removeClass('loading').find('.content');;
|
||||||
|
@ -133,30 +151,20 @@ editor = {
|
||||||
);
|
);
|
||||||
$('body').addClass('map-enabled');
|
$('body').addClass('map-enabled');
|
||||||
editor._section_control.clearSections();
|
editor._section_control.clearSections();
|
||||||
|
editor._subsection_control.clearSections();
|
||||||
|
|
||||||
var sections = content.find('[data-sections] a');
|
editor._fill_section_control(editor._section_control, content.find('[data-sections] a'));
|
||||||
if (sections.length) {
|
editor._fill_section_control(editor._subsection_control, content.find('[data-subsections] a'));
|
||||||
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();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$('body').removeClass('map-enabled').removeClass('show-map');
|
$('body').removeClass('map-enabled').removeClass('show-map');
|
||||||
editor._section_control.hide();
|
editor._section_control.hide();
|
||||||
|
editor._subsection_control.hide();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_sidebar_error: function(data) {
|
_sidebar_error: function(data) {
|
||||||
$('#sidebar').removeClass('loading').find('.content').html('<h3>Error '+data.status+'</h3>'+data.statusText);
|
$('#sidebar').removeClass('loading').find('.content').html('<h3>Error '+data.status+'</h3>'+data.statusText);
|
||||||
editor._section_control.hide();
|
editor._section_control.hide();
|
||||||
|
editor._subsection_control.hide();
|
||||||
},
|
},
|
||||||
_sidebar_link_click: function(e) {
|
_sidebar_link_click: function(e) {
|
||||||
// listener for link-clicks in the sidebar.
|
// listener for link-clicks in the sidebar.
|
||||||
|
|
|
@ -2,13 +2,23 @@
|
||||||
<ul data-sections>
|
<ul data-sections>
|
||||||
{% for s in sections %}
|
{% for s in sections %}
|
||||||
<li>
|
<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>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% elif section %}
|
{% elif section %}
|
||||||
<ul data-sections>
|
<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>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if geometry_url %}
|
{% if geometry_url %}
|
||||||
|
|
|
@ -52,7 +52,7 @@ def section_detail(request, pk):
|
||||||
section = get_object_or_404(Section.objects.select_related('on_top_of'), pk=pk)
|
section = get_object_or_404(Section.objects.select_related('on_top_of'), pk=pk)
|
||||||
|
|
||||||
return render(request, 'editor/section.html', {
|
return render(request, 'editor/section.html', {
|
||||||
'sections': Section.objects.all(),
|
'sections': Section.objects.filter(on_top_of__isnull=True),
|
||||||
'section': section,
|
'section': section,
|
||||||
'section_url': 'editor.sections.detail',
|
'section_url': 'editor.sections.detail',
|
||||||
'section_as_pk': True,
|
'section_as_pk': True,
|
||||||
|
@ -245,7 +245,7 @@ def list_objects(request, model=None, section=None, space=None, explicit_edit=Fa
|
||||||
ctx.update({
|
ctx.update({
|
||||||
'back_url': reverse('editor.sections.detail', kwargs={'pk': section.pk}),
|
'back_url': reverse('editor.sections.detail', kwargs={'pk': section.pk}),
|
||||||
'back_title': _('back to section'),
|
'back_title': _('back to section'),
|
||||||
'sections': Section.objects.all(),
|
'sections': Section.objects.filter(on_top_of__isnull=True),
|
||||||
'section': section,
|
'section': section,
|
||||||
'section_url': request.resolver_match.url_name,
|
'section_url': request.resolver_match.url_name,
|
||||||
'geometry_url': '/api/editor/geometries/?section='+str(section.primary_section_pk),
|
'geometry_url': '/api/editor/geometries/?section='+str(section.primary_section_pk),
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
@ -36,6 +38,20 @@ class Section(SpecificLocation, EditorFormMixin, models.Model):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
return Section.objects.filter(altitude__gt=self.altitude, on_top_of__isnull=True).order_by('altitude')
|
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
|
@property
|
||||||
def primary_section_pk(self):
|
def primary_section_pk(self):
|
||||||
return self.pk if self.on_top_of_id is None else self.on_top_of_id
|
return self.pk if self.on_top_of_id is None else self.on_top_of_id
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue