Files
NexHome/templates/properties/edit.html
T
Black-Cyan 9e9788ea22 🛠️
- add show price preference(store in cookies)
2026-06-12 17:36:57 +08:00

265 lines
13 KiB
HTML

{% extends "base.html" %}
{% block title %}Edit Listing - NexHome{% endblock %}
{% block content %}
<div class="max-w-3xl mx-auto px-4 py-10">
<h1 class="text-3xl font-bold text-primary mb-2">Edit Property</h1>
<p class="text-gray-500 mb-8">Update the details of your listing.</p>
{% if error %}
<div class="bg-red-100 border border-red-200 text-red-800 rounded-lg p-4 mb-6 text-sm">
{{ error }}
</div>
{% endif %}
<form method="POST" action="/properties/{{ prop.id }}/edit" enctype="multipart/form-data" class="bg-white rounded-2xl shadow-lg p-8 space-y-6">
<!-- Title -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Property Title *</label>
<input type="text" name="title" required
value="{{ prop.title }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<!-- Description -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Description *</label>
<textarea name="description" required rows="5"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">{{ prop.description }}</textarea>
</div>
<!-- Price & Type -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Price (USD) *</label>
<!-- Input mode toggle -->
<div class="flex gap-1 mb-2 bg-gray-100 rounded-lg p-0.5 text-xs">
<button type="button" id="priceModeTotal" onclick="setPriceMode('total')"
class="flex-1 py-1.5 rounded-md font-medium transition bg-white shadow text-primary">
Total Price
</button>
<button type="button" id="priceModeUnit" onclick="setPriceMode('unit')"
class="flex-1 py-1.5 rounded-md font-medium transition text-gray-500">
Per Sqft
</button>
</div>
<!-- Total price input (default visible) -->
<div class="relative" id="totalPriceGroup">
<span class="absolute left-3 top-3 text-gray-500 font-medium">$</span>
<input type="number" id="totalPriceInput" name="price" required min="0"
value="{{ prop.price }}"
class="w-full pl-8 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<!-- Unit price input (hidden by default) -->
<div class="relative hidden" id="unitPriceGroup">
<span class="absolute left-3 top-3 text-gray-500 font-medium">$</span>
<input type="number" id="unitPriceInput" min="0" step="0.01"
placeholder="225"
class="w-full pl-8 pr-12 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
<span class="absolute right-3 top-3 text-gray-400 text-sm">/sqft</span>
</div>
<!-- Reference total when in unit mode -->
<p class="text-xs text-gray-400 mt-1 hidden" id="priceRef">
Total: <span id="priceRefValue">$0</span>
</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Property Type *</label>
<select name="property_type" required
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
<option value="house" {% if prop.property_type == 'house' %}selected{% endif %}>House</option>
<option value="condo" {% if prop.property_type == 'condo' %}selected{% endif %}>Condo</option>
<option value="townhouse" {% if prop.property_type == 'townhouse' %}selected{% endif %}>Townhouse</option>
<option value="land" {% if prop.property_type == 'land' %}selected{% endif %}>Land</option>
</select>
</div>
</div>
<!-- Beds / Baths / Sqft -->
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Bedrooms *</label>
<input type="number" name="bedrooms" required min="0" max="20"
value="{{ prop.bedrooms }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Bathrooms *</label>
<input type="number" name="bathrooms" required min="0" max="20" step="0.5"
value="{{ prop.bathrooms }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Area (sqft) *</label>
<input type="number" id="areaSqftInput" name="area_sqft" required min="0"
value="{{ prop.area_sqft }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
</div>
<!-- Address -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Street Address *</label>
<input type="text" name="address" required
value="{{ prop.address }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<!-- City / State / Zip -->
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">City *</label>
<input type="text" name="city" required
value="{{ prop.city }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">State *</label>
<input type="text" name="state" required maxlength="2"
value="{{ prop.state }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Zip Code *</label>
<input type="text" name="zip_code" required maxlength="10"
value="{{ prop.zip_code }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
</div>
<!-- Year Built & Status -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Year Built</label>
<input type="number" name="year_built" min="1800" max="2030"
value="{{ prop.year_built or '' }}"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Status</label>
<select name="status"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
<option value="active" {% if prop.status == 'active' %}selected{% endif %}>Active</option>
<option value="pending" {% if prop.status == 'pending' %}selected{% endif %}>Pending</option>
<option value="sold" {% if prop.status == 'sold' %}selected{% endif %}>Sold</option>
</select>
</div>
</div>
<!-- Contact Info -->
<div class="border-t pt-6">
<h3 class="text-lg font-semibold text-primary mb-4">Contact Information</h3>
<p class="text-sm text-gray-500 mb-4">Provide at least one contact method (email or phone).</p>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Contact Email</label>
<input type="email" name="contact_email"
value="{{ prop.contact_email or '' }}"
placeholder="seller@example.com"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-accent outline-none transition">
</div>
<div class="relative">
{% set phone_value = prop.contact_phone or "" %}
{% include "components/phone_input.html" %}
</div>
</div>
</div>
<!-- Current Image -->
{% if primary_image %}
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">Current Image</label>
<img src="/static/{{ primary_image.image_path }}" alt="Current"
class="h-40 w-56 object-cover rounded-lg border">
</div>
{% endif %}
<!-- New Image Upload -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Replace Image</label>
<input type="file" name="image" accept="image/*"
class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-accent file:text-white hover:file:bg-blue-700 transition">
<p class="text-xs text-gray-400 mt-1">Leave empty to keep the current image.</p>
</div>
<!-- Submit -->
<div class="flex gap-4 pt-4">
<button type="submit"
class="flex-1 bg-accent hover:bg-blue-700 text-white font-semibold py-3.5 rounded-lg transition">
Save Changes
</button>
<a href="/properties/{{ prop.id }}"
class="px-8 py-3.5 border border-gray-300 text-gray-700 font-medium rounded-lg hover:bg-gray-50 transition">
Cancel
</a>
</div>
</form>
</div>
<script>
(function() {
var priceMode = 'total';
window.setPriceMode = function(mode) {
priceMode = mode;
var totalGroup = document.getElementById('totalPriceGroup');
var unitGroup = document.getElementById('unitPriceGroup');
var totalBtn = document.getElementById('priceModeTotal');
var unitBtn = document.getElementById('priceModeUnit');
var ref = document.getElementById('priceRef');
if (mode === 'total') {
totalGroup.classList.remove('hidden');
unitGroup.classList.add('hidden');
ref.classList.add('hidden');
totalBtn.classList.add('bg-white', 'shadow', 'text-primary');
totalBtn.classList.remove('text-gray-500');
unitBtn.classList.remove('bg-white', 'shadow', 'text-primary');
unitBtn.classList.add('text-gray-500');
} else {
totalGroup.classList.add('hidden');
unitGroup.classList.remove('hidden');
ref.classList.remove('hidden');
unitBtn.classList.add('bg-white', 'shadow', 'text-primary');
unitBtn.classList.remove('text-gray-500');
totalBtn.classList.remove('bg-white', 'shadow', 'text-primary');
totalBtn.classList.add('text-gray-500');
updateTotalFromUnit();
}
};
function getArea() {
return parseInt(document.getElementById('areaSqftInput').value) || 0;
}
function updateTotalFromUnit() {
var unitVal = parseFloat(document.getElementById('unitPriceInput').value) || 0;
var area = getArea();
var total = Math.round(unitVal * area);
document.getElementById('totalPriceInput').value = total || '';
document.getElementById('priceRefValue').textContent = '$' + total.toLocaleString();
}
document.getElementById('unitPriceInput').addEventListener('input', updateTotalFromUnit);
document.getElementById('areaSqftInput').addEventListener('input', function() {
if (priceMode === 'unit') updateTotalFromUnit();
});
// Initialize unit price from existing values
var priceInput = document.getElementById('totalPriceInput');
var areaInput = document.getElementById('areaSqftInput');
if (priceInput.value && areaInput.value && parseInt(areaInput.value) > 0) {
var unitPrice = parseInt(priceInput.value) / parseInt(areaInput.value);
document.getElementById('unitPriceInput').value = Math.round(unitPrice * 100) / 100;
}
// Ensure total price is synced before form submission
document.querySelector('form').addEventListener('submit', function() {
if (priceMode === 'unit') updateTotalFromUnit();
});
})();
</script>
{% endblock %}