clear sidebar in _sidebar_unload

This commit is contained in:
Laura Klünder 2017-05-19 16:34:02 +02:00
parent ff615a6e28
commit 2ab1462349
6 changed files with 56 additions and 30 deletions

View file

@ -97,7 +97,7 @@ editor = {
_sidebar_unload: function() {
// unload the sidebar. called on sidebar_get and form submit.
editor._section_control.disable();
$('#sidebar').addClass('loading').find('.content').html();
$('#sidebar').addClass('loading').find('.content').html('');
editor._unhighlight_geometry();
editor._cancel_editing();
},

View file

@ -2,7 +2,7 @@
<ul data-sections>
{% for s in sections %}
<li>
<a href="{% url section_url pk=s.id %}"{% 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 == s %} class="current"{% endif %}>{{ s.title }}</a>
</li>
{% endfor %}
</ul>

View file

@ -11,3 +11,4 @@
<a href="{% url 'editor.index' %}">&laquo; {% trans 'back to overview' %}</a>
</p>
{% include 'editor/fragment_child_models.html' %}

View file

@ -0,0 +1,14 @@
{% load bootstrap3 %}
{% load i18n %}
{% include 'editor/fragment_sections.html' %}
<a class="btn btn-default btn-sm pull-right" accesskey="e" href="{% url 'editor.section.edit' pk=section.id %}">
{% trans 'Section' as model_title %}
{% blocktrans %}Edit {{ model_title }}{% endblocktrans %}
</a>
<h3>{{ section.title }}</h3>
<p>
<a href="{% url 'editor.index' %}">&laquo; {% trans 'back to overview' %}</a>
</p>
{% include 'editor/fragment_child_models.html' %}

View file

@ -3,13 +3,20 @@ from django.conf.urls import url
from c3nav.editor.views import edit, list_objects, main_index, section_detail
def add_editor_urls(name, model, parent_name_plural=None, parent_name=None):
prefix = '' if parent_name is None else parent_name_plural+r'/(?P<'+parent_name+'>[0-9]+)/'
return [
url(r'^'+prefix+name+r'/$', list_objects, name='editor.'+name+'.list', kwargs={'model': model}),
url(r'^'+prefix+name+r'/(?P<pk>[0-9]+)/$', edit, name='editor.'+name+'.edit', kwargs={'model': model}),
url(r'^'+prefix+name+r'/create$', edit, name='editor.'+name+'.create', kwargs={'model': model}),
]
def add_editor_urls(name, model, parent_name_plural=None, parent_name=None, with_list=True, explicit_edit=False):
prefix = ('' if parent_name is None else parent_name_plural+r'/(?P<'+parent_name+'>[0-9]+)/')+name
name_prefix = 'editor.'+name+'.'
kwargs = {'model': model, 'explicit_edit': explicit_edit}
explicit_edit = r'edit' if explicit_edit else ''
result = []
if with_list:
result.append(url(r'^'+prefix+r'/$', list_objects, name=name_prefix+'list', kwargs=kwargs))
result.extend([
url(r'^'+prefix+r'/(?P<pk>\d+)/'+explicit_edit+'$', edit, name=name_prefix+'edit', kwargs=kwargs),
url(r'^'+prefix+r'/create$', edit, name=name_prefix+'create', kwargs=kwargs),
])
return result
urlpatterns = [
@ -18,5 +25,7 @@ urlpatterns = [
url(r'^sections/(?P<pk>[0-9]+)/edit$', edit, name='editor.section.edit', kwargs={'model': 'Section'}),
url(r'^sections/create$', edit, name='editor.section.create', kwargs={'model': 'Section'}),
]
urlpatterns.extend(add_editor_urls('sections', 'Section', with_list=False, explicit_edit=True))
urlpatterns.extend(add_editor_urls('locationgroups', 'LocationGroup'))
urlpatterns.extend(add_editor_urls('spaces', 'Space', 'sections', 'section', explicit_edit=True))
urlpatterns.extend(add_editor_urls('doors', 'Door', 'sections', 'section'))

View file

@ -8,7 +8,7 @@ from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import never_cache
from c3nav.mapdata.models import LocationGroup, Section
from c3nav.mapdata.models import Door, LocationGroup, Section, Space
from c3nav.mapdata.models.base import EDITOR_FORM_MODELS
@ -170,20 +170,13 @@ def edit(request, pk=None, model=None, section=None, space=None, explicit_edit=F
@sidebar_view
def list_objects(request, model=None, section=None, space=None):
def list_objects(request, model=None, section=None, space=None, explicit_edit=False):
model = EDITOR_FORM_MODELS[model]
if not request.resolver_match.url_name.endswith('.list'):
raise ValueError('url_name does not end with .list')
reverse_kwargs = {}
if section is not None:
reverse_kwargs['section'] = section
if space is not None:
reverse_kwargs['space'] = space
# noinspection PyProtectedMember
ctx = {
'create_url': reverse(request.resolver_match.url_name[:-4]+'create', kwargs=reverse_kwargs),
'path': request.path,
'model_name': model.__name__.lower(),
'model_title': model._meta.verbose_name,
@ -191,23 +184,25 @@ def list_objects(request, model=None, section=None, space=None):
}
queryset = model.objects.all().order_by('id')
for obj in queryset:
reverse_kwargs['pk'] = obj.pk
obj.edit_url = reverse(request.resolver_match.url_name[:-4]+'edit', kwargs=reverse_kwargs)
reverse_kwargs.pop('pk', None)
reverse_kwargs = {}
if space is not None:
space = get_object_or_404(Section, pk=section)
queryset = queryset.filter(space=space)
ctx.update({
'back_url': reverse('editor.space', kwargs={'pk': space.pk}),
'back_title': _('back to space'),
})
elif section is not None:
if section is not None:
reverse_kwargs['section'] = section
section = get_object_or_404(Section, pk=section)
queryset = queryset.filter(section=section)
ctx.update({
'back_url': reverse('editor.section', kwargs={'pk': section.pk}),
'back_title': _('back to section'),
'sections': Section.objects.all(),
'section': section,
'section_url': request.resolver_match.url_name,
})
elif space is not None:
reverse_kwargs['space'] = space
space = get_object_or_404(Section, pk=space)
queryset = queryset.filter(space=space)
ctx.update({
'back_url': reverse('editor.space', kwargs={'pk': space.pk}),
'back_title': _('back to space'),
})
else:
@ -216,7 +211,14 @@ def list_objects(request, model=None, section=None, space=None):
'back_title': _('back to overview'),
})
edit_url_name = request.resolver_match.url_name[:-5]+('' if explicit_edit else '.edit')
for obj in queryset:
reverse_kwargs['pk'] = obj.pk
obj.edit_url = reverse(edit_url_name, kwargs=reverse_kwargs)
reverse_kwargs.pop('pk', None)
ctx.update({
'create_url': reverse(request.resolver_match.url_name[:-4] + 'create', kwargs=reverse_kwargs),
'objects': queryset,
})