function togglePromoFields(purpose) { var discountFields = document.getElementById('discount-fields'); var trialFields = document.getElementById('trial-fields'); var codeInput = document.getElementById('pc-code'); if (purpose === 'discount') { discountFields.classList.remove('is-hidden'); trialFields.classList.remove('is-visible'); codeInput.required = true; codeInput.placeholder = 'e.g. LAUNCH50'; } else if (purpose === 'free_trial') { discountFields.classList.add('is-hidden'); trialFields.classList.add('is-visible'); codeInput.required = true; codeInput.placeholder = 'e.g. TRIAL14'; } else { discountFields.classList.add('is-hidden'); trialFields.classList.remove('is-visible'); codeInput.required = false; codeInput.placeholder = 'Auto-generated'; } } /// Show a modal listing redemptions of a single promo code. Fetched on /// demand so the page-render path doesn't pay for it. Guest checkouts /// surface as the guest's email; missing item titles render as "—". function showPromoRedemptions(codeId, codeLabel) { var existing = document.getElementById('promo-redemptions-modal'); if (existing) existing.remove(); var overlay = document.createElement('div'); overlay.id = 'promo-redemptions-modal'; overlay.className = 'modal-overlay'; overlay.style.display = 'flex'; overlay.onclick = function (e) { if (e.target === overlay) overlay.remove(); }; var content = document.createElement('div'); content.className = 'modal-content'; content.style.maxWidth = '640px'; content.style.padding = '2rem'; content.innerHTML = '
' + escapeHtml(codeLabel) + '| When | Who | Item | Paid |
|---|---|---|---|
| ' + when + ' | ' + who + ' | ' + item + ' | ' + paid + ' |
Showing the 500 most recent redemptions.
'; } body.innerHTML = html; }) .catch(function () { var body = document.getElementById('promo-redemptions-body'); if (body) body.textContent = 'Could not load redemptions.'; }); } /// Switch between preset trial lengths and a custom number input. The /// hidden #pc-trial-days carries the actual submitted value so we can keep /// the server-side contract (a single `trial_days` field) untouched. function onTrialPresetChange() { var preset = document.getElementById('pc-trial-preset'); var hidden = document.getElementById('pc-trial-days'); var custom = document.getElementById('pc-trial-days-custom'); if (preset.value === 'custom') { custom.hidden = false; custom.required = true; custom.focus(); hidden.value = custom.value || ''; } else { custom.hidden = true; custom.required = false; hidden.value = preset.value; } }