|
- <div class="container mt-4">
- <div class="d-flex justify-content-between align-items-center mb-4">
- <h1>Households</h1>
- <a href="/households/new" class="btn btn-primary">New Household</a>
- </div>
-
- <% Flash().ShowSuccessIfPresent %>
- <% Flash().ShowErrorsIfPresent %>
-
- <!-- Search and Filter Form -->
- <div class="card mb-4">
- <div class="card-body">
- <form method="get" action="/households" class="row g-3">
- <div class="col-md-5">
- <div class="input-group">
- <input type="text" class="form-control" name="q" placeholder="Search by address or street name..." value="<%= Server.HTMLEncode(HouseholdController.searchTerm) %>">
- <button class="btn btn-outline-primary" type="submit">Search</button>
- </div>
- </div>
- <div class="col-md-4">
- <select name="territory" class="form-select" onchange="this.form.submit()">
- <option value="">All Territories</option>
- <%
- Dim tIter, tItem
- Set tIter = HouseholdController.territoriesList.Iterator()
- Do While tIter.HasNext()
- Set tItem = tIter.GetNext()
- %>
- <option value="<%= tItem.Id %>" <% If tItem.Id = HouseholdController.filterTerritoryId Then Response.Write "selected" End If %>><%= Server.HTMLEncode(tItem.Name) %></option>
- <%
- Loop
- %>
- </select>
- </div>
- <div class="col-md-2">
- <select name="dnc" class="form-select" onchange="this.form.submit()">
- <option value="" <% If HouseholdController.filterDoNotCall = -1 Then Response.Write "selected" End If %>>All DNC Status</option>
- <option value="1" <% If HouseholdController.filterDoNotCall = 1 Then Response.Write "selected" End If %>>Do Not Call</option>
- <option value="0" <% If HouseholdController.filterDoNotCall = 0 Then Response.Write "selected" End If %>>Callable</option>
- </select>
- </div>
- <div class="col-md-1 text-end">
- <span class="text-muted">
- <%= HouseholdController.recordCount %> household(s)
- </span>
- <% If HouseholdController.searchTerm <> "" Or HouseholdController.filterTerritoryId > 0 Or HouseholdController.filterDoNotCall > -1 Then %>
- <a href="/households" class="btn btn-sm btn-outline-secondary ms-2">Clear</a>
- <% End If %>
- </div>
- </form>
- </div>
- </div>
-
- <div class="table-responsive">
- <table class="table table-striped table-hover">
- <thead class="table-dark">
- <tr>
- <th>ID</th>
- <th>Address</th>
- <th>Type</th>
- <th>DNC</th>
- <th>Street</th>
- <th>Territory</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- <%
- Dim iter, h
- Set iter = HouseholdController.households.Iterator()
- If Not iter.HasNext() Then
- %>
- <tr>
- <td colspan="7" class="text-center text-muted py-4">
- <% If HouseholdController.searchTerm <> "" Then %>
- No households found matching "<%= Server.HTMLEncode(HouseholdController.searchTerm) %>"
- <% ElseIf HouseholdController.filterTerritoryId > 0 Then %>
- No households found in this territory.
- <% Else %>
- No households found. <a href="/households/new">Create one</a>
- <% End If %>
- </td>
- </tr>
- <%
- Else
- Do While iter.HasNext()
- Set h = iter.GetNext()
- %>
- <tr>
- <td><%= h.Id %></td>
- <td><%= Server.HTMLEncode(h.Address) %></td>
- <td>
- <% If h.IsBusiness = 1 Then %>
- <span class="badge bg-info">Business</span>
- <% Else %>
- <span class="badge bg-secondary">Residential</span>
- <% End If %>
- </td>
- <td>
- <% If h.DoNotCall = 1 Then %>
- <span class="badge bg-danger">Do Not Call</span>
- <% If IsDate(h.DoNotCallDate) Then %>
- <div><small class="text-muted"><%= FormatDateTime(h.DoNotCallDate, 2) %></small></div>
- <% End If %>
- <% Else %>
- <span class="text-muted">No</span>
- <% End If %>
- </td>
- <td><%= h.StreetNumber %> <%= Server.HTMLEncode(h.StreetName) %></td>
- <td>
- <a href="/territories/<%= h.TerritoryId %>">
- <%
- If HouseholdController.territoryNamesById.Exists(CStr(h.TerritoryId)) Then
- Response.Write Server.HTMLEncode(HouseholdController.territoryNamesById(CStr(h.TerritoryId)))
- Else
- Response.Write "Territory " & h.TerritoryId
- End If
- %>
- </a>
- </td>
- <td>
- <a href="/households/<%= h.Id %>" class="btn btn-sm btn-info">View</a>
- <a href="/households/<%= h.Id %>/edit" class="btn btn-sm btn-warning">Edit</a>
- <form method="post" action="/households/<%= h.Id %>/delete" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this household?');">
- <button type="submit" class="btn btn-sm btn-danger">Delete</button>
- </form>
- </td>
- </tr>
- <%
- Loop
- End If
- %>
- </tbody>
- </table>
- </div>
-
- <!-- Pagination -->
- <% If HouseholdController.pageCount > 1 Then %>
- <%
- Dim baseUrl, pg, startPage, endPage
- baseUrl = "/households?"
- If HouseholdController.searchTerm <> "" Then
- baseUrl = baseUrl & "q=" & Server.URLEncode(HouseholdController.searchTerm) & "&"
- End If
- If HouseholdController.filterTerritoryId > 0 Then
- baseUrl = baseUrl & "territory=" & HouseholdController.filterTerritoryId & "&"
- End If
- If HouseholdController.filterDoNotCall > -1 Then
- baseUrl = baseUrl & "dnc=" & HouseholdController.filterDoNotCall & "&"
- End If
-
- ' Calculate pagination range (show 5 pages at a time)
- startPage = HouseholdController.currentPage - 2
- If startPage < 1 Then startPage = 1
- endPage = startPage + 4
- If endPage > HouseholdController.pageCount Then
- endPage = HouseholdController.pageCount
- startPage = endPage - 4
- If startPage < 1 Then startPage = 1
- End If
- %>
- <nav aria-label="Household pagination">
- <ul class="pagination justify-content-center">
- <li class="page-item <% If HouseholdController.currentPage = 1 Then Response.Write "disabled" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=1">« First</a>
- </li>
- <li class="page-item <% If HouseholdController.currentPage = 1 Then Response.Write "disabled" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=<%= HouseholdController.currentPage - 1 %>">‹ Prev</a>
- </li>
- <% For pg = startPage To endPage %>
- <li class="page-item <% If pg = HouseholdController.currentPage Then Response.Write "active" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=<%= pg %>"><%= pg %></a>
- </li>
- <% Next %>
- <li class="page-item <% If HouseholdController.currentPage >= HouseholdController.pageCount Then Response.Write "disabled" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=<%= HouseholdController.currentPage + 1 %>">Next ›</a>
- </li>
- <li class="page-item <% If HouseholdController.currentPage >= HouseholdController.pageCount Then Response.Write "disabled" End If %>">
- <a class="page-link" href="<%= baseUrl %>page=<%= HouseholdController.pageCount %>">Last »</a>
- </li>
- </ul>
- </nav>
- <p class="text-center text-muted">
- Page <%= HouseholdController.currentPage %> of <%= HouseholdController.pageCount %>
- </p>
- <% End If %>
- </div>
|