Some checks failed
Deploy Application / deploy (push) Has been cancelled
99 lines
3.2 KiB
JavaScript
99 lines
3.2 KiB
JavaScript
/**
|
|
* Common Utilities Module
|
|
*
|
|
* Provides shared utilities and helpers used across the application
|
|
*/
|
|
|
|
import { ActionHandler } from './ActionHandler.js';
|
|
import { dockerContainerHandler, genericApiHandler, bulkOperationsHandler, defaultHandler } from './ActionHandlers.js';
|
|
|
|
// Export ActionHandler and handlers
|
|
export { ActionHandler };
|
|
export { dockerContainerHandler, genericApiHandler, bulkOperationsHandler, defaultHandler };
|
|
|
|
// Make ActionHandler globally available for easy access
|
|
if (typeof window !== 'undefined') {
|
|
window.ActionHandler = ActionHandler;
|
|
window.ActionHandlers = {
|
|
dockerContainer: dockerContainerHandler,
|
|
genericApi: genericApiHandler,
|
|
bulkOperations: bulkOperationsHandler,
|
|
default: defaultHandler
|
|
};
|
|
}
|
|
|
|
// Framework module definition
|
|
export const definition = {
|
|
name: 'common',
|
|
version: '1.0.0',
|
|
dependencies: [],
|
|
provides: ['ActionHandler'],
|
|
priority: 0
|
|
};
|
|
|
|
// Framework module initialization
|
|
export async function init(config = {}, state = {}) {
|
|
console.log('[Common] Module initialized');
|
|
|
|
// Auto-initialize ActionHandlers for elements with data-action-handler attribute
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const containers = document.querySelectorAll('[data-action-handler-container]');
|
|
containers.forEach(container => {
|
|
const selector = container.dataset.actionHandlerContainer || container.className.split(' ')[0];
|
|
const handlerName = container.dataset.actionHandler || 'default';
|
|
|
|
const handler = new ActionHandler(selector, {
|
|
csrfTokenSelector: '[data-live-component]',
|
|
autoRefresh: true
|
|
});
|
|
|
|
// Register handler if specified
|
|
if (handlerName && window.ActionHandlers[handlerName]) {
|
|
handler.registerHandler(handlerName, window.ActionHandlers[handlerName]);
|
|
}
|
|
|
|
// Store handler on element for debugging
|
|
container.actionHandler = handler;
|
|
});
|
|
});
|
|
|
|
return {
|
|
ActionHandler,
|
|
handlers: {
|
|
dockerContainer: dockerContainerHandler,
|
|
genericApi: genericApiHandler,
|
|
bulkOperations: bulkOperationsHandler,
|
|
default: defaultHandler
|
|
},
|
|
state
|
|
};
|
|
}
|
|
|
|
// Framework DOM element initialization
|
|
export function initElement(element, options = {}) {
|
|
// Check if element needs ActionHandler
|
|
if (element.hasAttribute('data-action-handler-container')) {
|
|
const selector = element.dataset.actionHandlerContainer || `.${element.className.split(' ')[0]}`;
|
|
const handlerName = element.dataset.actionHandler || 'default';
|
|
|
|
const handler = new ActionHandler(selector, {
|
|
csrfTokenSelector: '[data-live-component]',
|
|
autoRefresh: true,
|
|
...options
|
|
});
|
|
|
|
// Register handler if specified
|
|
if (handlerName && window.ActionHandlers?.[handlerName]) {
|
|
handler.registerHandler(handlerName, window.ActionHandlers[handlerName]);
|
|
}
|
|
|
|
// Store handler on element
|
|
element.actionHandler = handler;
|
|
|
|
return handler;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|