1 | import {Bean, Autowired} from "../context/context";
|
2 | import {IMenuFactory} from "../interfaces/iMenuFactory";
|
3 | import {FilterManager, FilterWrapper} from "../filter/filterManager";
|
4 | import {Column} from "../entities/column";
|
5 | import {Utils as _} from "../utils";
|
6 | import {PopupService} from "../widgets/popupService";
|
7 | import {GridOptionsWrapper} from "../gridOptionsWrapper";
|
8 | import {EventService} from "../eventService";
|
9 | import {IAfterGuiAttachedParams} from "../interfaces/iComponent";
|
10 |
|
11 | @Bean('menuFactory')
|
12 | export class StandardMenuFactory implements IMenuFactory {
|
13 |
|
14 | @Autowired('eventService')
|
15 | private eventService: EventService;
|
16 | @Autowired('filterManager')
|
17 | private filterManager: FilterManager;
|
18 | @Autowired('popupService')
|
19 | private popupService: PopupService;
|
20 | @Autowired('gridOptionsWrapper')
|
21 | private gridOptionsWrapper: GridOptionsWrapper;
|
22 |
|
23 | private hidePopup: ()=> void;
|
24 |
|
25 | public hideActiveMenu(): void {
|
26 | if (this.hidePopup) {
|
27 | this.hidePopup();
|
28 | }
|
29 | }
|
30 |
|
31 | public showMenuAfterMouseEvent(column: Column, mouseEvent: MouseEvent|Touch): void {
|
32 | this.showPopup(column, (eMenu: HTMLElement) => {
|
33 | this.popupService.positionPopupUnderMouseEvent({
|
34 | column: column,
|
35 | type: 'columnMenu',
|
36 | mouseEvent: mouseEvent,
|
37 | ePopup: eMenu
|
38 | });
|
39 | });
|
40 | }
|
41 |
|
42 | public showMenuAfterButtonClick(column: Column, eventSource: HTMLElement): void {
|
43 | this.showPopup(column, (eMenu: HTMLElement) => {
|
44 | this.popupService.positionPopupUnderComponent(
|
45 | {type: 'columnMenu', eventSource: eventSource,
|
46 | ePopup: eMenu, keepWithinBounds: true, column: column});
|
47 | });
|
48 | }
|
49 |
|
50 | public showPopup(column: Column, positionCallback: (eMenu: HTMLElement)=>void): void {
|
51 | let filterWrapper: FilterWrapper = this.filterManager.getOrCreateFilterWrapper(column);
|
52 |
|
53 | let eMenu = document.createElement('div');
|
54 | _.addCssClass(eMenu, 'ag-menu');
|
55 | filterWrapper.guiPromise.promise.then(gui=> {
|
56 | eMenu.appendChild(gui);
|
57 | });
|
58 |
|
59 | let hidePopup: () => void;
|
60 |
|
61 | let bodyScrollListener = (event: any) => {
|
62 |
|
63 | if (event.direction==='horizontal') {
|
64 | hidePopup();
|
65 | }
|
66 | };
|
67 |
|
68 | this.eventService.addEventListener('bodyScroll', bodyScrollListener);
|
69 | let closedCallback = ()=> {
|
70 | this.eventService.removeEventListener('bodyScroll', bodyScrollListener);
|
71 | column.setMenuVisible(false, "contextMenu");
|
72 | };
|
73 |
|
74 |
|
75 |
|
76 | hidePopup = this.popupService.addAsModalPopup(eMenu, true, closedCallback);
|
77 | positionCallback(eMenu);
|
78 |
|
79 | filterWrapper.filterPromise.then(filter=> {
|
80 | if (filter.afterGuiAttached) {
|
81 | let params: IAfterGuiAttachedParams = {
|
82 | hidePopup: hidePopup
|
83 | };
|
84 | filter.afterGuiAttached(params);
|
85 | }
|
86 | });
|
87 |
|
88 | this.hidePopup = hidePopup;
|
89 |
|
90 | column.setMenuVisible(true, "contextMenu");
|
91 | }
|
92 |
|
93 | public isMenuEnabled(column: Column): boolean {
|
94 |
|
95 | return this.gridOptionsWrapper.isEnableFilter() && column.isFilterAllowed();
|
96 | }
|
97 |
|
98 | }
|