import person from "./person.js"; import raum from "./raum.js"; import employee from "./employee.js"; import organisationunit from "./organisationunit.js"; export default { props: [ "searchoptions", "searchfunction" ], data: function() { return { searchtimer: null, hidetimer: null, showsettings: false, searchsettings: { searchstr: '', types: [] }, showresult: false, searchresult: [], searching: false, error: null }; }, components: { person: person, raum: raum, employee: employee, organisationunit: organisationunit }, template: `
{{ this.error }}
Es wurden keine Ergebnisse gefunden.
`, beforeMount: function() { this.updateSearchOptions(); }, methods: { updateSearchOptions: function() { this.searchsettings.types = []; for( const idx in this.searchoptions.types ) { this.searchsettings.types.push(this.searchoptions.types[idx]); } }, calcSearchResultExtent: function() { var rect = this.$refs.searchbox.getBoundingClientRect(); //console.log(window.innerWidth + ' ' + window.innerHeight + ' ' + JSON.stringify(rect)); this.$refs.result.style.height = Math.floor(window.innerHeight * 0.80) + 'px'; }, search: function() { if( this.searchtimer !== null ) { clearTimeout(this.searchtimer); } if( this.searchsettings.searchstr.length >= 2 ) { this.calcSearchResultExtent(); this.searchtimer = setTimeout( this.callsearchapi, 500 ); } else { this.showresult = false; } }, callsearchapi: function() { var that = this; this.error = null; this.searchresult = []; this.searching = true; this.showsearchresult(); this.searchfunction(this.searchsettings) .then(function(response) { if( response.data?.error === 1 ) { that.error = 'Bei der Suche ist ein Fehler aufgetreten.'; } else { that.searchresult = response.data.data; } }) .catch(function(error) { that.error = 'Bei der Suche ist ein Fehler aufgetreten.' + ' ' + error.message; }) .finally(function() { that.searching = false; }); }, refreshsearch: function() { this.search(); this.togglesettings(); }, calcSearchSettingsExtent: function() { var rect = this.$refs.settingsbutton.getBoundingClientRect(); //console.log(window.innerWidth + ' ' + window.innerHeight + ' ' + JSON.stringify(rect)); this.$refs.settings.style.top = Math.floor(rect.bottom + 3) + 'px'; this.$refs.settings.style.right = Math.floor(window.innerWidth - rect.right) + 'px'; this.$refs.settings.style.width = Math.floor(window.innerWidth * 0.5) + 'px'; //this.$refs.settings.style.height = Math.floor(window.innerHeight * 0.5) + 'px'; }, togglesettings: function() { this.showsettings = !this.showsettings; this.calcSearchSettingsExtent(); }, hideresult: function() { this.showresult = false; window.removeEventListener('resize', this.calcSearchResultExtent); }, showsearchresult: function() { if( this.searchsettings.searchstr.length >= 3 ) { this.showresult = true; window.addEventListener('resize', this.calcSearchResultExtent); } }, searchfocusin: function(e) { e.preventDefault(); e.stopPropagation(); if( this.hidetimer !== null ) { clearTimeout(this.hidetimer); } }, searchfocusout: function(e) { e.preventDefault(); e.stopPropagation(); this.hidetimer = setTimeout( this.hideresult, 100 ); } } };