mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
fix: move loadCustomerEmails to module scope, wire into switchCTab, add emails to tab loop; drop redundant ?: [] in customer-emails.php
This commit is contained in:
@@ -24,4 +24,4 @@ $emails = db()->fetchAll(
|
||||
['cid' => $customerId]
|
||||
);
|
||||
|
||||
echo json_encode(['emails' => $emails ?: []]);
|
||||
echo json_encode(['emails' => $emails]);
|
||||
|
||||
+21
-20
@@ -517,29 +517,11 @@ function toggleCOrd(id){
|
||||
var _cCustId = null;
|
||||
var _cLoaded = false;
|
||||
|
||||
function switchCTab(tab) {
|
||||
['details','orders'].forEach(function(t) {
|
||||
var tabBtn = document.getElementById('ctab-' + t);
|
||||
var panel = document.getElementById('cpanel-' + t);
|
||||
if (tabBtn) {
|
||||
tabBtn.style.borderBottomColor = t === tab ? 'var(--color-primary)' : 'transparent';
|
||||
tabBtn.style.color = t === tab ? 'var(--color-primary)' : 'var(--color-text-muted)';
|
||||
}
|
||||
if (panel) panel.style.display = t === tab ? '' : 'none';
|
||||
});
|
||||
if (tab === 'orders' && _cCustId && !_cLoaded) loadCOrders(_cCustId);
|
||||
}
|
||||
|
||||
|
||||
function openCustomerModal(customer = null) {
|
||||
const isEdit = !!customer;
|
||||
_cCustId = isEdit ? customer.customer_id : null;
|
||||
_cLoaded = false;
|
||||
// Email history loader
|
||||
function loadCustomerEmails(customerId) {
|
||||
if (!customerId) return;
|
||||
document.getElementById('cEmailLoading').style.display = 'block';
|
||||
document.getElementById('cEmailContent').style.display = 'none';
|
||||
var colors = {"sent":"#3B82F6","delivered":"#10B981","bounced":"#EF4444","failed":"#EF4444","unknown":"#9CA3AF"};
|
||||
fetch('/admin/api/customer-emails.php?customer_id=' + encodeURIComponent(customerId))
|
||||
.then(r => r.json()).then(function(data) {
|
||||
document.getElementById('cEmailLoading').style.display = 'none';
|
||||
@@ -554,7 +536,6 @@ function openCustomerModal(customer = null) {
|
||||
}
|
||||
document.getElementById('cEmailEmpty').style.display = 'none';
|
||||
document.getElementById('cEmailTable').style.display = 'table';
|
||||
var colors={"sent":"#3B82F6","delivered":"#10B981","bounced":"#EF4444","failed":"#EF4444","unknown":"#9CA3AF"};
|
||||
var html = '';
|
||||
emails.forEach(function(e) {
|
||||
var color = colors[e.status] || '#9CA3AF';
|
||||
@@ -573,6 +554,26 @@ function openCustomerModal(customer = null) {
|
||||
});
|
||||
}
|
||||
|
||||
function switchCTab(tab) {
|
||||
['details','orders','emails'].forEach(function(t) {
|
||||
var tabBtn = document.getElementById('ctab-' + t);
|
||||
var panel = document.getElementById('cpanel-' + t);
|
||||
if (tabBtn) {
|
||||
tabBtn.style.borderBottomColor = t === tab ? 'var(--color-primary)' : 'transparent';
|
||||
tabBtn.style.color = t === tab ? 'var(--color-primary)' : 'var(--color-text-muted)';
|
||||
}
|
||||
if (panel) panel.style.display = t === tab ? '' : 'none';
|
||||
});
|
||||
if (tab === 'orders' && _cCustId && !_cLoaded) loadCOrders(_cCustId);
|
||||
if (tab === 'emails' && _cCustId) loadCustomerEmails(_cCustId);
|
||||
}
|
||||
|
||||
|
||||
function openCustomerModal(customer = null) {
|
||||
const isEdit = !!customer;
|
||||
_cCustId = isEdit ? customer.customer_id : null;
|
||||
_cLoaded = false;
|
||||
|
||||
document.getElementById('customerModalTitle').textContent = isEdit ? 'Edit Customer' : 'Add Customer';
|
||||
document.getElementById('customerSubmitBtn').textContent = isEdit ? 'Update Customer' : 'Add Customer';
|
||||
document.getElementById('customerAction').value = isEdit ? 'update' : 'create';
|
||||
|
||||
Reference in New Issue
Block a user