add feature: swap locations

This commit is contained in:
Laura Klünder 2016-12-25 11:49:08 +01:00
parent 2ee8b8a8e1
commit 13883e91a6
2 changed files with 44 additions and 0 deletions

View file

@ -50,6 +50,7 @@ c3nav = {
$('.locationselect .close-map').click(c3nav._locationselect_close_map); $('.locationselect .close-map').click(c3nav._locationselect_close_map);
$('.locationselect .level-selector a').click(c3nav._locationselect_click_level); $('.locationselect .level-selector a').click(c3nav._locationselect_click_level);
$('.locationselect .map-container').on('click', 'img', c3nav._locationselect_click_image); $('.locationselect .map-container').on('click', 'img', c3nav._locationselect_click_image);
$('.location-group .swap').click(c3nav.swap_locations);
$('#route-from-here').click(c3nav._click_route_from_here); $('#route-from-here').click(c3nav._click_route_from_here);
$('#route-to-here').click(c3nav._click_route_to_here); $('#route-to-here').click(c3nav._click_route_to_here);
@ -74,6 +75,37 @@ c3nav = {
window.onpopstate = c3nav._onpopstate; window.onpopstate = c3nav._onpopstate;
}, },
swap_locations: function(e) {
e.preventDefault();
var origin_select = $('.origin-select');
var destination_select = $('.destination-select');
var has_orig = origin_select.is('.selected');
var has_dest = destination_select.is('.selected');
var orig_id = '',
orig_html = '',
dest_id = '',
dest_html = '';
if (has_orig) {
orig_id = origin_select.find('.id-field').val();
orig_html = origin_select.find('.locationselect-selected .location').html();
}
if (has_dest) {
dest_id = destination_select.find('.id-field').val();
dest_html = destination_select.find('.locationselect-selected .location').html();
destination_select.toggleClass('selected', has_orig);
destination_select.find('.id_field').val(orig_id);
destination_select.find('.locationselect-selected .location').html(orig_html);
}
if (has_orig) {
origin_select.toggleClass('selected', has_dest);
origin_select.find('.id_field').val(dest_id);
origin_select.find('.locationselect-selected .location').html(dest_html);
}
},
_locationselect_reset: function(e) { _locationselect_reset: function(e) {
e.preventDefault(); e.preventDefault();
var location_group = $(this).closest('.location-group'); var location_group = $(this).closest('.location-group');

View file

@ -2,6 +2,18 @@
<div class="col-md-{% if name == 'location' %}12{% else %}6{% endif %} location-group {{ name }}-select{% if location %} selected{% endif %}{% if active_field == name and map_level %} map{% endif %}"> <div class="col-md-{% if name == 'location' %}12{% else %}6{% endif %} location-group {{ name }}-select{% if location %} selected{% endif %}{% if active_field == name and map_level %} map{% endif %}">
<div class="form-group{% if search == name and not search_results %} has-error{% endif %}" data-name="{{ name }}"> <div class="form-group{% if search == name and not search_results %} has-error{% endif %}" data-name="{{ name }}">
<label for="{{ name }}_input">{{ heading }}</label> <label for="{{ name }}_input">{{ heading }}</label>
{% if name == 'destination' %}
{% if origin %}
{% if destination %}
<a class="swap pull-right" href="{% url 'site.route' origin=destination.location_id destination=origin.location_id %}">{% trans 'swap' %}</a>
{% else %}
<a class="swap pull-right" href="{% url 'site.destination' destination=origin.location_id %}">{% trans 'swap' %}</a>
{% endif %}
{% elif destination %}
<a class="swap pull-right" href="{% url 'site.origin' destination=destination.location_id %}">{% trans 'swap' %}</a>
{% endif %}
{% endif %}
<div class="locationselect"> <div class="locationselect">
<div class="locationselect-input"> <div class="locationselect-input">
{% if search == name and search_results %} {% if search == name and search_results %}