diff options
-rw-r--r-- | http/res/ranking.js | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/http/res/ranking.js b/http/res/ranking.js index 1cf09ab..fca05e2 100644 --- a/http/res/ranking.js +++ b/http/res/ranking.js @@ -71,7 +71,7 @@ var ranking = { readHash : function() { var params = ranking.parseHash(location.hash); - var allParams = ['age', 'gender', 'region']; + var allParams = ['age', 'gender', 'region', 'name']; var paramsChanged = false; allParams.forEach(function(param) { var newParam = params.get(param) || []; @@ -86,13 +86,25 @@ var ranking = { $('button[data-filter="' + param + '"][data-value="' + value + '"]').addClass('btn-primary'); }); }); + var filtersPresent = false; allParams.forEach(function(param) { - if ($('button[data-filter="' + param + '"].btn-primary').size() == 0) { + if ($('button[data-filter="' + param + '"]').size() > 0 + && $('button[data-filter="' + param + '"].btn-primary').size() == 0) { $('button[data-clear="' + param + '"]').addClass('btn-primary'); } else { - $('#filters').collapse(); + filtersPresent |= ($('button[data-filter="' + param + '"]').size() > 0); + } + var field = $('input[data-filter-field="' + param + '"]'); + if (field.size() > 0) { + field.val(params.get(param)); + if (field.val().length > 0) { + filtersPresent = true; + } } }); + if (filtersPresent) { + $('#filters').collapse(); + } if (paramsChanged) { $('table.table-paginate').paginate('clear'); ranking.filterRows(params); @@ -117,7 +129,12 @@ var ranking = { var row = $(this); var hidden = false; params.forEach(function(value, param) { - if (param != 'page') { + if (param == 'name') { + if (row.find('td.' + param).text().trim().toLowerCase().search(value.join('')) == -1) { + row.hide(); + hidden = true; + } + } else if (param != 'page') { if (value.indexOf(row.find('td.' + param).text().trim()) == -1) { row.hide(); hidden = true; @@ -178,6 +195,20 @@ var ranking = { $(window).on('hashchange', ranking.readHash).trigger('hashchange'); }); + $('button[data-filter-action]').click(function(ev) { + if (!ranking.filtersDisabled) { + ranking.filtersDisabled = true; + $('table.data-table, .filters .panel-body').css('opacity', 0.1); + var button = $(this); + var params = ranking.parseHash(location.hash); + var param = params.get(button.attr('data-filter-action')); + var value = $('input[data-filter-field="' + button.attr('data-filter-action') + '"]').val().trim().toLowerCase(); + params.set(button.attr('data-filter-action'), [value]); + params.delete('page'); + location.hash = ranking.constructHash(params); + } + }); + $('button[data-filter]').click(function(ev) { if (!ranking.filtersDisabled) { ranking.filtersDisabled = true; |