Only use one filter for each column

HFJ-1620
pull/17/head
Frode Petterson 2016-03-01 11:34:34 +01:00
parent a41ecccb9a
commit 35a0d09b9b
1 changed files with 40 additions and 44 deletions

View File

@ -90,14 +90,7 @@ var H5PDataView = (function ($) {
continue; continue;
} }
var facets = self.facets[col]; url += '&facets[' + col + ']=' + self.facets[col].id;
for (var facet in facets) {
if (!facets.hasOwnProperty(facet)) {
continue;
}
url += '&facets[' + col + '][]=' + facet;
}
} }
// Fire ajax request // Fire ajax request
@ -235,52 +228,55 @@ var H5PDataView = (function ($) {
H5PDataView.prototype.filterByFacet = function (col, id, text) { H5PDataView.prototype.filterByFacet = function (col, id, text) {
var self = this; var self = this;
if (self.facets[col] === undefined) { if (self.facets[col] !== undefined) {
self.facets[col] = {}; if (self.facets[col].id === id) {
return; // Don't use the same filter again
}
// Remove current filter for this col
self.facets[col].$tag.remove();
} }
// Only add if it isn't already added // Add to UI
if (self.facets[col][id] === undefined) { self.facets[col] = {
self.facets[col][id] = text; id: id,
'$tag': $('<span/>', {
// Add to UI
var $tag = $('<span/>', {
'class': 'h5p-facet-tag', 'class': 'h5p-facet-tag',
text: text, text: text,
appendTo: self.$facets, appendTo: self.$facets,
}); })
};
/** /**
* Callback for removing filter * Callback for removing filter.
* *
* @private * @private
*/ */
var remove = function () { var remove = function () {
delete self.facets[col][id]; self.facets[col].$tag.remove();
$tag.remove(); delete self.facets[col];
self.loadData(); self.loadData();
}; };
// Remove button // Remove button
$('<span/>', { $('<span/>', {
role: 'button', role: 'button',
tabindex: 0, tabindex: 0,
appendTo: $tag, appendTo: self.facets[col].$tag,
text: self.l10n.remove, text: self.l10n.remove,
title: self.l10n.remove, title: self.l10n.remove,
on: { on: {
click: remove, click: remove,
keypress: function (event) { keypress: function (event) {
if (event.which === 32) { if (event.which === 32) {
remove(); remove();
}
} }
} }
}); }
});
// Load data with new filter // Load data with new filter
self.loadData(); self.loadData();
}
}; };
/** /**