depicts/static/js/item.js

54 lines
1.3 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: [],
people: people,
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_person(person) {
var hit = person;
hit['count'] = 0;
this.new_depicts.push(hit);
},
2019-09-25 14:38:52 +01:00
add_depicts(hit) {
this.new_depicts.push(hit);
this.hits = [];
this.searchTerms = '';
2019-10-16 17:19:30 +01:00
this.$refs.search.focus();
2019-09-25 14:38:52 +01:00
},
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
});