63 lines
No EOL
2 KiB
JavaScript
63 lines
No EOL
2 KiB
JavaScript
import { CoreEvents } from '../constants/CoreEvents';
|
|
/**
|
|
* NavigationButtonsManager - Manages navigation button UI and state
|
|
*
|
|
* RESPONSIBILITY:
|
|
* ===============
|
|
* This manager owns all logic related to the <swp-nav-group> UI element.
|
|
* It follows the principle that each functional UI element has its own manager.
|
|
*
|
|
* RESPONSIBILITIES:
|
|
* - Handles button clicks on swp-nav-button elements
|
|
* - Validates navigation actions (prev, next, today)
|
|
* - Emits NAV_BUTTON_CLICKED events
|
|
* - Manages button UI listeners
|
|
*
|
|
* EVENT FLOW:
|
|
* ===========
|
|
* User clicks button → validateAction() → emit event → NavigationManager handles navigation
|
|
*
|
|
* SUBSCRIBERS:
|
|
* ============
|
|
* - NavigationManager: Performs actual navigation logic (animations, grid updates, week calculations)
|
|
*/
|
|
export class NavigationButtonsManager {
|
|
constructor(eventBus) {
|
|
this.buttonListeners = new Map();
|
|
this.eventBus = eventBus;
|
|
this.setupButtonListeners();
|
|
}
|
|
/**
|
|
* Setup click listeners on all navigation buttons
|
|
*/
|
|
setupButtonListeners() {
|
|
const buttons = document.querySelectorAll('swp-nav-button[data-action]');
|
|
buttons.forEach(button => {
|
|
const clickHandler = (event) => {
|
|
event.preventDefault();
|
|
const action = button.getAttribute('data-action');
|
|
if (action && this.isValidAction(action)) {
|
|
this.handleNavigation(action);
|
|
}
|
|
};
|
|
button.addEventListener('click', clickHandler);
|
|
this.buttonListeners.set(button, clickHandler);
|
|
});
|
|
}
|
|
/**
|
|
* Handle navigation action
|
|
*/
|
|
handleNavigation(action) {
|
|
// Emit navigation button clicked event
|
|
this.eventBus.emit(CoreEvents.NAV_BUTTON_CLICKED, {
|
|
action: action
|
|
});
|
|
}
|
|
/**
|
|
* Validate if string is a valid navigation action
|
|
*/
|
|
isValidAction(action) {
|
|
return ['prev', 'next', 'today'].includes(action);
|
|
}
|
|
}
|
|
//# sourceMappingURL=NavigationButtonsManager.js.map
|