2019-05-31 15:01:54 +02:00
|
|
|
<template v-slot="default">
|
|
|
|
<div v-bind:id="blockid">
|
|
|
|
<SearchForm
|
|
|
|
v-if="displayform"
|
|
|
|
v-bind:form="form"></SearchForm>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-10-27 15:45:21 +02:00
|
|
|
import qs from 'querystring-es3'
|
|
|
|
|
2019-05-31 15:01:54 +02:00
|
|
|
import SearchForm from 'vuejs/components/Form/SearchForm'
|
|
|
|
import { mapState, mapActions } from 'vuex'
|
2021-09-16 21:40:18 +02:00
|
|
|
import MA from 'vuejs/api/ma-axios'
|
2019-05-31 15:01:54 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: ['blockid', 'formhtml'],
|
|
|
|
data(){
|
|
|
|
return {
|
|
|
|
form: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
2021-10-27 15:45:21 +02:00
|
|
|
canSearch: state => state.User.canSearch,
|
|
|
|
keys: state => state.Search.keys,
|
2022-08-12 17:00:49 +02:00
|
|
|
terms: state => state.Search.terms,
|
2021-10-27 15:45:21 +02:00
|
|
|
filters: state => state.Search.filters
|
2019-05-31 15:01:54 +02:00
|
|
|
}),
|
|
|
|
displayform(){
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('computed displayform')
|
2019-05-31 15:01:54 +02:00
|
|
|
return this.canSearch && this.form
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount() {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('SearchBlock beforeMount')
|
2019-05-31 15:01:54 +02:00
|
|
|
this.form = this.formhtml
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
canSearch(new_value, old_value) {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('canSearch changed, old: '+old_value+", new: "+new_value)
|
|
|
|
if (new_value && !this.form) {
|
2019-05-31 15:01:54 +02:00
|
|
|
this.getSearchForm()
|
|
|
|
}
|
2021-03-31 18:42:05 +02:00
|
|
|
if (!new_value && this.form) {
|
2019-05-31 15:01:54 +02:00
|
|
|
this.form = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getSearchForm(){
|
2021-10-27 15:45:21 +02:00
|
|
|
console.log('getSearchForm')
|
|
|
|
// var urlParams = new URLSearchParams(window.location.search);
|
|
|
|
// var urlParamsKeys = urlParams.keys()
|
|
|
|
const params = {
|
|
|
|
keys: this.keys,
|
2022-08-12 17:00:49 +02:00
|
|
|
terms: this.terms, //JSON.stringify(this.terms),
|
2021-10-27 15:45:21 +02:00
|
|
|
filters: this.filters
|
|
|
|
}
|
|
|
|
console.log('Search getSearchForm params', params)
|
|
|
|
const q = qs.stringify(params)
|
|
|
|
MA.get(`/materio_sapi/search_form?`+q)
|
2019-05-31 15:01:54 +02:00
|
|
|
.then(({data}) => {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('getSearchForm')
|
2019-05-31 15:01:54 +02:00
|
|
|
this.form = data.rendered
|
|
|
|
})
|
2021-03-31 18:42:05 +02:00
|
|
|
.catch((error) => {
|
2019-05-31 15:01:54 +02:00
|
|
|
console.warn('Issue with get searchform', error)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
SearchForm
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|