|
- <div class="container mt-4">
- <div class="d-flex justify-content-between align-items-center mb-4">
- <h1>Territories</h1>
- <a href="/territories/new" class="btn btn-primary">New Territory</a>
- </div>
-
- <% Flash().ShowSuccessIfPresent %>
- <% Flash().ShowErrorsIfPresent %>
-
- <!-- Search Form -->
- <div class="card mb-4">
- <div class="card-body">
- <form method="get" action="/territories" class="row g-3">
- <div class="col-md-8">
- <div class="input-group">
- <input type="text" class="form-control" name="q" placeholder="Search by name or description..." value="<%= Server.HTMLEncode(TerritoryController.searchTerm) %>">
- <button class="btn btn-outline-primary" type="submit">Search</button>
- <% If TerritoryController.searchTerm <> "" Then %>
- <a href="/territories" class="btn btn-outline-secondary">Clear</a>
- <% End If %>
- </div>
- </div>
- <div class="col-md-4 text-end">
- <span class="text-muted">
- <% If TerritoryController.searchTerm <> "" Then %>
- Found <%= TerritoryController.recordCount %> result(s)
- <% Else %>
- <%= TerritoryController.recordCount %> total territories
- <% End If %>
- </span>
- </div>
- </form>
- </div>
- </div>
-
- <div class="table-responsive">
- <table class="table table-striped table-hover">
- <thead class="table-dark">
- <tr>
- <th>ID</th>
- <th>Name</th>
- <th>Description</th>
- <th>Households</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- <%
- Dim iter, t
- Set iter = TerritoryController.territories.Iterator()
- If Not iter.HasNext() Then
- %>
- <tr>
- <td colspan="5" class="text-center text-muted py-4">
- <% If TerritoryController.searchTerm <> "" Then %>
- No territories found matching "<%= Server.HTMLEncode(TerritoryController.searchTerm) %>"
- <% Else %>
- No territories found. <a href="/territories/new">Create one</a>
- <% End If %>
- </td>
- </tr>
- <%
- Else
- Do While iter.HasNext()
- Set t = iter.GetNext()
- %>
- <tr>
- <td><%= t.Id %></td>
- <td><%= Server.HTMLEncode(t.Name) %></td>
- <td><%= Server.HTMLEncode(Left(t.Description & "", 50)) %><% If Len(t.Description & "") > 50 Then Response.Write "..." End If %></td>
- <%
- Dim householdCount
- householdCount = 0
- If IsObject(TerritoryController.territoryHouseholdCounts) Then
- If TerritoryController.territoryHouseholdCounts.Exists(CLng(t.Id)) Then
- householdCount = TerritoryController.territoryHouseholdCounts(CLng(t.Id))
- End If
- End If
- %>
- <td><%= householdCount %></td>
- <td>
- <a href="/territories/<%= t.Id %>" class="btn btn-sm btn-info">View</a>
- <a href="/territories/<%= t.Id %>/edit" class="btn btn-sm btn-warning">Edit</a>
- <form method="post" action="/territories/<%= t.Id %>/delete" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this territory?');">
- <button type="submit" class="btn btn-sm btn-danger">Delete</button>
- </form>
- </td>
- </tr>
- <%
- Loop
- End If
- %>
- </tbody>
- </table>
- </div>
-
- <!-- Pagination -->
- <% If TerritoryController.pageCount > 1 Then %>
- <%
- Dim baseUrl, pg, startPage, endPage
- baseUrl = "/territories?"
- If TerritoryController.searchTerm <> "" Then
- baseUrl = baseUrl & "q=" & Server.URLEncode(TerritoryController.searchTerm) & "&"
- End If
-
- ' Calculate pagination range (show 5 pages at a time)
- startPage = TerritoryController.currentPage - 2
- If startPage < 1 Then startPage = 1
- endPage = startPage + 4
- If endPage > TerritoryController.pageCount Then
- endPage = TerritoryController.pageCount
- startPage = endPage - 4
- If startPage < 1 Then startPage = 1
- End If
- %>
- <nav aria-label="Territory pagination">
- <ul class="pagination justify-content-center">
- <!-- First page -->
- <li class="page-item <% If TerritoryController.currentPage = 1 Then Response.Write "disabled" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=1">« First</a>
- </li>
-
- <!-- Previous page -->
- <li class="page-item <% If TerritoryController.currentPage = 1 Then Response.Write "disabled" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=<%= TerritoryController.currentPage - 1 %>">‹ Prev</a>
- </li>
-
- <!-- Page numbers -->
- <% For pg = startPage To endPage %>
- <li class="page-item <% If pg = TerritoryController.currentPage Then Response.Write "active" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=<%= pg %>"><%= pg %></a>
- </li>
- <% Next %>
-
- <!-- Next page -->
- <li class="page-item <% If TerritoryController.currentPage >= TerritoryController.pageCount Then Response.Write "disabled" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=<%= TerritoryController.currentPage + 1 %>">Next ›</a>
- </li>
-
- <!-- Last page -->
- <li class="page-item <% If TerritoryController.currentPage >= TerritoryController.pageCount Then Response.Write "disabled" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=<%= TerritoryController.pageCount %>">Last »</a>
- </li>
- </ul>
- </nav>
- <p class="text-center text-muted">
- Page <%= TerritoryController.currentPage %> of <%= TerritoryController.pageCount %>
- </p>
- <% End If %>
- </div>
|