From 8f3b3036df71113f8be00f21f1e5026b0c039eab Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Mon, 14 Sep 2015 21:29:02 +0200 Subject: [PATCH] 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. --- static/js/editor.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/static/js/editor.js b/static/js/editor.js index ff421f69..5cc255d3 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -55,13 +55,25 @@ pandora.ui.editor = function(data) { }) } : layer.autocomplete ? function(key, value, callback) { - pandora.api.autocomplete({ - key: key, - operator: '=', - range: [0, 20], - value: value - }, function(result) { - callback(result.data.items); + var keys = layer.autocompleteKeys && layer.autocompleteKeys.length + ? layer.autocompleteKeys + : [key]; + var n = keys.length; + var itemss = []; + + 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 });