communicationMenu.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import {ItemMenu, ItemsMenu} from "~/types/types";
  2. import BaseMenu from "~/use/layout/Menus/baseMenu";
  3. class CommunicationMenu extends BaseMenu{
  4. private $ability:any;
  5. constructor($config:any, $ability:any) {
  6. super($config)
  7. this.$ability = $ability
  8. }
  9. /**
  10. * Construit le menu Communication ou null si aucune page accessible
  11. * @return {ItemMenu | null}
  12. */
  13. getMenu():ItemMenu | null {
  14. const children:ItemsMenu = [];
  15. if (this.$ability().can('display', 'inbox_page')) {
  16. children.push(this.constructMenu('inbox', 'fa-inbox', '/messages/list/', true))
  17. }
  18. if (this.$ability().can('display', 'message_send_page')) {
  19. children.push(this.constructMenu('message_send', 'fa-paper-plane', '/messagessends/list/', true))
  20. }
  21. if (this.$ability().can('display', 'message_templates_page')) {
  22. children.push(this.constructMenu('message_templates', 'fa-edit', '/templates/list/', true))
  23. }
  24. if(children.length === 1){
  25. return children[0];
  26. }
  27. return children.length > 0 ? this.constructMenu('communication', 'fa-comments', undefined, undefined, children) : null;
  28. }
  29. }
  30. export const getCommunicationMenu= ($config:any, $ability:any) => new CommunicationMenu($config, $ability).getMenu()