site: allow setting locations by url
This commit is contained in:
parent
584e99559c
commit
7528686e87
6 changed files with 91 additions and 10 deletions
|
@ -6,6 +6,9 @@ body {
|
||||||
.locationselect .input-lg {
|
.locationselect .input-lg {
|
||||||
height: 62px;
|
height: 62px;
|
||||||
}
|
}
|
||||||
|
.locationselect > div {
|
||||||
|
position:relative;
|
||||||
|
}
|
||||||
.locationselect .locationselect-selected {
|
.locationselect .locationselect-selected {
|
||||||
display:none;
|
display:none;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +18,21 @@ body {
|
||||||
.locationselect.selected .locationselect-input {
|
.locationselect.selected .locationselect-input {
|
||||||
display:none;
|
display:none;
|
||||||
}
|
}
|
||||||
|
.locationselect .icons {
|
||||||
|
height:48px;
|
||||||
|
position:absolute;
|
||||||
|
right:7px;
|
||||||
|
top:7px;
|
||||||
|
opacity:0.5;
|
||||||
|
}
|
||||||
|
.locationselect .icons a {
|
||||||
|
display:inline-block;
|
||||||
|
width:48px;
|
||||||
|
height:48px;
|
||||||
|
}
|
||||||
|
.locationselect .icons .reset {
|
||||||
|
background-image:url('/static/site/img/icons/cross.svg');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.location {
|
.location {
|
||||||
|
|
|
@ -27,9 +27,19 @@ c3nav = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
c3nav.update_history_state(true);
|
||||||
c3nav.init_typeahead($('.locationselect input:text'));
|
c3nav.init_typeahead($('.locationselect input:text'));
|
||||||
|
|
||||||
$('.locationselect:not(.selected) .locationselect-input .tt-input').first().focus();
|
$('.locationselect:not(.selected) .locationselect-input .tt-input').first().focus();
|
||||||
|
$('.locationselect .icons .reset').click(c3nav._locationselect_reset)
|
||||||
|
},
|
||||||
|
|
||||||
|
_locationselect_reset: function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var locationselect = $(this).closest('.locationselect');
|
||||||
|
locationselect.find('.name-field').val('');
|
||||||
|
locationselect.removeClass('selected').find('.tt-input').focus().keyup().removeData('enter_item');
|
||||||
|
c3nav.update_history_state();
|
||||||
},
|
},
|
||||||
|
|
||||||
init_typeahead: function(elem) {
|
init_typeahead: function(elem) {
|
||||||
|
@ -58,6 +68,7 @@ c3nav = {
|
||||||
selected.find('.subtitle').text(item.subtitle);
|
selected.find('.subtitle').text(item.subtitle);
|
||||||
selected.find('.name-field').val(item.name);
|
selected.find('.name-field').val(item.name);
|
||||||
e.target.blur();
|
e.target.blur();
|
||||||
|
c3nav.update_history_state();
|
||||||
|
|
||||||
$('.locationselect:not(.selected) .locationselect-input .tt-input').first().focus();
|
$('.locationselect:not(.selected) .locationselect-input .tt-input').first().focus();
|
||||||
},
|
},
|
||||||
|
@ -66,6 +77,26 @@ c3nav = {
|
||||||
},
|
},
|
||||||
_typeahead_cursorchange: function(e, item) {
|
_typeahead_cursorchange: function(e, item) {
|
||||||
$(e.target).data('enter_item', item);
|
$(e.target).data('enter_item', item);
|
||||||
|
},
|
||||||
|
|
||||||
|
update_history_state: function(e, replace) {
|
||||||
|
var origin = $(':input[name=origin]').val();
|
||||||
|
var destination = $(':input[name=destination]').val();
|
||||||
|
url = '/';
|
||||||
|
if (origin !== '') {
|
||||||
|
url += origin + '/'
|
||||||
|
if (destination !== '') {
|
||||||
|
url += destination + '/'
|
||||||
|
}
|
||||||
|
} else if (destination !== '') {
|
||||||
|
url += '_/' + destination + '/'
|
||||||
|
}
|
||||||
|
if (replace) {
|
||||||
|
history.replaceState({}, '', url);
|
||||||
|
} else {
|
||||||
|
history.pushState({}, '', url);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$(document).ready(c3nav.init);
|
$(document).ready(c3nav.init);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="{ name }}_input">{{ heading }}</label>
|
<label for="{ name }}_input">{{ heading }}</label>
|
||||||
<div class="locationselect{% if location %} selected{% endif %}">
|
<div class="locationselect {% if location %} selected{% endif %}">
|
||||||
<div class="locationselect-input">
|
<div class="locationselect-input">
|
||||||
<input type="text" class="form-control input-lg" id="{ name }}_input" name="{{ name }}_search" placeholder="{% trans 'Search any Location…' %}">
|
<input type="text" class="form-control input-lg" id="{ name }}_input" name="{{ name }}_search" placeholder="{% trans 'Search any Location…' %}">
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,6 +10,9 @@
|
||||||
<span class="title">{{ location.title }}</span>
|
<span class="title">{{ location.title }}</span>
|
||||||
<small class="subtitle">{{ location.subtitle }}</small>
|
<small class="subtitle">{{ location.subtitle }}</small>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="icons">
|
||||||
|
<a href="" class="reset"></a>
|
||||||
|
</div>
|
||||||
<input type="hidden" name="{{ name }}" value="{{ location.name }}" class="name-field">
|
<input type="hidden" name="{{ name }}" value="{{ location.name }}" class="name-field">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.views.generic import TemplateView
|
|
||||||
|
from c3nav.site.views import main
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', TemplateView.as_view(template_name='site/index.html'), name='site.index')
|
url(r'^(?P<origin>[a-z0-9-_:]+)/$', main, name='site.main'),
|
||||||
|
url(r'^_/(?P<destination>[a-z0-9-_:]+)/$', main, name='site.main'),
|
||||||
|
url(r'^(?P<origin>[a-z0-9-_:]+)/(?P<destination>[a-z0-9-_:]+)/$', main, name='site.main'),
|
||||||
|
url(r'^$', main, name='site.main')
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,10 +1,35 @@
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.shortcuts import redirect, render
|
||||||
|
|
||||||
from c3nav.mapdata.utils.cache import get_levels_cached
|
from c3nav.mapdata.locations import get_location
|
||||||
|
|
||||||
|
|
||||||
def main(request):
|
def main(request, origin=None, destination=None):
|
||||||
get_levels_cached()
|
do_redirect = False
|
||||||
_
|
|
||||||
src = request.POST if request.method == 'POST' else request.GET
|
if origin:
|
||||||
src == 5
|
origin_obj = get_location(request, origin)
|
||||||
|
if origin_obj.name != origin:
|
||||||
|
do_redirect = True
|
||||||
|
origin = origin_obj
|
||||||
|
|
||||||
|
if destination:
|
||||||
|
destination_obj = get_location(request, destination)
|
||||||
|
if destination_obj.name != destination:
|
||||||
|
do_redirect = True
|
||||||
|
destination = destination_obj
|
||||||
|
|
||||||
|
if do_redirect:
|
||||||
|
new_url = '/'
|
||||||
|
if origin:
|
||||||
|
new_url += origin.name+'/'
|
||||||
|
if destination:
|
||||||
|
new_url += destination.name + '/'
|
||||||
|
elif destination:
|
||||||
|
new_url += '_/' + destination.name + '/'
|
||||||
|
|
||||||
|
redirect(new_url)
|
||||||
|
|
||||||
|
return render(request, 'site/main.html', {
|
||||||
|
'origin': origin,
|
||||||
|
'destination': destination
|
||||||
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue