138 lines
4.2 KiB
JavaScript
Executable File
138 lines
4.2 KiB
JavaScript
Executable File
/**
|
|
* Calendar JavaScript - FullCalendar Configuration
|
|
* Nómina Pegaso
|
|
*/
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Calendar initialization is now handled in the blade template
|
|
// This file provides additional utility functions
|
|
|
|
/**
|
|
* Format currency values
|
|
*/
|
|
window.formatCurrency = function(amount) {
|
|
return '$' + parseFloat(amount).toLocaleString('es-ES', {
|
|
minimumFractionDigits: 2,
|
|
maximumFractionDigits: 2
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Format date for display
|
|
*/
|
|
window.formatDate = function(dateStr, format = 'long') {
|
|
const date = new Date(dateStr + 'T00:00:00');
|
|
|
|
if (format === 'short') {
|
|
return date.toLocaleDateString('es-ES', {
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: 'numeric'
|
|
});
|
|
}
|
|
|
|
return date.toLocaleDateString('es-ES', {
|
|
weekday: 'long',
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric'
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Show notification toast
|
|
*/
|
|
window.showToast = function(message, type = 'info') {
|
|
const toast = document.createElement('div');
|
|
toast.className = `toast show align-items-center text-white bg-${type} border-0`;
|
|
toast.setAttribute('role', 'alert');
|
|
toast.setAttribute('aria-live', 'assertive');
|
|
toast.setAttribute('aria-atomic', 'true');
|
|
|
|
toast.innerHTML = `
|
|
<div class="d-flex">
|
|
<div class="toast-body">${message}</div>
|
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
|
|
</div>
|
|
`;
|
|
|
|
const container = document.querySelector('.toast-container') || createToastContainer();
|
|
container.appendChild(toast);
|
|
|
|
setTimeout(() => {
|
|
toast.remove();
|
|
}, 5000);
|
|
};
|
|
|
|
function createToastContainer() {
|
|
const container = document.createElement('div');
|
|
container.className = 'toast-container';
|
|
document.body.appendChild(container);
|
|
return container;
|
|
}
|
|
|
|
/**
|
|
* Confirm action with modal
|
|
*/
|
|
window.confirmAction = function(message, onConfirm) {
|
|
if (confirm(message)) {
|
|
onConfirm();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Validate date is within current month
|
|
*/
|
|
window.validateDateInMonth = function(dateInput, monthId) {
|
|
// This can be extended to validate against specific month
|
|
const selectedDate = new Date(dateInput.value);
|
|
const now = new Date();
|
|
|
|
return selectedDate <= now;
|
|
};
|
|
|
|
/**
|
|
* Calculate difference between two values
|
|
*/
|
|
window.calculateDifference = function(value1, value2) {
|
|
const diff = parseFloat(value1) - parseFloat(value2);
|
|
const sign = diff >= 0 ? '+' : '';
|
|
return sign + formatCurrency(diff);
|
|
};
|
|
|
|
/**
|
|
* Update summary cards dynamically
|
|
*/
|
|
window.updateSummaryCard = function(cardId, value) {
|
|
const card = document.getElementById(cardId);
|
|
if (card) {
|
|
card.textContent = formatCurrency(value);
|
|
}
|
|
};
|
|
});
|
|
|
|
/**
|
|
* Mobile sidebar toggle
|
|
*/
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const mobileNavBtn = document.getElementById('mobileNavBtn');
|
|
const mobileNavBtn2 = document.getElementById('mobileNavBtn2');
|
|
const sidebar = document.getElementById('sidebar');
|
|
const sidebarOverlay = document.getElementById('sidebarOverlay');
|
|
|
|
function toggleSidebar() {
|
|
sidebar.classList.toggle('show');
|
|
sidebarOverlay.classList.toggle('show');
|
|
}
|
|
|
|
if (mobileNavBtn) mobileNavBtn.addEventListener('click', toggleSidebar);
|
|
if (mobileNavBtn2) mobileNavBtn2.addEventListener('click', toggleSidebar);
|
|
if (sidebarOverlay) sidebarOverlay.addEventListener('click', toggleSidebar);
|
|
|
|
// Close sidebar on escape key
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Escape' && sidebar.classList.contains('show')) {
|
|
toggleSidebar();
|
|
}
|
|
});
|
|
}); |