/** * WooCow – My Account frontend JavaScript */ (function ($) { 'use strict'; if (!$('#woocow-account').length) return; const ajax = (action, data) => $.post(woocowAcct.ajax_url, { action, nonce: woocowAcct.nonce, ...data }); const notice = (msg, type = 'success') => { const $n = $('#woocow-acct-notices'); $n.html(`
`); setTimeout(() => $n.find('> div').fadeOut(400, function () { $(this).remove(); }), 5000); }; function esc(str) { return String(str).replace(/[&<>"']/g, m => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[m]); } function formatMB(bytes) { if (!bytes) return '0 MB'; const mb = bytes / 1024 / 1024; return mb >= 1024 ? (mb / 1024).toFixed(1) + ' GB' : mb.toFixed(0) + ' MB'; } // ── Load Mailboxes ──────────────────────────────────────────────────────── $(document).on('click', '.woocow-load-mailboxes', function () { const $panel = $(this).closest('.woocow-domain-panel'); const sid = $panel.data('server-id'); const domain = $panel.data('domain'); const $wrap = $panel.find('.woocow-mailboxes-wrap'); const $list = $panel.find('.woocow-mailboxes-list'); $(this).prop('disabled', true).text('Loading…'); $wrap.show(); $list.html('Fetching mailboxes…
'); ajax('woocow_acct_mailboxes', { server_id: sid, domain }).done(res => { $(this).prop('disabled', false).text('Refresh'); if (!res.success) { $list.html(`${esc(res.data)}
`); return; } const boxes = res.data.mailboxes || []; const webmail = res.data.webmail_url; if (!boxes.length) { $list.html('No mailboxes yet. Create one below.
'); return; } let html = ''; boxes.forEach(m => { const pct = parseFloat(m.percent_in_use || 0); const used = formatMB(m.quota_used); const max = formatMB(m.quota); const col = pct > 85 ? '#e74c3c' : pct > 60 ? '#f39c12' : '#27ae60'; html += `Loading aliases…
'); $wrap.slideDown(); ajax('woocow_acct_aliases', { server_id: sid, domain }).done(res => { if (!res.success) { $list.html(`${esc(res.data)}
`); return; } const aliases = res.data; if (!aliases.length) { $list.html('No aliases for this domain yet.
'); return; } let html = '