Skip to content

Commit

Permalink
fix toggle any filter (#1065)
Browse files Browse the repository at this point in the history
* fix toggle any filter

for multiselect checkbox groups:
if all selected --> others deselected
if other selected --> any deselected
if none selected --> any selected

* fix eslint error
joshmorel authored and mbeacom committed May 4, 2018
1 parent f45d40f commit fbf992a
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions app/assets/v2/js/pages/dashboard.js
Original file line number Diff line number Diff line change
@@ -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);
} else {
// Deselect option 'any' when another filter is selected
anyOption.prop('checked', false);
}
};

@@ -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');
@@ -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();
});

0 comments on commit fbf992a

Please sign in to comment.