Fix add new game: reset form on section load, add prominent Add New Game button

- resetGameForm() now called every time Game Management section is opened,
  preventing stuck edit state (disabled slug, wrong form title)
- Added prominent Add New Game button at top of section (master admin only)
- DOMContentLoaded init ensures form state is correct on page load

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 18:49:57 +00:00
parent 0c96b0ad7c
commit 56ea742495
+11 -4
View File
@@ -772,7 +772,14 @@ tr:hover td{background:rgba(255,255,255,.015)}
<!-- ── GAME MANAGEMENT ─────────────────────────────────── -->
<div class="section" id="section-games">
<div class="page-title">🕹️ Game Management</div>
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:20px;flex-wrap:wrap;gap:10px">
<div class="page-title" style="margin-bottom:0">🕹️ Game Management</div>
<?php if ((int)$_SESSION['user_id'] === MASTER_ADMIN_ID): ?>
<button class="btn btn-gold" onclick="resetGameForm();document.getElementById('game-form-card').scrollIntoView({behavior:'smooth'})" style="padding:10px 20px;font-size:15px">
Add New Game
</button>
<?php endif; ?>
</div>
<!-- Add / Edit form — master admin always sees this; others see it only when editing -->
<div class="card" id="game-form-card" style="margin-bottom:16px;<?= (int)$_SESSION['user_id'] !== MASTER_ADMIN_ID ? 'display:none' : '' ?>">
@@ -1172,8 +1179,8 @@ loadStats();
loadPurchases('pending');
loadCashouts('pending');
loadUsers();
// Initialize game form state on page load
if (typeof resetGameForm === 'function') resetGameForm();
// Initialize game form once DOM is ready
document.addEventListener('DOMContentLoaded', () => resetGameForm());
async function loadStats() {
const d = await apiFetch('stats');
@@ -3428,7 +3435,7 @@ function showSec(name) {
if (name === 'referrals') { loadAdminReferrals('pending', document.querySelector('#section-referrals .ftab')); }
if (name === 'platform-accounts') loadPlatformAccountRequests('pending', document.querySelector('#section-platform-accounts .ftab'));
if (name === 'broadcasts') loadBroadcasts();
if (name === 'games') { loadGames(); loadArchivedGames(); }
if (name === 'games') { loadGames(); loadArchivedGames(); resetGameForm(); }
if (name === 'payments') loadPaymentSettings();
if (name === 'payout-settings') loadPayoutSettings();
if (name === 'cashout-methods') loadCashoutMethods();