From 9979ece0ca1500e7e7db683746fefccafbc48536 Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 12 Aug 2013 09:50:54 +0000 Subject: [PATCH] fix 'clear all filters' (fixes #1437) --- static/js/filter.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/static/js/filter.js b/static/js/filter.js index d7d5536e6..ca22e13e9 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -245,7 +245,10 @@ pandora.ui.filter = function(id) { }, click: function(data) { 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') { pandora.$ui.filters.clearFilters(); } @@ -258,12 +261,6 @@ pandora.ui.filter = function(id) { width: '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) { $menu.disableItem(id); }; @@ -279,9 +276,16 @@ pandora.ui.filters = function() { $filters[i] = pandora.ui.filter(filter.id); }); $filters.clearFilters = function() { - $filters.forEach(function($filter) { - $filter.clearFilter(); + var find = Ox.clone(pandora.user.ui.find, true), + 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() { var selected = $filters.map(function($filter) {