depicts/static/js/item.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-09-25 14:38:52 +01:00
var typingTimer;
var doneTypingInterval = 500;
2019-09-25 13:41:27 +01:00
var app = new Vue({
2019-09-25 14:38:52 +01:00
el: '#app',
data: {
prevTerms: '',
searchTerms: '',
hits: [],
new_depicts: [],
2019-10-07 14:12:30 +01:00
existing_depicts: existing_depicts,
2019-09-25 13:41:27 +01:00
},
2019-09-25 14:38:52 +01:00
methods: {
remove(index) {
2019-10-07 14:12:30 +01:00
this.$delete(this.new_depicts, index);
2019-09-25 14:38:52 +01:00
},
add_depicts(hit) {
this.new_depicts.push(hit);
this.hits = [];
this.searchTerms = '';
},
run_search() {
var terms = this.searchTerms;
if (terms == this.prevTerms) {
return; // no change
}
this.prevTerms = terms;
if (terms.length < 3) {
this.hits = [];
return;
}
2019-09-25 13:41:27 +01:00
2019-09-25 14:38:52 +01:00
var vm = this;
2019-09-25 13:41:27 +01:00
2019-09-25 14:38:52 +01:00
fetch(lookup_url + '?terms=' + encodeURI(terms))
.then((res) => res.json())
.then((data) => {
vm.hits = data.hits;
})
},
search(event) {
clearTimeout(typingTimer);
typingTimer = setTimeout(this.run_search, doneTypingInterval);
}
},
2019-09-25 13:41:27 +01:00
});