Now also mark the filters accordingly to URL.

This commit is contained in:
Víðir Valberg Guðmundsson 2017-04-21 19:09:46 +02:00
parent 0dc10d3f95
commit 13631eac93
4 changed files with 22 additions and 39 deletions

View file

@ -82,6 +82,7 @@ webSocketBridge.listen(function(payload, stream) {
var location_parameter = findGetParameter('location') var location_parameter = findGetParameter('location')
var locations = location_parameter != null ? location_parameter.split(',') : []; var locations = location_parameter != null ? location_parameter.split(',') : [];
toggleFilterBoxes(types, locations);
render_schedule(types, locations); render_schedule(types, locations);
} }
}); });
@ -220,3 +221,20 @@ filter.addEventListener('change', function(e) {
render_schedule(types, event_locations); render_schedule(types, event_locations);
}); });
function toggleFilterBoxes(types, locations) {
var type_input = Array.prototype.slice.call(document.querySelectorAll('.event-type-checkbox'));
type_input.map(function(box) {
if(types.includes(box.value)) {
box.checked = !box.checked;
}
return box;
});
var location_input = Array.prototype.slice.call(document.querySelectorAll('.location-checkbox'));
location_input.map(function(box) {
if(locations.includes(box.value)) {
box.checked = !box.checked;
}
return box;
});
}

View file

@ -33,8 +33,7 @@
name="event-type-{{ type.slug }}" name="event-type-{{ type.slug }}"
id="event-type-{{ type.slug }}" id="event-type-{{ type.slug }}"
value="{{ type.slug }}" value="{{ type.slug }}"
class="form-control event-type-checkbox" class="form-control event-type-checkbox" />
checked />
<div class="btn-group"> <div class="btn-group">
<label for="event-type-{{ type.slug }}" class="btn btn-default" style="min-width: 200px; text-align: left;"> <label for="event-type-{{ type.slug }}" class="btn btn-default" style="min-width: 200px; text-align: left;">
@ -60,8 +59,7 @@
id="location-{{ location.slug }}" id="location-{{ location.slug }}"
name="locations" name="locations"
value="{{ location.slug }}" value="{{ location.slug }}"
class="form-control location-checkbox" class="form-control location-checkbox" />
checked />
<div class="btn-group"> <div class="btn-group">
<label for="location-{{ location.slug }}" class="btn btn-default" style="min-width: 200px; text-align: left;"> <label for="location-{{ location.slug }}" class="btn btn-default" style="min-width: 200px; text-align: left;">

View file

@ -234,41 +234,6 @@ class ScheduleView(CampViewMixin, TemplateView):
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super(ScheduleView, self).get_context_data(**kwargs) context = super(ScheduleView, self).get_context_data(**kwargs)
eventinstances = models.EventInstance.objects.filter(event__in=self.camp.events.all()).select_related()
type_slug = self.request.GET.get('type', None)
location_slug = self.request.GET.get('location', None)
if type_slug:
try:
eventtype = models.EventType.objects.get(
slug=type_slug
)
except models.EventType.DoesNotExist:
raise Http404
context['eventtype'] = eventtype
context['get_string'] = '?type={}'.format(type_slug)
eventinstances = eventinstances.filter(event__event_type=eventtype)
if location_slug:
try:
eventlocation = models.EventLocation.objects.get(
slug=location_slug,
camp=self.camp,
)
except models.EventLocation.DoesNotExist:
raise Http404
context['location'] = eventlocation
get_part = 'location={}'.format(location_slug)
if 'get_string' in context:
context['get_string'] = context['get_string'] + '&{}'.format(get_part)
else:
context['get_string'] = '?{}'.format(get_part)
eventinstances = eventinstances.filter(location=eventlocation)
context['eventinstances'] = eventinstances
# Do stuff if we are dealing with a day schedule # Do stuff if we are dealing with a day schedule
if 'day' in kwargs: if 'day' in kwargs:

View file

@ -153,7 +153,9 @@ footer {
padding: 5px; padding: 5px;
vertical-align: top; vertical-align: top;
margin: 5px; margin: 5px;
width: 200px;
max-width: 200px; max-width: 200px;
min-width: 200px;
min-height: 100px; min-height: 100px;
flex-grow: 1; flex-grow: 1;
border: 1px solid black; border: 1px solid black;