2021-03-08 21:11:14 +01:00
|
|
|
<script>
|
|
|
|
|
|
|
|
import Vue from 'vue'
|
|
|
|
|
|
|
|
import { mapState, mapActions } from 'vuex'
|
|
|
|
|
2021-09-16 21:40:18 +02:00
|
|
|
import MA from 'vuejs/api/ma-axios'
|
2021-03-08 21:11:14 +01:00
|
|
|
import router from 'vuejs/route'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
router,
|
|
|
|
props:['id','dom_html'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
html: null,
|
|
|
|
template: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
isloggedin: state => state.User.isloggedin
|
|
|
|
})
|
|
|
|
},
|
|
|
|
beforeMount() {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log("beforeMount header_menu", this.html)
|
|
|
|
if (!this.template) {
|
|
|
|
// console.log('no home_template')
|
|
|
|
if (this.dom_html) { // if html prop is available
|
2021-03-08 21:11:14 +01:00
|
|
|
this.html = this.dom_html
|
|
|
|
this.compileTemplate()
|
2021-03-31 18:42:05 +02:00
|
|
|
} else { // else get it from ajax
|
2021-03-08 21:11:14 +01:00
|
|
|
this.getMenuBlockHtml()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-03-29 22:28:24 +02:00
|
|
|
// ...mapActions({
|
|
|
|
// openCloseHamMenu: 'Common/openCloseHamMenu'
|
|
|
|
// }),
|
2021-03-08 21:11:14 +01:00
|
|
|
compileTemplate(){
|
|
|
|
this.template = Vue.compile(this.html)
|
|
|
|
},
|
|
|
|
getMenuBlockHtml(){
|
|
|
|
MA.get('materio_decoupled/ajax/getheadermenu')
|
|
|
|
.then(({data}) => {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('HeaderMenu getMenuBlockHtml data', data)
|
2021-03-08 21:11:14 +01:00
|
|
|
this.html = data.rendered // record the html src into data
|
|
|
|
})
|
2021-03-31 18:42:05 +02:00
|
|
|
.catch((error) => {
|
2021-03-08 21:11:14 +01:00
|
|
|
console.warn('Issue with getMenuBlockHtml', error)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onclick (event) {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log("Clicked on header menu link", event)
|
2021-03-08 21:11:14 +01:00
|
|
|
const href = event.target.getAttribute('href')
|
2021-03-29 22:28:24 +02:00
|
|
|
// this.openCloseHamMenu(false)
|
2021-03-08 21:11:14 +01:00
|
|
|
this.$router.push(href)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render(h) {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('headerMenu render')
|
|
|
|
if (!this.template) {
|
2021-06-01 22:46:15 +02:00
|
|
|
return h('span', $t('default.Loading…'))
|
2021-03-31 18:42:05 +02:00
|
|
|
} else {
|
2021-03-08 21:11:14 +01:00
|
|
|
return this.template.render.call(this)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
html(n, o) {
|
2021-03-08 22:04:50 +01:00
|
|
|
// console.log('header_menu html changed', o, n)
|
2021-03-08 21:11:14 +01:00
|
|
|
this.compileTemplate()
|
|
|
|
},
|
|
|
|
isloggedin(n, o) {
|
|
|
|
console.log("HeaderMenu isloggedin changed", o, n)
|
|
|
|
this.getMenuBlockHtml()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|