Adding new functionality

This commit is contained in:
2025-08-31 06:20:15 -07:00
parent c8c02da433
commit 5b6011bdb8
9 changed files with 1821 additions and 82 deletions

View File

@@ -455,6 +455,16 @@
transform: translateY(-1px);
}
.twp-btn-warning {
background: #ffc107;
color: #212529;
}
.twp-btn-warning:hover {
background: #e0a800;
transform: translateY(-1px);
}
.twp-btn-success {
background: #007cba;
color: white;

View File

@@ -277,6 +277,10 @@
hangupCall();
});
$('#twp-resume-btn').on('click', function() {
toggleHold(); // Resume the call
});
// Call control buttons
$('#twp-hold-btn').on('click', function() {
toggleHold();
@@ -531,6 +535,10 @@
$('#twp-hold-btn').text('Hold').removeClass('btn-active');
$('#twp-record-btn').text('Record').removeClass('btn-active');
// Reset resume button
const $resumeBtn = $('#twp-resume-btn');
$resumeBtn.hide();
// Restart alerts if enabled and there are waiting calls
if (alertEnabled) {
const hasWaitingCalls = userQueues.some(q => parseInt(q.current_waiting) > 0);
@@ -731,23 +739,27 @@
function updateCallState(state) {
const $callBtn = $('#twp-call-btn');
const $hangupBtn = $('#twp-hangup-btn');
const $resumeBtn = $('#twp-resume-btn');
const $controlsPanel = $('#twp-call-controls-panel');
switch (state) {
case 'idle':
$callBtn.show().prop('disabled', false);
$hangupBtn.hide();
$resumeBtn.hide();
$controlsPanel.hide();
break;
case 'connecting':
case 'ringing':
$callBtn.hide();
$hangupBtn.show();
$resumeBtn.hide();
$controlsPanel.hide();
break;
case 'connected':
$callBtn.hide();
$hangupBtn.show();
$resumeBtn.hide(); // Will be shown by hold logic when needed
$controlsPanel.show();
break;
}
@@ -1596,19 +1608,33 @@
isOnHold = !currentHoldState;
console.log('Hold state updated to:', isOnHold);
// Update hold button and show/hide dedicated resume button
const $resumeBtn = $('#twp-resume-btn');
if (isOnHold) {
console.log('Setting button to Resume state...');
$holdBtn.text('Resume').addClass('btn-active').prop('disabled', false);
// Show dedicated resume button
$resumeBtn.show();
console.log('Resume button shown - visible:', $resumeBtn.is(':visible'));
console.log('Button after update - text:', $holdBtn.text(), 'classes:', $holdBtn.attr('class'));
showMessage('Call placed on hold - Click Resume to continue', 'info');
showMessage('Call placed on hold - Click Resume Call button to continue', 'info');
// Verify the button was actually updated
setTimeout(function() {
console.log('Button state after 100ms:', $holdBtn.text(), $holdBtn.hasClass('btn-active'));
console.log('Resume button visible after 100ms:', $resumeBtn.is(':visible'));
}, 100);
} else {
console.log('Setting button to Hold state...');
$holdBtn.text('Hold').removeClass('btn-active').prop('disabled', false);
// Hide dedicated resume button
$resumeBtn.hide();
console.log('Resume button hidden');
console.log('Button after update - text:', $holdBtn.text(), 'classes:', $holdBtn.attr('class'));
showMessage('Call resumed', 'info');
}
@@ -1676,10 +1702,8 @@
if (response.success) {
showMessage('Call transferred successfully', 'success');
hideTransferDialog();
// End the call on our end
if (currentCall) {
currentCall.disconnect();
}
// Don't disconnect - let the transfer complete naturally
// The call will be disconnected by Twilio after successful transfer
} else {
showMessage('Failed to transfer call: ' + (response.data || 'Unknown error'), 'error');
}
@@ -1855,28 +1879,33 @@
/**
* Show agent selection transfer dialog
*/
function showAgentTransferDialog() {
// Load available agents for transfer
$.ajax({
url: twp_frontend_ajax.ajax_url,
method: 'POST',
data: {
action: 'twp_get_transfer_agents',
nonce: twp_frontend_ajax.nonce
},
success: function(response) {
if (response.success) {
buildAgentTransferDialog(response.data);
} else {
showMessage('Failed to load agents: ' + (response.data || 'Unknown error'), 'error');
function showAgentTransferDialog(agents = null) {
if (agents) {
// Use passed agents data directly
buildAgentTransferDialog(agents);
} else {
// Load available agents for transfer
$.ajax({
url: twp_frontend_ajax.ajax_url,
method: 'POST',
data: {
action: 'twp_get_transfer_agents',
nonce: twp_frontend_ajax.nonce
},
success: function(response) {
if (response.success) {
buildAgentTransferDialog(response.data);
} else {
showMessage('Failed to load agents: ' + (response.data || 'Unknown error'), 'error');
showManualTransferDialog(); // Fallback to manual entry
}
},
error: function() {
showMessage('Failed to load agents', 'error');
showManualTransferDialog(); // Fallback to manual entry
}
},
error: function() {
showMessage('Failed to load agents', 'error');
showManualTransferDialog(); // Fallback to manual entry
}
});
});
}
}
/**
@@ -2034,7 +2063,7 @@
url: twp_frontend_ajax.ajax_url,
method: 'POST',
data: {
action: 'twp_get_all_queues',
action: 'twp_get_requeue_queues',
nonce: twp_frontend_ajax.nonce
},
success: function(response) {