Support autocomplete from a group of layers

The idea here is to have several layers which share a set of tags. This
mirrors what we already have if several layers reference the same type
of entity. You might have config like this:

        {
            "id": "keywords",
            "title": "Keywords",
            "canAddAnnotations": {"member": true, "staff": true, "admin": true},
            "item": "Keyword",
            "overlap": true,
            "type": "string",
            "autocomplete": true,
            "autocompleteKeys": ["keywords", "minorkeywords"]
        },
        {
            "id": "minorkeywords",
            "title": "Minor Keywords",
            "canAddAnnotations": {"member": true, "staff": true, "admin": true},
            "item": "Keyword",
            "overlap": true,
            "type": "string",
            "autocomplete": true,
            "autocompleteKeys": ["keywords", "minorkeywords"]
        },

Now, adding new keywords in either bin will offer autocompletions from
the union of the two layers. The other option would be to do this on the
server side, but I thought this was a less invasive way to achieve this.
This commit is contained in:
Will Thompson 2015-09-14 21:29:02 +02:00 committed by j
parent 4f064fda76
commit 8f3b3036df

View file

@ -55,13 +55,25 @@ pandora.ui.editor = function(data) {
}) })
} : layer.autocomplete } : layer.autocomplete
? function(key, value, callback) { ? function(key, value, callback) {
pandora.api.autocomplete({ var keys = layer.autocompleteKeys && layer.autocompleteKeys.length
key: key, ? layer.autocompleteKeys
operator: '=', : [key];
range: [0, 20], var n = keys.length;
value: value var itemss = [];
}, function(result) {
callback(result.data.items); keys.forEach(function(key) {
pandora.api.autocomplete({
key: key,
operator: '=',
range: [0, 20],
value: value
}, function(result) {
n--;
itemss.push(result.data.items);
if (n == 0) {
callback(Ox.unique(Ox.flatten(itemss)));
}
});
}); });
} : null } : null
}); });