websiteMenu.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {ItemMenu, ItemsMenu, organizationState} from "~/types/interfaces";
  2. import BaseMenu from "~/use/layout/Menus/baseMenu";
  3. import * as _ from "lodash"
  4. class WebsiteMenu extends BaseMenu{
  5. private $ability:any;
  6. private $store:any;
  7. constructor($config:any, $ability:any, $store:any) {
  8. super($config)
  9. this.$ability = $ability
  10. this.$store = $store
  11. }
  12. /**
  13. * Construit le menu Site internet ou null si aucune page accessible
  14. * @return {ItemMenu | null}
  15. */
  16. getMenu():ItemMenu | null {
  17. const children:ItemsMenu = [];
  18. if(!this.$store.state.profile.organization.website && this.$store.state.profile.access.isAdminAccess){
  19. children.push(this.constructMenu('fa-globe-europe', 'simple_modification', this.getWebsite(this.$store.state.profile.organization), false, undefined, true))
  20. children.push(this.constructMenu('fa-globe-europe', 'advanced_modification', this.getWebsite(this.$store.state.profile.organization) + '/typo3', false, undefined, true))
  21. }
  22. return children.length > 0 ? this.constructMenu('fa-globe-europe', 'website', undefined, undefined, children) : null;
  23. }
  24. /**
  25. * Construit le menu Header des Sites internet ou null si aucune page accessible
  26. * @return {ItemMenu | null}
  27. */
  28. getHeaderMenu():ItemMenu | null {
  29. const children:ItemsMenu = [];
  30. children.push(this.constructMenu(this.$store.state.profile.organization.name, undefined, this.getWebsite(this.$store.state.profile.organization), false, undefined, true))
  31. _.each(this.$store.state.profile.organization.parents, parent => {
  32. children.push(this.constructMenu(parent.name, undefined, this.getWebsite(parent), false))
  33. })
  34. return children.length > 0 ? this.constructMenu('website', 'fa-globe-europe', undefined, undefined, children) : null;
  35. }
  36. getWebsite(organization:organizationState):string{
  37. return organization.website ? organization.website : this.$config.baseURL_typo3.replace('###subDomain###', organization.subDomain)
  38. }
  39. }
  40. export const getWebsiteMenu = ($config:any, $ability:any, $store:any) => new WebsiteMenu($config, $ability, $store)