diff --git a/src/components/Autocomplete.vue b/src/components/Autocomplete.vue index 725f182731a9d80479c807c811ecf1f21074f0bb..4218bb3963529805bcaf37c235ac879a6706e471 100644 --- a/src/components/Autocomplete.vue +++ b/src/components/Autocomplete.vue @@ -62,37 +62,17 @@ select(item) { if (item) { if (typeof item != 'string') { - let self = this - /* - if (item.articles) { - axios.get(self.endpoint + 'articles?', {params: {lord: item.match, - dict: self.$parent.lang}}) - .then( - function(response) { - ['bob', 'nob'].forEach((dict_tag) => { - response.data[dict_tag].forEach((article_id) => { - let article = {} - article.article_id = article_id - article.dictionary = dict_tag - article.match = item.match - item.articles.push(article) - }) - }) - } - ) + this.items = [] + this.suggesting = false + if (item.article_promise) { + item.article_promise.then((response) => { + item.article_ids = response.data + this.submit(item) + }) + } + else { + this.submit(item) } - */ - this.items = [] - this.suggesting = false - - self.$emit('submit', item) - - setTimeout(() => { - self.$refs.autocomplete.$refs.input.select() - this.items = [] - this.suggesting = false - }, 1) - } // If blurred else { @@ -123,7 +103,7 @@ let hits = [] response.data.forEach((item, i) => { - let hit = {q: q, match: item[0], label: item[0], articles: []} + let hit = {q: q, match: item[0], label: item[0], article_promise: self.get_articles(item[0])} hit.lang = item[1] hits.push(hit) @@ -132,12 +112,25 @@ hits.push({q: q, label: q + ' '}) self.items = hits } - self.loading = false }) }, + get_articles(match) { + let self = this + return axios.get(self.endpoint + 'articles?', {params: {lord: match, dict: self.$parent.lang}}) + }, + submit(item) { + this.$emit('submit', item) + let self = this + + setTimeout(() => { + self.$refs.autocomplete.$refs.input.select() + this.items = [] + this.suggesting = false + }, 1) + } }, } </script>