main.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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(){
  36. console.log("Clicked on logo");
  37. this.$router.push({name:'home'})
  38. }
  39. }
  40. })
  41. }
  42. function initVUserBlock(){
  43. let mount_point = drupalSettings.user.uid !== 0 ? 'block-userblock' : 'block-userlogin';
  44. let props = {
  45. title: "",
  46. loginblock:""
  47. };
  48. switch (mount_point) {
  49. case 'block-userlogin':
  50. let $block = document.getElementById(mount_point);
  51. console.log('initVUserBlock login form html', $block);
  52. props.loginblock = $block.outerHTML.trim()
  53. break;
  54. case 'block-userblock':
  55. default:
  56. break;
  57. }
  58. _v_user_block = new Vue({
  59. store,
  60. // computed: {
  61. // ...mapState({
  62. // isloggedin: state => state.User.isloggedin
  63. // })
  64. // },
  65. created () {
  66. // if already loggedin, call store.user to get the user infos
  67. if(drupalSettings.user.uid !== 0){
  68. this.$store.commit('User/setUid', drupalSettings.user.uid)
  69. this.$store.dispatch('User/getUser')
  70. }
  71. },
  72. render: h => h(VUserBlock, {props:props})
  73. }).$mount('#'+mount_point)
  74. // console.log('initVUserBlock', _v_user_block);
  75. }
  76. function initVMainContent(){
  77. let id = "main-content"
  78. let $main_content = document.querySelector('#'+id)
  79. // console.log('main-content', $main_content);
  80. let main_html = $main_content.innerHTML
  81. _v_main_content = new Vue({
  82. store,
  83. render: h => h(VMainContent, {props:{id:id, html:main_html}})
  84. }).$mount('#'+id)
  85. // console.log('initTestVContent', v_test_content);
  86. }
  87. function initVSearchBlock(){
  88. // console.log('initVSearchBlock');
  89. let id = "block-materiosapisearchblock"
  90. let $search_block = document.getElementById(id)
  91. var formhtml = null
  92. if($search_block){
  93. // get the search form html to pass it as template to the vue
  94. // we gain display speed vs async downloaded data
  95. formhtml = $search_block.innerHTML
  96. }else{
  97. // else create the empty block to fill it later with async data
  98. $search_block = document.createElement('div')
  99. $search_block.setAttribute('id', id)
  100. let $region = document.getElementById('content-top');
  101. $region.appendChild($search_block);
  102. }
  103. // in any case create the vue
  104. _v_search_block = new Vue({
  105. store,
  106. render: h => h(VSearchBlock, {props:{blockid:id, formhtml:formhtml}})
  107. }).$mount('#'+id)
  108. }
  109. init()
  110. } // end MaterioTheme()
  111. var materiotheme = new MaterioTheme();
  112. })(Drupal, drupalSettings);