Files
telegram-shop/src/admin/views/locations.ejs
NW 88a15acb29 fix(admin): delete feedback alerts + informative block errors (issue #127)
- locations/categories GET pass req.query.error/success to views
- locations/categories EJS render dismissible error/success alerts (modeled on catalog.ejs)
- Delete errors include blocking counts + 'Remove X first' hints
- 🔒 lock hint on rows with linked categories/products/subcategories
- 18 new tests (adminDeleteFeedback.test.js); 48 total pass
2026-08-04 17:05:06 +01:00

98 lines
5.6 KiB
Plaintext

<% if (error) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<%= error %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<% if (success) { %>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<%= success %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<a href="/catalog" class="btn btn-sm btn-outline-secondary mb-2">« Back to Catalog</a>
<div class="panel panel-icon mb-3">
<div class="panel-hdr">
<h2 class="d-flex align-items-center gap-2">
<button class="btn btn-link p-0 text-decoration-none" type="button" data-bs-toggle="collapse" data-bs-target="#addLocationCollapse" aria-expanded="false" aria-controls="addLocationCollapse">Add Location</button>
</h2>
</div>
<div class="collapse" id="addLocationCollapse">
<div class="panel-content">
<form method="POST" action="/locations" class="d-flex flex-wrap gap-2 align-items-end">
<input type="hidden" name="_csrf" value="<%= csrfToken %>">
<div>
<label class="form-label">Country</label>
<input name="country" class="form-control form-control-sm" placeholder="Country" required>
</div>
<div>
<label class="form-label">City</label>
<input name="city" class="form-control form-control-sm" placeholder="City" required>
</div>
<div>
<label class="form-label">District</label>
<input name="district" class="form-control form-control-sm" placeholder="District">
</div>
<button type="submit" class="btn btn-primary btn-sm">Add</button>
</form>
</div>
</div>
</div>
<div class="panel panel-icon">
<div class="panel-container show">
<div class="panel-content">
<table class="table table-striped table-bordered table-hover mb-0">
<thead><tr><th>ID</th><th>Country</th><th>City</th><th>District</th><th>Categories</th><th>Products</th><th>Status</th><th>Actions</th></tr></thead>
<tbody>
<% if (locations.length === 0) { %>
<tr><td colspan="8" class="text-muted">No locations</td></tr>
<% } else { %>
<% locations.forEach(function(l) { %>
<tr<%= l.is_active === 0 ? ' class="table-secondary"' : '' %>>
<td><%= l.id %></td>
<td><%= l.country %></td>
<td><%= l.city %></td>
<td><%= l.district || '' %></td>
<td><%= l.category_count || 0 %></td>
<td><%= l.product_count || 0 %></td>
<td>
<% if (l.is_active === 1) { %>
<span class="badge bg-success">Active</span>
<% } else { %>
<span class="badge bg-secondary">Disabled</span>
<% } %>
</td>
<td>
<form method="POST" action="/locations/<%= l.id %>/update" class="d-inline-flex gap-1 align-items-center mb-1">
<input type="hidden" name="_csrf" value="<%= csrfToken %>">
<input name="country" class="form-control form-control-sm" value="<%= l.country %>" required size="8" style="width:80px">
<input name="city" class="form-control form-control-sm" value="<%= l.city %>" required size="8" style="width:80px">
<input name="district" class="form-control form-control-sm" value="<%= l.district || '' %>" size="8" style="width:80px">
<button class="btn btn-sm btn-primary">Save</button>
</form>
<form method="POST" action="/locations/<%= l.id %>/toggle" class="d-inline" onsubmit="<%= l.is_active === 1 ? "return confirm('Disable this location?')" : '' %>">
<input type="hidden" name="_csrf" value="<%= csrfToken %>">
<% if (l.is_active === 1) { %>
<button class="btn btn-sm btn-warning">Disable</button>
<% } else { %>
<button class="btn btn-sm btn-success">Enable</button>
<% } %>
</form>
<form method="POST" action="/locations/<%= l.id %>/delete" class="d-inline" onsubmit="return confirm('Delete location?')">
<input type="hidden" name="_csrf" value="<%= csrfToken %>">
<button class="btn btn-sm btn-danger">Delete</button>
</form>
<% if (l.category_count > 0 || l.product_count > 0) { %>
<span class="text-warning" title="Blocks deletion">🔒</span>
<% } %>
</td>
</tr>
<% }); %>
<% } %>
</tbody>
</table>
</div>
</div>
</div>