Files
Ecobuddy/Views/template/createModal.phtml
2025-04-22 01:17:48 +01:00

119 lines
6.1 KiB
PHTML
Executable File

<!-- Create Facility Modal -->
<div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="createModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content border-0 shadow">
<div class="modal-header bg-light">
<h5 class="modal-title" id="createModalLabel">
<i class="bi bi-plus-circle-fill text-success me-2"></i>Add New Facility
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body p-4">
<!-- Create facility form -->
<form id="createForm">
<!-- Form fields -->
<div class="mb-3">
<label for="createTitle" class="form-label">Facility Name</label>
<input type="text" class="form-control" id="createTitle" name="title" required>
</div>
<div class="mb-3">
<label for="createCategory" class="form-label">Category</label>
<select class="form-select" id="createCategory" name="category" required>
<option value="" selected disabled>Select a category</option>
<option value="recycling">Recycling Center</option>
<option value="compost">Composting Facility</option>
<option value="ewaste">E-Waste Collection</option>
<option value="donation">Donation Center</option>
<option value="refill">Refill Station</option>
<option value="repair">Repair Shop</option>
<option value="garden">Community Garden</option>
<option value="market">Farmers Market</option>
<option value="other">Other</option>
</select>
</div>
<div class="mb-3">
<label for="createDescription" class="form-label">Description</label>
<textarea class="form-control" id="createDescription" name="description" rows="3" required></textarea>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="createLatitude" class="form-label">Latitude</label>
<input type="number" step="any" class="form-control" id="createLatitude" name="lat" required>
</div>
<div class="col-md-6 mb-3">
<label for="createLongitude" class="form-label">Longitude</label>
<input type="number" step="any" class="form-control" id="createLongitude" name="lng" required>
</div>
</div>
<div class="mb-3">
<label for="createHouseNumber" class="form-label">House Number/Name</label>
<input type="text" class="form-control" id="createHouseNumber" name="houseNumber" required>
</div>
<div class="mb-3">
<label for="createStreetName" class="form-label">Street Name</label>
<input type="text" class="form-control" id="createStreetName" name="streetName" required>
</div>
<div class="mb-3">
<label for="createTown" class="form-label">Town/City</label>
<input type="text" class="form-control" id="createTown" name="town" required>
</div>
<div class="mb-3">
<label for="createCounty" class="form-label">County</label>
<input type="text" class="form-control" id="createCounty" name="county" required>
</div>
<div class="mb-3">
<label for="createPostcode" class="form-label">Postcode</label>
<input type="text" class="form-control" id="createPostcode" name="postcode" required>
</div>
<div id="createError" class="alert alert-danger" style="display: none;"></div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-success">
<i class="bi bi-plus-circle me-1"></i>Create Facility
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
// Only allow admin users to access this modal
document.addEventListener('DOMContentLoaded', function() {
const createModal = document.getElementById('createModal');
if (createModal) {
createModal.addEventListener('show.bs.modal', async function(event) {
// Validate authentication with server first
let isAdmin = false;
if (auth.isAuthenticated()) {
try {
// This will validate the token with the server and handle refresh if needed
const isValid = await auth.validateOnLoad();
if (isValid) {
isAdmin = auth.isAdmin();
}
} catch (error) {
console.error('Error validating authentication:', error);
isAdmin = false;
}
}
if (!isAdmin) {
event.preventDefault();
alert('You need administrator privileges to add new facilities.');
}
});
}
});
</script>