Files
KCAPDemoServer/src/templates/admin/edit_product.html

125 lines
6.6 KiB
HTML
Raw Normal View History

2025-05-08 20:49:15 -04:00
{% extends "layout.html" %}
{% block title %}Edit Product - KCAP Demo Server{% endblock %}
{% block content %}
<div class="row mt-4">
<div class="col-md-8 offset-md-2">
<div class="card">
<div class="card-header">
<h2>Edit Product</h2>
</div>
<div class="card-body">
2025-06-19 14:25:42 -04:00
<form action="{{ url_for('admin.edit_product', tenant_id=tenant_id, product_id=product_id) }}" method="POST" enctype="multipart/form-data">
2025-05-08 20:49:15 -04:00
<div class="mb-3">
<label for="product_id" class="form-label">Product ID</label>
<input type="text" class="form-control" id="product_id" value="{{ product_id }}" disabled>
<div class="form-text">Product ID cannot be changed.</div>
</div>
{% for field in custom_fields %}
{% if field.fieldName != '_id' %}
<div class="mb-3">
<label for="field_{{ field.fieldName }}" class="form-label">{{ field.label }}</label>
{% set current_value = '' %}
{% for prod_field in product %}
{% if prod_field.fieldName == field.fieldName %}
{% set current_value = prod_field.value %}
2025-05-08 20:49:15 -04:00
{% endif %}
{% endfor %}
{% if field.fieldType == 'IMAGE_URI' %}
<input type="file" class="form-control" id="image_{{ field.fieldName }}" name="image_{{ field.fieldName }}" accept="image/*" onchange="previewImage(this, 'preview_new_{{ field.fieldName }}')">
<div class="form-text">Leave empty to keep the current image.</div>
{% if current_value %}
<div class="mt-3">
<label class="form-label">Current Image:</label>
2025-05-08 20:49:15 -04:00
<div>
<img src="{{ current_value }}" alt="Current image" class="image-preview" style="max-width: 200px;">
2025-05-08 20:49:15 -04:00
</div>
</div>
2025-05-08 20:49:15 -04:00
{% endif %}
<div class="mt-2">
<label class="form-label">New Image Preview:</label>
<img id="preview_new_{{ field.fieldName }}" class="image-preview" style="display: none; max-width: 200px;">
</div>
{% elif field.fieldType == 'TEXT' %}
{% if field.fieldName == '_price' %}
<div class="input-group">
<span class="input-group-text">$</span>
{% set price_value = current_value|replace('$', '') %}
<input type="text" class="form-control" id="field_{{ field.fieldName }}" name="field_{{ field.fieldName }}"
pattern="[0-9]+(\.[0-9]{1,2})?" value="{{ price_value }}" placeholder="49.99">
</div>
{% else %}
<input type="text" class="form-control" id="field_{{ field.fieldName }}" name="field_{{ field.fieldName }}" value="{{ current_value }}">
{% endif %}
{% else %}
<input type="text" class="form-control" id="field_{{ field.fieldName }}" name="field_{{ field.fieldName }}" value="{{ current_value }}">
{% endif %}
2025-05-08 20:49:15 -04:00
</div>
{% endif %}
{% endfor %}
<!-- Fallback fields for backward compatibility -->
{% if not custom_fields|selectattr('fieldName', 'equalto', '_name')|list %}
{% for field in product %}
{% if field.fieldName == '_name' %}
<div class="mb-3">
<label for="name" class="form-label">Product Name</label>
<input type="text" class="form-control" id="name" name="name" value="{{ field.value }}">
</div>
{% endif %}
{% endfor %}
{% endif %}
{% if not custom_fields|selectattr('fieldName', 'equalto', '_price')|list %}
{% for field in product %}
{% if field.fieldName == '_price' %}
<div class="mb-3">
<label for="price" class="form-label">Price</label>
<div class="input-group">
<span class="input-group-text">$</span>
{% set price_value = field.value|replace('$', '') %}
<input type="text" class="form-control" id="price" name="price"
pattern="[0-9]+(\.[0-9]{1,2})?" value="{{ price_value }}" placeholder="49.99">
</div>
</div>
{% endif %}
{% endfor %}
{% endif %}
2025-05-08 20:49:15 -04:00
<div class="d-flex justify-content-between">
2025-06-19 14:25:42 -04:00
<a href="{{ url_for('admin.index', tenant_id=tenant_id) }}" class="btn btn-secondary">Cancel</a>
2025-05-08 20:49:15 -04:00
<button type="submit" class="btn btn-primary">Update Product</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
function previewImage(input, previewId) {
var preview = document.getElementById(previewId || 'image-preview');
2025-05-08 20:49:15 -04:00
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
preview.src = e.target.result;
preview.style.display = 'block';
}
reader.readAsDataURL(input.files[0]);
} else {
preview.style.display = 'none';
}
}
</script>
{% endblock %}