Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix toggle any filter #1065

Merged
merged 2 commits into from
May 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions app/assets/v2/js/pages/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,23 @@ var set_filter_header = function() {
$('#filter').html(filter_status);
};

// TODO: Refactor function :
// Deselect option 'any' when another filter is selected
// Selects option 'any' when no filter is applied
// TODO : Disable other filters when 'any' is selected
var disableAny = function() {
for (var i = 0; i < sidebar_keys.length; i++) {
var key = sidebar_keys[i];
var tag = ($('input[name=' + key + '][value]'));

tag.map(function(index, input) {
if ($(input).prop('checked')) {
if (input.value === 'any') {
$('input[name=' + key + '][value=any]').prop('checked', true);
} else {
$('input[name=' + key + '][value=any]').prop('checked', false);
}
}
});
var toggleAny = function(event) {
if (!event)
return;
var key = event.target.name;
var anyOption = $('input[name=' + key + '][value=any]');

if ($('input[name=' + key + ']:checked').length === 0) {
$('input[name=' + key + '][value=any]').prop('checked', true);
}
// Selects option 'any' when no filter is applied
if ($('input[name=' + key + ']:checked').length === 0) {
anyOption.prop('checked', true);
return;
}
if (event.target.value === 'any') {
// Deselect other filters when 'any' is selected
$('input[name=' + key + '][value!=any]').prop('checked', false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

} else {
// Deselect option 'any' when another filter is selected
anyOption.prop('checked', false);
}
};

Expand Down Expand Up @@ -368,10 +363,10 @@ var trigger_scroll = debounce(function() {
$(window).scroll(trigger_scroll);
$('body').bind('touchmove', trigger_scroll);

var refreshBounties = function() {
var refreshBounties = function(event) {
save_sidebar_latest();
set_filter_header();
disableAny();
toggleAny(event);
getFilters();

$('.nonefound').css('display', 'none');
Expand Down Expand Up @@ -679,7 +674,7 @@ $(document).ready(function() {

// sidebar filters
$('.sidebar_search input[type=checkbox], .sidebar_search label').change(function(e) {
refreshBounties();
refreshBounties(e);
e.preventDefault();
});

Expand Down