reseting the filter box when you switch dynamically between maps

This commit is contained in:
Connor Turland 2014-08-11 12:04:06 -04:00
parent 22e07e4ca8
commit 995d49a5bd
2 changed files with 38 additions and 3 deletions

View file

@ -545,12 +545,13 @@ Metamaps.GlobalUI.Search = {
var win;
if (dataset == "topics") {
win = window.open('/topics/' + datum.id, '_blank');
win.focus();
} else if (dataset == "maps") {
win = window.open('/maps/' + datum.id, '_blank');
Metamaps.Router.maps(datum.id);
} else if (dataset == "mappers") {
win = window.open('/maps/mappers/' + datum.id, '_blank');
win.focus();
}
win.focus();
}
},
initSearchOptions: function () {

View file

@ -1989,6 +1989,36 @@ Metamaps.Filter = {
}
}, time);
},
reset: function () {
var self = Metamaps.Filter;
self.filters.metacodes = [];
self.filters.mappers = [];
self.filters.synapses = [];
self.visible.metacodes = [];
self.visible.mappers = [];
self.visible.synapses = [];
$('#filter_by_metacode ul').empty();
$('#filter_by_mapper ul').empty();
$('#filter_by_synapse ul').empty();
},
initializeFilterData: function () {
var self = Metamaps.Filter;
var check = function (filtersToUse, topicsOrSynapses, propertyToCheck) {
Metamaps[topicsOrSynapses].each(function(model) {
var prop = model.get(propertyToCheck) ? model.get(propertyToCheck).toString() : false;
if (prop && self.visible[filtersToUse].indexOf(prop) === -1) {
self.visible[filtersToUse].push(prop);
}
});
};
check('metacodes', 'Topics', 'metacode_id');
check('mappers', 'Topics', 'user_id');
check('mappers', 'Synapses', 'user_id');
check('synapses', 'Synapses', 'desc');
},
/*
Most of this data essentially depends on the ruby function which are happening for filter inside view filterBox
But what these function do is load this data into three accessible array within java : metacodes, mappers and synapses
@ -2720,9 +2750,13 @@ Metamaps.Map = {
Metamaps.JIT.prepareVizData();
// update filters
Metamaps.Filter.checkMappers();
Metamaps.Filter.reset();
Metamaps.Filter.initializeFilterData(); // this sets all the visible filters to true
// these three update the actual filter box with the right list items
Metamaps.Filter.checkMetacodes();
Metamaps.Filter.checkSynapses();
Metamaps.Filter.checkMappers();
}
$.ajax({