diff --git a/assets/js/woocow-admin.js b/assets/js/woocow-admin.js index 7d22132..b428246 100644 --- a/assets/js/woocow-admin.js +++ b/assets/js/woocow-admin.js @@ -312,10 +312,11 @@ EmailNameQuota UsedQuota MaxActiveActions `; boxes.forEach(m => { - const pct = m.percent_in_use || 0; - const used = formatMB(m.quota_used); - const max = formatMB(m.quota); - const bar = `
`; + const pct = m.percent_in_use || 0; + const used = formatMB(m.quota_used); + const max = formatMB(m.quota); + const bar = `
`; + const quotaMB = Math.round((m.quota || 0) / 1024 / 1024); html += ` ${esc(m.username)} ${esc(m.name)} @@ -323,7 +324,12 @@ ${max} ${m.active == 1 ? '✓' : '–'} - + + + `; }); @@ -379,6 +385,69 @@ else notice($('#wc-mb-notices'), 'error', res.data); }); }); + + // ── Edit modal: Reset PW ────────────────────────────────────────────── + + let editEmail = ''; + let editType = ''; + + const openEditModal = (email, type, currentQuota) => { + editEmail = email; + editType = type; + $('#wc-mb-edit-subtitle').text(email); + $('#wc-mb-edit-notice').text(''); + $('#wc-mb-edit-pw-section, #wc-mb-edit-quota-section').hide(); + + if (type === 'password') { + $('#wc-mb-edit-title').text('Reset Password'); + $('#wc-mb-edit-pass, #wc-mb-edit-pass2').val(''); + $('#wc-mb-edit-pw-section').show(); + setTimeout(() => $('#wc-mb-edit-pass').trigger('focus'), 100); + } else { + $('#wc-mb-edit-title').text('Set Quota'); + $('#wc-mb-edit-quota').val(currentQuota || 1024); + $('#wc-mb-edit-quota-section').show(); + setTimeout(() => $('#wc-mb-edit-quota').trigger('focus'), 100); + } + $('#wc-mb-edit-modal').show(); + }; + + $(document).on('click', '.wc-mb-reset-pw', function () { + openEditModal($(this).data('email'), 'password', null); + }); + + $(document).on('click', '.wc-mb-set-quota', function () { + openEditModal($(this).data('email'), 'quota', $(this).data('quota')); + }); + + $('#wc-mb-edit-cancel').on('click', () => $('#wc-mb-edit-modal').hide()); + $(document).on('keydown', e => { if (e.key === 'Escape') $('#wc-mb-edit-modal').hide(); }); + + $('#wc-mb-edit-save').on('click', () => { + const $note = $('#wc-mb-edit-notice').text('Saving…'); + const data = { server_id: currentServerId, email: editEmail, type: editType }; + + if (editType === 'password') { + data.password = $('#wc-mb-edit-pass').val(); + data.password2 = $('#wc-mb-edit-pass2').val(); + if (!data.password) { $note.html('Password cannot be empty.'); return; } + if (data.password !== data.password2) { $note.html('Passwords do not match.'); return; } + } else { + data.quota = $('#wc-mb-edit-quota').val(); + if (!data.quota || data.quota < 1) { $note.html('Enter a valid quota.'); return; } + } + + ajax('woocow_admin_mailbox_edit', data).done(res => { + if (res.success) { + $('#wc-mb-edit-modal').hide(); + const msg = editType === 'password' ? 'Password updated.' : 'Quota updated.'; + notice($('#wc-mb-notices'), 'success', `${esc(editEmail)} — ${msg}`); + if (editType === 'quota') loadMailboxes(); // refresh to show new quota + } else { + $note.html(`${esc(res.data)}`); + } + }); + }); } // ── Utilities ───────────────────────────────────────────────────────────── diff --git a/includes/class-woocow-admin.php b/includes/class-woocow-admin.php index d2dbbb2..9e58fe0 100644 --- a/includes/class-woocow-admin.php +++ b/includes/class-woocow-admin.php @@ -23,6 +23,7 @@ class WooCow_Admin { 'woocow_admin_mailboxes', 'woocow_admin_mailbox_create', 'woocow_admin_mailbox_delete', + 'woocow_admin_mailbox_edit', ]; foreach ( $ajax_actions as $action ) { @@ -218,6 +219,45 @@ class WooCow_Admin {
+ + +