/**
* ChaosBoost Dashboard JavaScript
* Handles all dashboard interactions
*/
(function($) {
'use strict';
// Check if dashboard config exists
if (typeof chaosboostDashboard === 'undefined') {
console.warn('ChaosBoost Dashboard: Configuration not loaded');
return;
}
const config = chaosboostDashboard;
let currentOrderId = null;
let currentUserId = null;
$(document).ready(function() {
console.log('🎮 ChaosBoost Dashboard Initializing...');
initNavigation();
initOrdersPagination();
initMessaging();
initProfileForms();
initInviteSection();
if (config.isBooster) {
initBoosterServices();
initStatisticsChart();
}
console.log('✅ Dashboard Ready');
});
/**
* Navigation highlighting
*/
function initNavigation() {
$('.dashboard-nav .nav-item').on('click', function(e) {
// Allow natural navigation, just add loading state
$(this).addClass('loading');
});
}
/**
* Orders pagination
*/
function initOrdersPagination() {
let currentPage = 1;
const $container = $('.orders-table-container');
$container.on('click', '.pagination-btn.next', function() {
if ($(this).prop('disabled')) return;
loadOrders(++currentPage);
});
$container.on('click', '.pagination-btn.prev', function() {
if ($(this).prop('disabled') || currentPage <= 1) return;
loadOrders(--currentPage);
});
function loadOrders(page) {
$container.addClass('loading');
$.ajax({
url: config.ajaxurl,
type: 'POST',
data: {
action: 'chaosboost_get_user_orders',
nonce: config.nonce,
page: page,
limit: 10
},
success: function(response) {
$container.removeClass('loading');
if (response.success && response.data.orders) {
updateOrdersTable(response.data.orders);
updatePagination(page, response.data.orders.length);
}
},
error: function() {
$container.removeClass('loading');
showNotification(config.strings.error, 'error');
}
});
}
function updateOrdersTable(orders) {
const $tbody = $container.find('tbody');
$tbody.empty();
if (orders.length === 0) {
$tbody.append('
| No hay más pedidos |
');
return;
}
orders.forEach(function(order) {
$tbody.append(`
| ${order.id} |
${escapeHtml(order.products)} |
${order.total} |
${order.date} |
`);
});
}
function updatePagination(page, count) {
$container.find('.current-page').text(page);
$container.find('.pagination-btn.prev').prop('disabled', page <= 1);
$container.find('.pagination-btn.next').prop('disabled', count < 10);
}
}
/**
* Messaging system
*/
function initMessaging() {
const $messageSection = $('.messages-section');
if ($messageSection.length === 0) return;
// Conversation selection
$messageSection.on('click', '.conversation-item', function() {
const $item = $(this);
const orderId = $item.data('order-id');
const userId = $item.data('user-id');
const name = $item.find('.conv-name').text();
$('.conversation-item').removeClass('active');
$item.addClass('active').removeClass('unread');
currentOrderId = orderId;
currentUserId = userId;
loadMessages(orderId, userId, name);
});
// Send message
$messageSection.on('click', '.send-btn', sendMessage);
$messageSection.on('keypress', '.chat-input', function(e) {
if (e.which === 13 && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
function loadMessages(orderId, userId, name) {
const $chatMessages = $('#chat-messages');
const $chatHeader = $('.chat-header');
const $chatInput = $('.chat-input');
const $sendBtn = $('.send-btn');
$chatMessages.html('');
$chatHeader.find('.chat-title').text(name);
$chatInput.prop('disabled', false);
$sendBtn.prop('disabled', false);
$.ajax({
url: config.ajaxurl,
type: 'POST',
data: {
action: 'chaosboost_get_messages',
nonce: config.nonce,
order_id: orderId,
user_id: userId
},
success: function(response) {
if (response.success) {
renderMessages(response.data.messages);
if (response.data.messages.length > 0) {
const lastMsg = response.data.messages[response.data.messages.length - 1];
$chatHeader.find('.chat-date').text(lastMsg.date);
}
}
},
error: function() {
$chatMessages.html('');
}
});
}
function renderMessages(messages) {
const $chatMessages = $('#chat-messages');
$chatMessages.empty();
if (messages.length === 0) {
$chatMessages.html('No hay mensajes aún. ¡Inicia la conversación!
');
return;
}
messages.forEach(function(msg) {
const msgClass = msg.is_mine ? 'sent' : 'received';
$chatMessages.append(`
${escapeHtml(msg.message)}
`);
});
// Scroll to bottom
$chatMessages.scrollTop($chatMessages[0].scrollHeight);
}
function sendMessage() {
const $input = $('.chat-input');
const message = $input.val().trim();
if (!message || !currentOrderId) return;
const $sendBtn = $('.send-btn');
$sendBtn.prop('disabled', true);
$.ajax({
url: config.ajaxurl,
type: 'POST',
data: {
action: 'chaosboost_send_message',
nonce: config.nonce,
order_id: currentOrderId,
receiver_id: currentUserId,
message: message
},
success: function(response) {
$sendBtn.prop('disabled', false);
if (response.success) {
$input.val('');
// Add message to chat
$('#chat-messages').append(`
${escapeHtml(message)}
`);
// Scroll to bottom
const $chatMessages = $('#chat-messages');
$chatMessages.scrollTop($chatMessages[0].scrollHeight);
} else {
showNotification(response.data.message || 'Error al enviar', 'error');
}
},
error: function() {
$sendBtn.prop('disabled', false);
showNotification('Error de conexión', 'error');
}
});
}
}
/**
* Profile forms
*/
function initProfileForms() {
// Profile info form
$('#profile-info-form').on('submit', function(e) {
e.preventDefault();
const $form = $(this);
const $btn = $form.find('.btn-save');
const originalText = $btn.text();
$btn.prop('disabled', true).text('Guardando...');
$.ajax({
url: config.ajaxurl,
type: 'POST',
data: {
action: 'chaosboost_update_profile',
nonce: config.nonce,
display_name: $form.find('[name="display_name"]').val(),
email: $form.find('[name="email"]').val(),
discord_tag: $form.find('[name="discord_tag"]').val(),
phone: $form.find('[name="phone"]').val(),
country: $form.find('[name="country"]').val()
},
success: function(response) {
$btn.prop('disabled', false).text(originalText);
if (response.success) {
showNotification(response.data.message, 'success');
} else {
showNotification(response.data.message || 'Error al guardar', 'error');
}
},
error: function() {
$btn.prop('disabled', false).text(originalText);
showNotification('Error de conexión', 'error');
}
});
});
// Password form
$('#password-form').on('submit', function(e) {
e.preventDefault();
const $form = $(this);
const $btn = $form.find('.btn-save');
const originalText = $btn.text();
const newPassword = $form.find('[name="new_password"]').val();
const confirmPassword = $form.find('[name="confirm_password"]').val();
if (newPassword !== confirmPassword) {
showNotification('Las contraseñas no coinciden', 'error');
return;
}
$btn.prop('disabled', true).text('Guardando...');
$.ajax({
url: config.ajaxurl,
type: 'POST',
data: {
action: 'chaosboost_update_password',
nonce: config.nonce,
new_password: newPassword,
confirm_password: confirmPassword
},
success: function(response) {
$btn.prop('disabled', false).text(originalText);
if (response.success) {
showNotification(response.data.message, 'success');
$form.find('input').val('');
// Redirect to login after password change
setTimeout(function() {
window.location.href = '/wp-login.php';
}, 2000);
} else {
showNotification(response.data.message || 'Error al guardar', 'error');
}
},
error: function() {
$btn.prop('disabled', false).text(originalText);
showNotification('Error de conexión', 'error');
}
});
});
}
/**
* Invite section
*/
function initInviteSection() {
// Copy link button
$('.btn-copy-link').on('click', function() {
const url = $(this).data('url');
const $input = $('.invite-link-input');
// Copy to clipboard
$input.select();
document.execCommand('copy');
// Visual feedback
const $btn = $(this);
const originalText = $btn.text();
$btn.text('¡COPIADO!');
setTimeout(function() {
$btn.text(originalText);
}, 2000);
showNotification('Link copiado al portapapeles', 'success');
});
}
/**
* Booster services (only for boosters)
*/
function initBoosterServices() {
const $container = $('.services-table-container');
if ($container.length === 0) return;
// Service actions
$container.on('click', '.action-link', function(e) {
e.preventDefault();
const $link = $(this);
const $row = $link.closest('tr');
const serviceId = $row.data('service-id');
const action = $link.data('action');
if (action === 'delete') {
if (!confirm(config.strings.confirmDelete)) return;
} else if (action === 'pause') {
if (!confirm(config.strings.confirmPause)) return;
}
updateServiceStatus(serviceId, action, $row);
});
function updateServiceStatus(serviceId, action, $row) {
$row.addClass('updating');
$.ajax({
url: config.ajaxurl,
type: 'POST',
data: {
action: 'chaosboost_update_service_status',
nonce: config.nonce,
service_id: serviceId,
service_action: action
},
success: function(response) {
$row.removeClass('updating');
if (response.success) {
if (action === 'delete') {
$row.fadeOut(300, function() {
$(this).remove();
});
} else {
showNotification(response.data.message, 'success');
}
} else {
showNotification(response.data.message || 'Error', 'error');
}
},
error: function() {
$row.removeClass('updating');
showNotification('Error de conexión', 'error');
}
});
}
}
/**
* Statistics chart (only for boosters)
*/
function initStatisticsChart() {
const $canvas = $('#earningsChartCanvas');
if ($canvas.length === 0) return;
// Check if Chart.js is available
if (typeof Chart === 'undefined') {
// Load Chart.js dynamically
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/chart.js';
script.onload = createChart;
document.head.appendChild(script);
} else {
createChart();
}
function createChart() {
const ctx = $canvas[0].getContext('2d');
const chartData = window.chaosboostChartData || {
labels: ['0', '20', '30', '40', '50', '100', '200', '300', '400'],
data: [200, 150, 100, 120, 180, 250, 280, 300, 280]
};
new Chart(ctx, {
type: 'line',
data: {
labels: chartData.labels,
datasets: [{
label: 'Ganancias',
data: chartData.data,
borderColor: '#FFC908',
backgroundColor: 'rgba(255, 201, 8, 0.1)',
borderWidth: 2,
fill: true,
tension: 0.4,
pointRadius: 0,
pointHoverRadius: 6,
pointBackgroundColor: '#FFC908'
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
}
},
scales: {
x: {
grid: {
color: 'rgba(255, 201, 8, 0.1)'
},
ticks: {
color: '#FFC908'
}
},
y: {
grid: {
color: 'rgba(255, 201, 8, 0.1)'
},
ticks: {
color: '#FFC908'
},
beginAtZero: true,
max: 300
}
}
}
});
}
}
/**
* Utility: Show notification
*/
function showNotification(message, type) {
type = type || 'info';
$('.chaosboost-dashboard-notification').remove();
const typeColors = {
'success': '#4CAF50',
'error': '#f44336',
'info': '#2196F3'
};
const bgColor = typeColors[type] || '#2196F3';
const $notif = $(`${escapeHtml(message)}
`);
$notif.css({
'position': 'fixed',
'top': '20px',
'right': '20px',
'background': bgColor,
'color': 'white',
'padding': '15px 25px',
'border-radius': '8px',
'box-shadow': '0 4px 15px rgba(0,0,0,0.3)',
'z-index': '999999',
'opacity': '0',
'transition': 'opacity 0.3s',
'font-family': 'Rajdhani, sans-serif',
'font-weight': '600',
'font-size': '16px',
'max-width': '350px'
});
$('body').append($notif);
setTimeout(() => $notif.css('opacity', '1'), 100);
setTimeout(() => {
$notif.css('opacity', '0');
setTimeout(() => $notif.remove(), 300);
}, 3000);
}
/**
* Utility: Escape HTML
*/
function escapeHtml(text) {
if (typeof text !== 'string') return text;
const map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return text.replace(/[&<>"']/g, m => map[m]);
}
})(jQuery);
Warning: Cannot modify header information - headers already sent by (output started at /home/u926939092/domains/dragonboosting.com/public_html/wp-content/plugins/boster/index.php:1) in /home/u926939092/domains/dragonboosting.com/public_html/wp-includes/pluggable.php on line 1450
Warning: Cannot modify header information - headers already sent by (output started at /home/u926939092/domains/dragonboosting.com/public_html/wp-content/plugins/boster/index.php:1) in /home/u926939092/domains/dragonboosting.com/public_html/wp-includes/pluggable.php on line 1453