summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-06-20 15:04:38 +0200
committeremkael <emkael@tlen.pl>2017-06-20 15:04:38 +0200
commit5ec21d8a5794599672a26e5abf7912b0e7f2a3c5 (patch)
tree74ee044bb4032bf30a709688639a56ff36a83859 /http
parentf74ae48f71ec95638ed2ebc6212dd40d815c78ff (diff)
Filtering by players' names
Diffstat (limited to 'http')
-rw-r--r--http/res/ranking.js39
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;