888 lines
27 KiB
HTML
888 lines
27 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Create QR Code - QR Management System</title>
|
|
<link
|
|
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
|
|
rel="stylesheet"
|
|
/>
|
|
<style>
|
|
:root {
|
|
--primary-color: #2563eb;
|
|
--secondary-color: #64748b;
|
|
--success-color: #10b981;
|
|
--warning-color: #f59e0b;
|
|
--error-color: #ef4444;
|
|
--gray-50: #f8fafc;
|
|
--gray-100: #f1f5f9;
|
|
--gray-200: #e2e8f0;
|
|
--gray-300: #cbd5e1;
|
|
--gray-500: #64748b;
|
|
--gray-600: #475569;
|
|
--gray-700: #334155;
|
|
--gray-800: #1e293b;
|
|
--gray-900: #0f172a;
|
|
--white: #ffffff;
|
|
--radius-lg: 8px;
|
|
--radius-xl: 12px;
|
|
--radius-2xl: 16px;
|
|
--shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1),
|
|
0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
|
--transition: all 0.2s ease-in-out;
|
|
--font-size-base: 1rem;
|
|
}
|
|
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
|
sans-serif;
|
|
background: linear-gradient(
|
|
135deg,
|
|
var(--gray-50) 0%,
|
|
var(--gray-100) 100%
|
|
);
|
|
color: var(--gray-800);
|
|
line-height: 1.6;
|
|
min-height: 100vh;
|
|
padding: 2rem 1rem;
|
|
}
|
|
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.form-container {
|
|
background: var(--white);
|
|
border-radius: var(--radius-2xl);
|
|
box-shadow: var(--shadow);
|
|
padding: 2rem;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.form-header {
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
padding-bottom: 1.5rem;
|
|
border-bottom: 1px solid var(--gray-200);
|
|
}
|
|
|
|
.form-header h1 {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.5rem;
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
color: var(--gray-900);
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.form-header p {
|
|
color: var(--gray-500);
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.form-section {
|
|
margin-bottom: 2rem;
|
|
padding: 1.5rem;
|
|
background: var(--gray-50);
|
|
border-radius: var(--radius-xl);
|
|
border: 1px solid var(--gray-200);
|
|
}
|
|
|
|
.section-header {
|
|
margin-bottom: 1.5rem;
|
|
padding-bottom: 1rem;
|
|
border-bottom: 1px solid var(--gray-200);
|
|
}
|
|
|
|
.section-header h3 {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
font-size: 1.25rem;
|
|
font-weight: 600;
|
|
color: var(--gray-800);
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.section-header p {
|
|
color: var(--gray-600);
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
.form-group {
|
|
position: relative;
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
.form-group label {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
font-weight: 600;
|
|
color: var(--gray-700);
|
|
margin-bottom: 0.5rem;
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
.form-group input,
|
|
.form-group select,
|
|
.form-group textarea {
|
|
width: 100%;
|
|
padding: 0.75rem;
|
|
border: 2px solid var(--gray-200);
|
|
border-radius: var(--radius-lg);
|
|
font-size: var(--font-size-base);
|
|
transition: var(--transition);
|
|
background-color: var(--white);
|
|
}
|
|
|
|
.form-group input:focus,
|
|
.form-group select:focus,
|
|
.form-group textarea:focus {
|
|
outline: none;
|
|
border-color: var(--primary-color);
|
|
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
|
|
}
|
|
|
|
.form-group textarea {
|
|
resize: vertical;
|
|
min-height: 80px;
|
|
}
|
|
|
|
.form-help {
|
|
display: block;
|
|
margin-top: 0.5rem;
|
|
font-size: 0.75rem;
|
|
color: var(--gray-500);
|
|
}
|
|
|
|
.character-counter {
|
|
position: absolute;
|
|
bottom: -1.5rem;
|
|
right: 0;
|
|
font-size: 0.75rem;
|
|
color: var(--gray-500);
|
|
}
|
|
|
|
.character-counter.warning {
|
|
color: var(--warning-color);
|
|
}
|
|
|
|
/* Coordinate Display Section */
|
|
.coordinates-section {
|
|
background: var(--primary-color);
|
|
color: white;
|
|
border-radius: var(--radius-xl);
|
|
padding: 1.5rem;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.coordinates-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.coordinates-header h4 {
|
|
font-size: 1.125rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.coordinates-content {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.coordinate-display {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
padding: 1rem;
|
|
border-radius: var(--radius-lg);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.coordinate-info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.25rem;
|
|
}
|
|
|
|
.coordinate-value {
|
|
font-family: "Courier New", monospace;
|
|
font-size: 1.125rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.coordinate-label {
|
|
font-size: 0.875rem;
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.coordinates-actions {
|
|
display: flex;
|
|
gap: 0.75rem;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.btn-coordinate {
|
|
padding: 0.5rem 1rem;
|
|
background: rgba(255, 255, 255, 0.2);
|
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
border-radius: var(--radius-lg);
|
|
color: white;
|
|
font-size: 0.875rem;
|
|
cursor: pointer;
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.btn-coordinate:hover {
|
|
background: rgba(255, 255, 255, 0.3);
|
|
}
|
|
|
|
.btn-coordinate:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.loading-spinner {
|
|
display: inline-block;
|
|
width: 1rem;
|
|
height: 1rem;
|
|
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
border-radius: 50%;
|
|
border-top-color: white;
|
|
animation: spin 1s ease-in-out infinite;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
|
|
.status-message {
|
|
padding: 0.75rem;
|
|
border-radius: var(--radius-lg);
|
|
margin-top: 1rem;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.status-success {
|
|
background: rgba(16, 185, 129, 0.1);
|
|
color: var(--success-color);
|
|
border: 1px solid rgba(16, 185, 129, 0.2);
|
|
}
|
|
|
|
.status-error {
|
|
background: rgba(239, 68, 68, 0.1);
|
|
color: var(--error-color);
|
|
border: 1px solid rgba(239, 68, 68, 0.2);
|
|
}
|
|
|
|
.status-warning {
|
|
background: rgba(245, 158, 11, 0.1);
|
|
color: var(--warning-color);
|
|
border: 1px solid rgba(245, 158, 11, 0.2);
|
|
}
|
|
|
|
.form-actions {
|
|
display: flex;
|
|
gap: 1rem;
|
|
justify-content: center;
|
|
margin-top: 2rem;
|
|
padding-top: 2rem;
|
|
border-top: 1px solid var(--gray-200);
|
|
}
|
|
|
|
.btn {
|
|
padding: 0.75rem 2rem;
|
|
border: none;
|
|
border-radius: var(--radius-lg);
|
|
font-size: 1rem;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: var(--transition);
|
|
text-decoration: none;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: var(--primary-color);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background: #1d4ed8;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: var(--gray-200);
|
|
color: var(--gray-700);
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background: var(--gray-300);
|
|
}
|
|
|
|
.error-message {
|
|
color: var(--error-color);
|
|
font-size: 0.875rem;
|
|
margin-top: 0.5rem;
|
|
}
|
|
|
|
.form-group.has-error input,
|
|
.form-group.has-error textarea {
|
|
border-color: var(--error-color);
|
|
}
|
|
|
|
@media (max-width: 640px) {
|
|
.container {
|
|
padding: 0 0.5rem;
|
|
}
|
|
|
|
.form-container {
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.form-actions {
|
|
flex-direction: column;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="form-container">
|
|
<div class="form-header">
|
|
<h1>
|
|
<i class="fas fa-qrcode"></i>
|
|
Create New QR Code
|
|
</h1>
|
|
<p>Generate a QR code for attendance tracking at your location</p>
|
|
</div>
|
|
|
|
<form method="POST" class="form" id="createQRForm">
|
|
<!-- Basic Information Section -->
|
|
<div class="form-section">
|
|
<div class="section-header">
|
|
<h3>
|
|
<i class="fas fa-info-circle"></i>
|
|
Basic Information
|
|
</h3>
|
|
<p>Provide the basic details for your QR code</p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="name">
|
|
<i class="fas fa-tag"></i>
|
|
QR Code Name <span style="color: var(--error-color)">*</span>
|
|
</label>
|
|
<input
|
|
type="text"
|
|
id="name"
|
|
name="name"
|
|
required
|
|
placeholder="e.g., Main Office Entrance, Conference Room A"
|
|
maxlength="100"
|
|
/>
|
|
<small class="form-help"
|
|
>A unique name to identify this QR code</small
|
|
>
|
|
<div class="character-counter">
|
|
<span id="nameCounter">0/100</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="location">
|
|
<i class="fas fa-map-marker-alt"></i>
|
|
Location Name <span style="color: var(--error-color)">*</span>
|
|
</label>
|
|
<input
|
|
type="text"
|
|
id="location"
|
|
name="location"
|
|
required
|
|
placeholder="e.g., Corporate Headquarters, Branch Office"
|
|
maxlength="100"
|
|
/>
|
|
<small class="form-help"
|
|
>The name of the physical location where this QR code will be
|
|
used</small
|
|
>
|
|
<div class="character-counter">
|
|
<span id="locationCounter">0/100</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="project_id">
|
|
<i class="fas fa-folder"></i>
|
|
Project (Optional)
|
|
</label>
|
|
<select id="project_id" name="project_id" class="form-select">
|
|
<option value="">Select a project (Optional)</option>
|
|
{% for project in projects %}
|
|
<option value="{{ project.id }}">
|
|
{{ project.name }} ({{ project.qr_count }} QR codes)
|
|
</option>
|
|
{% endfor %}
|
|
</select>
|
|
<small class="form-help">
|
|
<i class="fas fa-info-circle"></i>
|
|
Organize your QR code by assigning it to a project
|
|
</small>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Location Details Section -->
|
|
<div class="form-section">
|
|
<div class="section-header">
|
|
<h3>
|
|
<i class="fas fa-building"></i>
|
|
Location Details
|
|
</h3>
|
|
<p>Provide the complete address and event information</p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="location_address">
|
|
<i class="fas fa-home"></i>
|
|
Complete Address
|
|
<span style="color: var(--error-color)">*</span>
|
|
</label>
|
|
<textarea
|
|
id="location_address"
|
|
name="location_address"
|
|
required
|
|
placeholder="Enter the full address including street, city, state, and ZIP code"
|
|
rows="3"
|
|
maxlength="500"
|
|
></textarea>
|
|
<small class="form-help"
|
|
>Include all address details for accurate location
|
|
identification</small
|
|
>
|
|
<div class="character-counter">
|
|
<span id="addressCounter">0/500</span>
|
|
</div>
|
|
|
|
<!-- Address Coordinates Section -->
|
|
<div
|
|
class="coordinates-section"
|
|
id="coordinatesSection"
|
|
style="display: none"
|
|
>
|
|
<div class="coordinates-header">
|
|
<i class="fas fa-crosshairs"></i>
|
|
<h4>Address Coordinates</h4>
|
|
</div>
|
|
|
|
<div class="coordinates-content">
|
|
<div class="coordinate-display">
|
|
<div class="coordinate-info">
|
|
<div class="coordinate-value" id="latitudeDisplay">
|
|
---.------
|
|
</div>
|
|
<div class="coordinate-label">Latitude</div>
|
|
</div>
|
|
<div class="coordinate-info">
|
|
<div class="coordinate-value" id="longitudeDisplay">
|
|
---.------
|
|
</div>
|
|
<div class="coordinate-label">Longitude</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="coordinates-actions">
|
|
<button
|
|
type="button"
|
|
class="btn-coordinate"
|
|
id="geocodeBtn"
|
|
>
|
|
<i class="fas fa-search-location"></i>
|
|
Get Coordinates
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="btn-coordinate"
|
|
id="clearCoordinatesBtn"
|
|
style="display: none"
|
|
>
|
|
<i class="fas fa-times"></i>
|
|
Clear
|
|
</button>
|
|
</div>
|
|
|
|
<div id="coordinateStatus"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="location_event">
|
|
<i class="fas fa-calendar-alt"></i>
|
|
Event or Purpose
|
|
<span style="color: var(--error-color)">*</span>
|
|
</label>
|
|
<input
|
|
type="text"
|
|
id="location_event"
|
|
name="location_event"
|
|
required
|
|
placeholder="e.g., Weekly Team Meeting, Customer Check-in, Training Session"
|
|
maxlength="200"
|
|
/>
|
|
<small class="form-help"
|
|
>Describe the event or purpose for this QR code</small
|
|
>
|
|
<div class="character-counter">
|
|
<span id="eventCounter">0/200</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Hidden coordinate fields for form submission -->
|
|
<input type="hidden" id="latitude" name="latitude" value="" />
|
|
<input type="hidden" id="longitude" name="longitude" value="" />
|
|
<input type="hidden" id="coordinate_accuracy" name="coordinate_accuracy" value="" />
|
|
|
|
<!-- Form Actions -->
|
|
<div class="form-actions">
|
|
<a href="{{ url_for('dashboard') }}" class="btn btn-secondary">
|
|
<i class="fas fa-arrow-left"></i>
|
|
Cancel
|
|
</a>
|
|
<button type="submit" class="btn btn-primary" id="submitBtn">
|
|
<i class="fas fa-plus"></i>
|
|
Create QR Code
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Global variables
|
|
let coordinatesData = {
|
|
latitude: null,
|
|
longitude: null,
|
|
accuracy: null,
|
|
};
|
|
|
|
// Initialize the form when page loads
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
initializeForm();
|
|
initializeCharacterCounters();
|
|
initializeCoordinatesFeature();
|
|
initializeProjectDropdown();
|
|
});
|
|
|
|
function initializeForm() {
|
|
// Form validation on submit
|
|
document
|
|
.getElementById("createQRForm")
|
|
.addEventListener("submit", function (e) {
|
|
if (!validateForm()) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
// Show loading state
|
|
const submitBtn = document.getElementById("submitBtn");
|
|
submitBtn.innerHTML =
|
|
'<i class="fas fa-spinner fa-spin"></i> Creating QR Code...';
|
|
submitBtn.disabled = true;
|
|
});
|
|
}
|
|
|
|
function initializeCharacterCounters() {
|
|
const counters = [
|
|
{ input: "name", counter: "nameCounter", max: 100 },
|
|
{ input: "location", counter: "locationCounter", max: 100 },
|
|
{ input: "location_address", counter: "addressCounter", max: 500 },
|
|
{ input: "location_event", counter: "eventCounter", max: 200 },
|
|
];
|
|
|
|
counters.forEach((item) => {
|
|
const input = document.getElementById(item.input);
|
|
const counter = document.getElementById(item.counter);
|
|
|
|
if (input && counter) {
|
|
input.addEventListener("input", function () {
|
|
const length = this.value.length;
|
|
counter.textContent = `${length}/${item.max}`;
|
|
|
|
if (length > item.max * 0.9) {
|
|
counter.classList.add("warning");
|
|
} else {
|
|
counter.classList.remove("warning");
|
|
}
|
|
});
|
|
|
|
// Initial count
|
|
const length = input.value.length;
|
|
counter.textContent = `${length}/${item.max}`;
|
|
}
|
|
});
|
|
}
|
|
|
|
function initializeCoordinatesFeature() {
|
|
const addressInput = document.getElementById("location_address");
|
|
const coordinatesSection =
|
|
document.getElementById("coordinatesSection");
|
|
const geocodeBtn = document.getElementById("geocodeBtn");
|
|
const clearBtn = document.getElementById("clearCoordinatesBtn");
|
|
|
|
// Show coordinates section when address has content
|
|
addressInput.addEventListener("input", function () {
|
|
if (this.value.trim().length > 10) {
|
|
coordinatesSection.style.display = "block";
|
|
} else {
|
|
coordinatesSection.style.display = "none";
|
|
clearCoordinates();
|
|
}
|
|
});
|
|
|
|
// Geocode button click
|
|
geocodeBtn.addEventListener("click", function () {
|
|
const address = addressInput.value.trim();
|
|
if (address.length > 10) {
|
|
geocodeAddress(address);
|
|
} else {
|
|
showStatus("error", "Please enter a complete address first");
|
|
}
|
|
});
|
|
|
|
// Clear coordinates button
|
|
clearBtn.addEventListener("click", clearCoordinates);
|
|
}
|
|
|
|
async function geocodeAddress(address) {
|
|
const geocodeBtn = document.getElementById("geocodeBtn");
|
|
const statusDiv = document.getElementById("coordinateStatus");
|
|
|
|
// Show loading state
|
|
geocodeBtn.innerHTML =
|
|
'<span class="loading-spinner"></span> Getting coordinates...';
|
|
geocodeBtn.disabled = true;
|
|
|
|
try {
|
|
const response = await fetch("/api/geocode", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ address: address }),
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
// Update coordinates
|
|
coordinatesData = {
|
|
latitude: result.data.latitude,
|
|
longitude: result.data.longitude,
|
|
accuracy: result.data.accuracy,
|
|
};
|
|
|
|
// Update display
|
|
updateCoordinatesDisplay();
|
|
|
|
// Update hidden form fields
|
|
updateHiddenFields();
|
|
|
|
// Show success message
|
|
showStatus("success", result.message);
|
|
} else {
|
|
showStatus("error", result.message);
|
|
}
|
|
} catch (error) {
|
|
console.error("Geocoding error:", error);
|
|
showStatus("error", "Network error occurred. Please try again.");
|
|
}
|
|
|
|
// Reset button state
|
|
geocodeBtn.innerHTML =
|
|
'<i class="fas fa-search-location"></i> Get Coordinates';
|
|
geocodeBtn.disabled = false;
|
|
}
|
|
|
|
function updateCoordinatesDisplay() {
|
|
const latDisplay = document.getElementById("latitudeDisplay");
|
|
const lngDisplay = document.getElementById("longitudeDisplay");
|
|
const clearBtn = document.getElementById("clearCoordinatesBtn");
|
|
|
|
if (coordinatesData.latitude && coordinatesData.longitude) {
|
|
latDisplay.textContent = coordinatesData.latitude.toFixed(10);
|
|
lngDisplay.textContent = coordinatesData.longitude.toFixed(10);
|
|
clearBtn.style.display = "inline-flex";
|
|
} else {
|
|
latDisplay.textContent = "---.----------";
|
|
lngDisplay.textContent = "---.----------";
|
|
clearBtn.style.display = "none";
|
|
}
|
|
}
|
|
|
|
function updateHiddenFields() {
|
|
console.log("📝 Updating hidden coordinate fields");
|
|
|
|
// Update hidden form fields with coordinate data
|
|
const latitudeField = document.getElementById("latitude");
|
|
const longitudeField = document.getElementById("longitude");
|
|
const accuracyField = document.getElementById("coordinate_accuracy");
|
|
|
|
if (coordinatesData.latitude && coordinatesData.longitude) {
|
|
latitudeField.value = coordinatesData.latitude;
|
|
longitudeField.value = coordinatesData.longitude;
|
|
accuracyField.value = coordinatesData.accuracy || 'geocoded';
|
|
|
|
console.log("✓ Hidden fields updated:", {
|
|
latitude: latitudeField.value,
|
|
longitude: longitudeField.value,
|
|
accuracy: accuracyField.value
|
|
});
|
|
} else {
|
|
// Clear fields if no coordinates
|
|
latitudeField.value = '';
|
|
longitudeField.value = '';
|
|
accuracyField.value = '';
|
|
|
|
console.log("✓ Hidden fields cleared");
|
|
}
|
|
}
|
|
|
|
function clearCoordinates() {
|
|
coordinatesData = {
|
|
latitude: null,
|
|
longitude: null,
|
|
accuracy: null,
|
|
};
|
|
|
|
// Clear display
|
|
document.getElementById("latitudeValue").textContent = "--";
|
|
document.getElementById("longitudeValue").textContent = "--";
|
|
document.getElementById("accuracyValue").textContent = "--";
|
|
|
|
// Clear hidden fields
|
|
updateHiddenFields();
|
|
|
|
// Hide coordinates section
|
|
document.getElementById("coordinatesSection").style.display = "none";
|
|
|
|
console.log("🧹 Coordinates cleared");
|
|
}
|
|
|
|
function showStatus(type, message) {
|
|
const statusDiv = document.getElementById("coordinateStatus");
|
|
const iconMap = {
|
|
success: "fas fa-check-circle",
|
|
error: "fas fa-exclamation-circle",
|
|
warning: "fas fa-exclamation-triangle",
|
|
};
|
|
|
|
statusDiv.innerHTML = `
|
|
<div class="status-message status-${type}">
|
|
<i class="${iconMap[type]}"></i>
|
|
<span>${message}</span>
|
|
</div>
|
|
`;
|
|
|
|
// Auto-clear after 5 seconds for success messages
|
|
if (type === "success") {
|
|
setTimeout(() => {
|
|
statusDiv.innerHTML = "";
|
|
}, 5000);
|
|
}
|
|
}
|
|
|
|
function validateForm() {
|
|
const name = document.getElementById("name").value.trim();
|
|
const location = document.getElementById("location").value.trim();
|
|
const address = document.getElementById("location_address").value.trim();
|
|
|
|
if (!name || !location || !address) {
|
|
alert("Please fill in all required fields");
|
|
return false;
|
|
}
|
|
|
|
// DEBUG: Log coordinates being submitted
|
|
const latitude = document.getElementById("latitude").value;
|
|
const longitude = document.getElementById("longitude").value;
|
|
const accuracy = document.getElementById("coordinate_accuracy").value;
|
|
|
|
console.log("🚀 Form submission data:", {
|
|
name: name,
|
|
location: location,
|
|
address: address,
|
|
coordinates: {
|
|
latitude: latitude,
|
|
longitude: longitude,
|
|
accuracy: accuracy
|
|
}
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
function showFieldError(input, message) {
|
|
const formGroup = input.closest(".form-group");
|
|
formGroup.classList.add("has-error");
|
|
|
|
let errorElement = formGroup.querySelector(".error-message");
|
|
if (!errorElement) {
|
|
errorElement = document.createElement("div");
|
|
errorElement.className = "error-message";
|
|
formGroup.appendChild(errorElement);
|
|
}
|
|
|
|
errorElement.textContent = message;
|
|
}
|
|
|
|
function clearFieldError(input) {
|
|
const formGroup = input.closest(".form-group");
|
|
formGroup.classList.remove("has-error");
|
|
|
|
const errorElement = formGroup.querySelector(".error-message");
|
|
if (errorElement) {
|
|
errorElement.remove();
|
|
}
|
|
}
|
|
|
|
// Project dropdown functionality
|
|
function initializeProjectDropdown() {
|
|
const projectSelect = document.getElementById('project_id');
|
|
|
|
if (projectSelect) {
|
|
// Load projects dynamically (optional enhancement)
|
|
// For now, projects are loaded server-side
|
|
projectSelect.addEventListener('change', function() {
|
|
const selectedOption = this.options[this.selectedIndex];
|
|
|
|
if (selectedOption.value) {
|
|
console.log('Selected project:', selectedOption.text);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|