';
}
// Add pagination
if (pagination.total_pages > 1) {
html += renderPagination(pagination);
}
html += '
';
$('#hvac-events-table-container').html(html);
}
/**
* Render pagination
*/
function renderPagination(pagination) {
var html = '
';
// Previous button
if (pagination.has_prev) {
html += '';
}
// Page numbers (show 5 pages around current)
var startPage = Math.max(1, pagination.current_page - 2);
var endPage = Math.min(pagination.total_pages, pagination.current_page + 2);
if (startPage > 1) {
html += '';
if (startPage > 2) {
html += '...';
}
}
for (var i = startPage; i <= endPage; i++) {
var activeClass = i === pagination.current_page ? ' hvac-btn-primary' : ' hvac-btn-secondary';
html += '';
}
if (endPage < pagination.total_pages) {
if (endPage < pagination.total_pages - 1) {
html += '...';
}
html += '';
}
// Next button
if (pagination.has_next) {
html += '';
}
html += '
';
return html;
}
/**
* Render simple calendar view
*/
function renderCalendar(events) {
var html = '
';
if (events.length === 0) {
html += '
';
html += '
No events found for the selected date range.
';
html += '
';
} else {
// Group events by date
var eventsByDate = {};
events.forEach(function(event) {
var date = event.start;
if (!eventsByDate[date]) {
eventsByDate[date] = [];
}
eventsByDate[date].push(event);
});
// Sort dates
var sortedDates = Object.keys(eventsByDate).sort();
sortedDates.forEach(function(date) {
var dateObj = new Date(date);
var dateStr = dateObj.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
html += '
';
html += '
' + dateStr + '
';
html += '
';
eventsByDate[date].forEach(function(event) {
html += '
';
html += 'Capacity: ' + event.extendedProps.capacity + ' | ';
html += 'Sold: ' + event.extendedProps.sold + ' | ';
html += 'Revenue: $' + formatMoney(event.extendedProps.revenue);
html += '
';
html += '
';
});
html += '
';
});
}
html += '
';
$('#hvac-calendar-content').html(html);
}
/**
* Update events count display
*/
function updateEventsCount(count) {
var text = count + ' event' + (count !== 1 ? 's' : '') + ' found';
$('#events-count-display').text(text);
}
/**
* Show error message
*/
function showError(message) {
// Create a simple alert for now - could be enhanced with a modal
if (window.console) {
console.error('HVAC Events Overview:', message);
}
// Add error message to page
var errorHtml = '
';
errorHtml += '
Error: ' + message + '
';
errorHtml += '
';
// Show at top of events content
$('.hvac-events-content').prepend(errorHtml);
// Auto-remove after 5 seconds
setTimeout(function() {
$('.hvac-notice-error').fadeOut(function() {
$(this).remove();
});
}, 5000);
}
/**
* Format money for display
*/
function formatMoney(amount) {
return parseFloat(amount).toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
}
/**
* Debounce function to limit function calls
*/
function debounce(func, wait) {
var timeout;
return function executedFunction() {
var context = this;
var args = arguments;
var later = function() {
timeout = null;
func.apply(context, args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
})(jQuery);