fix 'clear all filters' (fixes #1437)

This commit is contained in:
rolux 2013-08-12 09:50:54 +00:00
parent 95a1995ad9
commit 9979ece0ca

View file

@ -245,7 +245,10 @@ pandora.ui.filter = function(id) {
}, },
click: function(data) { click: function(data) {
if (data.id == 'clearFilter') { if (data.id == 'clearFilter') {
that.clearFilter(); // FIXME: List should trigger event on options change
if (!Ox.isEmpty(that.options('selected'))) {
that.options({selected: []}).triggerEvent('select', {ids: []});
}
} else if (data.id == 'clearFilters') { } else if (data.id == 'clearFilters') {
pandora.$ui.filters.clearFilters(); pandora.$ui.filters.clearFilters();
} }
@ -258,12 +261,6 @@ pandora.ui.filter = function(id) {
width: '8px', width: '8px',
height: '8px' height: '8px'
}); });
that.clearFilter = function() {
// FIXME: List should trigger event on options change
if (!Ox.isEmpty(that.options('selected'))) {
that.options({selected: []}).triggerEvent('select', {ids: []});
}
};
that.disableMenuItem = function(id) { that.disableMenuItem = function(id) {
$menu.disableItem(id); $menu.disableItem(id);
}; };
@ -279,9 +276,16 @@ pandora.ui.filters = function() {
$filters[i] = pandora.ui.filter(filter.id); $filters[i] = pandora.ui.filter(filter.id);
}); });
$filters.clearFilters = function() { $filters.clearFilters = function() {
$filters.forEach(function($filter) { var find = Ox.clone(pandora.user.ui.find, true),
$filter.clearFilter(); indices = pandora.user.ui._filterState.map(function(filterState) {
return filterState.index;
}).filter(function(index) {
return index > -1;
});
find.conditions = find.conditions.filter(function(condition, index) {
return !Ox.contains(indices, index);
}); });
pandora.UI.set({find: find})
}; };
$filters.updateMenus = function() { $filters.updateMenus = function() {
var selected = $filters.map(function($filter) { var selected = $filters.map(function($filter) {