From ad7b21fbefbaa08ac4690323c36dce092681b4f7 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 22 Apr 2012 12:50:03 +0000 Subject: [PATCH] don't make filter requests (a total of 15) when filters are collapsed --- static/js/pandora/browser.js | 7 +++++++ static/js/pandora/filter.js | 9 +++++---- static/js/pandora/mainPanel.js | 17 ++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/static/js/pandora/browser.js b/static/js/pandora/browser.js index bd074321..e343e4f3 100644 --- a/static/js/pandora/browser.js +++ b/static/js/pandora/browser.js @@ -39,6 +39,13 @@ pandora.ui.browser = function() { toggle: function(data) { data.collapsed && pandora.$ui.list.gainFocus(); pandora.UI.set({showFilters: !data.collapsed}); + if (!data.collapsed) { + pandora.$ui.filters.forEach(function($filter) { + if ($filter.options('_reload')) { + $filter.options({_reload: false}).reloadList(); + } + }); + } if (pandora.user.ui.listView == 'map') { pandora.$ui.map.resizeMap(); } else if (pandora.user.ui.listView == 'calendar') { diff --git a/static/js/pandora/filter.js b/static/js/pandora/filter.js index 76633657..ff29f03c 100644 --- a/static/js/pandora/filter.js +++ b/static/js/pandora/filter.js @@ -7,6 +7,7 @@ pandora.ui.filter = function(id) { title = Ox.getObjectById(pandora.site.filters, id).title, //width = pandora.getFilterWidth(i, panelWidth), that = Ox.TextList({ + _reload: !pandora.user.ui.showFilters, columns: [ { align: 'left', @@ -58,15 +59,15 @@ pandora.ui.filter = function(id) { columnsVisible: true, id: 'filter_' + id, items: function(data, callback) { - //if (pandora.user.ui.showFilters) { + if (pandora.user.ui.showFilters) { delete data.keys; return pandora.api.find(Ox.extend(data, { group: id, query: pandora.user.ui._filterState[i].find }), callback); - //} else { - // callback({data: {items: data.keys ? [] : 0}}); - //} + } else { + callback({data: {items: data.keys ? [] : 0}}); + } }, scrollbarVisible: true, selected: pandora.user.ui._filterState[i].selected, diff --git a/static/js/pandora/mainPanel.js b/static/js/pandora/mainPanel.js index a3f11de1..64fd0827 100644 --- a/static/js/pandora/mainPanel.js +++ b/static/js/pandora/mainPanel.js @@ -36,13 +36,20 @@ pandora.ui.mainPanel = function() { // FIXME: why is this being handled _here_? pandora.user.ui._filterState.forEach(function(data, i) { if (!Ox.isEqual(data.selected, previousUI._filterState[i].selected)) { - pandora.$ui.filters[i].options({selected: data.selected}); + if (pandora.user.ui.showFilters) { + pandora.$ui.filters[i].options({selected: data.selected}); + } else { + pandora.$ui.filters[i].options({_reload: true, selected: []}); + } } if (!Ox.isEqual(data.find, previousUI._filterState[i].find)) { - Ox.Log('FIND', 'NOT EQUAL', data.find, previousUI._filterState[i].find) - pandora.$ui.filters[i].reloadList(); - } else { - Ox.Log('FIND', 'EQUAL', data.find, previousUI._filterState[i].find) + if (pandora.user.ui.showFilters) { + pandora.$ui.filters[i].reloadList(); + } else { + // we can call reloadList here, since the items function + // handles the hidden filters case without making requests + pandora.$ui.filters[i].options({_reload: true}).reloadList(); + } } }); } else {