main.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import Vue from 'vue'
  2. import store from 'vuejs/store'
  3. import router from 'vuejs/route'
  4. import VUserBlock from 'vuejs/components/Block/UserBlock'
  5. import VMainContent from 'vuejs/components/Content/MainContent'
  6. import VSearchBlock from 'vuejs/components/Block/SearchBlock'
  7. import { mapState } from 'vuex'
  8. // require('theme/assets/styles/main.scss');
  9. import 'theme/assets/styles/main.scss'
  10. (function(Drupal, drupalSettings) {
  11. var MaterioTheme = function(){
  12. var _v_sitebranding_block, _v_user_block, _v_main_content, _v_search_block;
  13. var _is_front = drupalSettings.path.isFront;
  14. console.log('drupalSettings', drupalSettings);
  15. // ___ _ _
  16. // |_ _|_ _ (_) |_
  17. // | || ' \| | _|
  18. // |___|_||_|_|\__|
  19. function init(){
  20. console.log("MaterioTheme init()")
  21. initVues()
  22. }
  23. function initVues(){
  24. initVSiteBrandingBlock()
  25. initVUserBlock()
  26. initVMainContent()
  27. initVSearchBlock()
  28. }
  29. function initVSiteBrandingBlock(){
  30. _v_sitebranding_block = new Vue({
  31. store,
  32. router,
  33. el: '#block-sitebranding',
  34. methods: {
  35. onclick(event){
  36. // console.log("Clicked on logo event", event);
  37. let href = event.target.getAttribute('href');
  38. // console.log("Clicked on logo href", href);
  39. this.$router.push(href)
  40. }
  41. }
  42. })
  43. }
  44. function initVUserBlock(){
  45. let mount_point = drupalSettings.user.uid !== 0 ? 'block-userblock' : 'block-userlogin';
  46. let props = {
  47. title: "",
  48. loginblock:""
  49. };
  50. switch (mount_point) {
  51. case 'block-userlogin':
  52. let $block = document.getElementById(mount_point);
  53. console.log('initVUserBlock login form html', $block);
  54. props.loginblock = $block.outerHTML.trim()
  55. break;
  56. case 'block-userblock':
  57. default:
  58. break;
  59. }
  60. _v_user_block = new Vue({
  61. store,
  62. // computed: {
  63. // ...mapState({
  64. // isloggedin: state => state.User.isloggedin
  65. // })
  66. // },
  67. created () {
  68. // if already loggedin, call store.user to get the user infos
  69. if(drupalSettings.user.uid !== 0){
  70. this.$store.commit('User/setUid', drupalSettings.user.uid)
  71. this.$store.dispatch('User/getUser')
  72. }
  73. },
  74. render: h => h(VUserBlock, {props:props})
  75. }).$mount('#'+mount_point)
  76. // console.log('initVUserBlock', _v_user_block);
  77. }
  78. function initVMainContent(){
  79. let id = "main-content"
  80. let $main_content = document.querySelector('#'+id)
  81. // console.log('main-content', $main_content);
  82. let main_html = $main_content.innerHTML
  83. _v_main_content = new Vue({
  84. store,
  85. render: h => h(VMainContent, {props:{id:id, html:main_html, isfront:drupalSettings.path.isFront}})
  86. }).$mount('#'+id)
  87. // console.log('initTestVContent', v_test_content);
  88. }
  89. function initVSearchBlock(){
  90. // console.log('initVSearchBlock');
  91. let id = "block-materiosapisearchblock"
  92. let $search_block = document.getElementById(id)
  93. var formhtml = null
  94. if($search_block){
  95. // get the search form html to pass it as template to the vue
  96. // we gain display speed vs async downloaded data
  97. formhtml = $search_block.innerHTML
  98. }else{
  99. // else create the empty block to fill it later with async data
  100. $search_block = document.createElement('div')
  101. $search_block.setAttribute('id', id)
  102. let $region = document.getElementById('content-top');
  103. $region.appendChild($search_block);
  104. }
  105. // in any case create the vue
  106. _v_search_block = new Vue({
  107. store,
  108. render: h => h(VSearchBlock, {props:{blockid:id, formhtml:formhtml}})
  109. }).$mount('#'+id)
  110. }
  111. init()
  112. } // end MaterioTheme()
  113. var materiotheme = new MaterioTheme();
  114. })(Drupal, drupalSettings);