placesDialog: fix getMatches function

This commit is contained in:
rolux 2013-02-27 17:06:54 +05:30
parent 8a6235b2b5
commit 6d4fb74a0d

View file

@ -22,24 +22,27 @@ pandora.ui.placesDialog = function(options) {
getMatches: function(names, callback) { getMatches: function(names, callback) {
// fixme: the results of this are of course // fixme: the results of this are of course
// not identical to actual place matches // not identical to actual place matches
var key, operator; var conditions = [], keys, operator;
if (names.length == 0) { if (names.length == 0) {
callback(0); callback(0);
} else { } else {
key = pandora.site.layers.filter(function(layer) { keys = pandora.site.layers.filter(function(layer) {
return layer.type == 'place' || layer.hasPlaces; return layer.type == 'place' || layer.hasPlaces;
}).map(function(layer) { }).map(function(layer) {
return layer.id; return layer.id;
})[0], });
keys.forEach(function(key) {
operator = Ox.getObjectById( operator = Ox.getObjectById(
pandora.site.layers, key pandora.site.layers, key
).type == 'place' ? '==' : '='; ).type == 'place' ? '==' : '=';
names.forEach(function(name) {
conditions.push({key: key, value: name, operator: operator});
});
});
pandora.api.findClips({ pandora.api.findClips({
query: { query: {
conditions: names.map(function(name) { conditions: conditions,
return {key: key, value: name, operator: operator}; operator: conditions.length == 1 ? '&' : '|'
}),
operator: names.length == 1 ? '&' : '|'
} }
}, function(result) { }, function(result) {
callback(result.data.items); callback(result.data.items);