Commit f8b7ad16 authored by okhin's avatar okhin
Browse files

Adding filters

parent 7a51ee2c
Pipeline #876 passed with stage
in 1 second
...@@ -29,6 +29,9 @@ class Controller { ...@@ -29,6 +29,9 @@ class Controller {
// Workaround for caching variables // Workaround for caching variables
$f3->set('contacts', $f3->get('contacts')); $f3->set('contacts', $f3->get('contacts'));
$groups = Api::get_groups();
$f3->set('groups', $groups);
$group_types = Api::get_group_types(); $group_types = Api::get_group_types();
$f3->set('group_types', $group_types); $f3->set('group_types', $group_types);
} }
......
...@@ -6,6 +6,16 @@ ...@@ -6,6 +6,16 @@
<input type="search" id="search" class="autocomplete"> <input type="search" id="search" class="autocomplete">
<label class="label-icon" for="search"><i class="material-icons">search</i></label> <label class="label-icon" for="search"><i class="material-icons">search</i></label>
</div> </div>
<repeat group="{{ @group_types }}" value="{{ @group_type }}">
<div class="input-field">
<label for="{{ @group_type.name }}">{{ @group_type.name }}</label>
<select class="filter" id="{{ @group_type.name }}" name="{{ @group_type.name }}">
<repeat group="{{ @groups }}" value="{{ @group }}">
<option value="{{ @group.id }}">{{ @group.name }}</option>
</repeat>
</select>
</div>
</repeat>
</div> </div>
</nav> </nav>
<div class="wrapper" data-json='{{ json_encode(@contacts) }}'> <div class="wrapper" data-json='{{ json_encode(@contacts) }}'>
...@@ -24,6 +34,21 @@ $(document).ready(function() { ...@@ -24,6 +34,21 @@ $(document).ready(function() {
limit: 20, limit: 20,
}); });
$('select.filter').change(function() {
var filter_group = $(this).val();
var contacts = JSON.parse(wrapper.attr('data-json'));
contacts = contacts.filter(function(contact) {
var keep = false
contact['groups'].forEach(function(group) {
if (group['id'] === Number(filter_group)) {
keep = true;
};
});
return keep;
});
list_meps(contacts, $('.contact .wrapper'));
});
$('#search').change(function() { $('#search').change(function() {
var contacts = JSON.parse(wrapper.attr('data-json')); var contacts = JSON.parse(wrapper.attr('data-json'));
contacts = contacts.filter(function(contact) { contacts = contacts.filter(function(contact) {
...@@ -38,6 +63,8 @@ $(document).ready(function() { ...@@ -38,6 +63,8 @@ $(document).ready(function() {
var random = Math.floor((Math.random() * $('.collection-item').length)); var random = Math.floor((Math.random() * $('.collection-item').length));
update_mep($('.collection-item').eq(random)); update_mep($('.collection-item').eq(random));
$('select').material_select();
}); });
function list_meps(contacts, wrapper) { function list_meps(contacts, wrapper) {
...@@ -73,18 +100,26 @@ function display_mep(contact) { ...@@ -73,18 +100,26 @@ function display_mep(contact) {
var group = contact['groups'].filter(function(group) { var group = contact['groups'].filter(function(group) {
return group['type'] === 'group'; return group['type'] === 'group';
}); });
var group_src = 'http://www.europarl.europa.eu/ep_framework/img/group/group_iconsmall_' if ( group.length > 0 ) {
+ group[0]['name'].toLowerCase().replace('/','') + '.png'; var group_src = 'http://www.europarl.europa.eu/ep_framework/img/group/group_iconsmall_'
var country_src = 'http://www.europarl.europa.eu/ep_framework/img/flag/flag_icon_' + group[0]['name'].toLowerCase().replace('/','') + '.png';
+ country[0]['name'].toLowerCase().replace('/','') + '.gif'; $('<img />').attr('src', group_src)
$('<img />').addClass('circle') .appendTo(li);
.attr('src', country_src) };
.appendTo(li) if ( country.length > 0 ) {
var country_src = 'http://www.europarl.europa.eu/ep_framework/img/flag/flag_icon_'
+ country[0]['name'].toLowerCase().replace('/','') + '.gif';
$('<img />').addClass('circle')
.attr('src', country_src)
.appendTo(li)
} else {
$('<img />').addClass('circle')
.attr('src', '/static/img/placeholder.jpg')
.appendTo(li)
};
$('<span />').addClass('title') $('<span />').addClass('title')
.text(contact['full_name']) .text(contact['full_name'])
.appendTo(li); .appendTo(li);
$('<img />').attr('src', group_src)
.appendTo(li);
var groups = $('<ul />') var groups = $('<ul />')
.appendTo(li); .appendTo(li);
contact['groups'].forEach(function(group) { contact['groups'].forEach(function(group) {
...@@ -124,14 +159,18 @@ function update_mep(element) { ...@@ -124,14 +159,18 @@ function update_mep(element) {
return group['type'] === 'group'; return group['type'] === 'group';
}); });
var group_src = 'http://www.europarl.europa.eu/ep_framework/img/group/group_iconsmall_' if ( group.length > 0 ) {
+ group[0]['name'].toLowerCase().replace('/','') + '.png'; var group_src = 'http://www.europarl.europa.eu/ep_framework/img/group/group_iconsmall_'
var country_src = 'http://www.europarl.europa.eu/ep_framework/img/flag/flag_icon_' + group[0]['name'].toLowerCase().replace('/','') + '.png';
+ country[0]['name'].toLowerCase() .replace('/','')+ '.gif'; $('.card-content .group').text(group[0]['name'])
$('.card-content .group').text(group[0]['name']) .append($('<img>').attr('src', group_src));
.append($('<img>').attr('src', group_src)); };
$('.card-content .country').text(country[0]['name']) if (country.length > 0) {
.append($('<img>').attr('src', country_src)); var country_src = 'http://www.europarl.europa.eu/ep_framework/img/flag/flag_icon_'
+ country[0]['name'].toLowerCase() .replace('/','')+ '.gif';
$('.card-content .country').text(country[0]['name'])
.append($('<img>').attr('src', country_src));
};
$('#contact-phone').attr('href', 'tel:' + contact['phone']); $('#contact-phone').attr('href', 'tel:' + contact['phone']);
$('#contact-phone').text(contact['phone']); $('#contact-phone').text(contact['phone']);
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment