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-10-20 17:11:26 -04:00
|
|
|
<form action="/{{ tenant_id }}/edit/{{ 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>
|
|
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
{% for field in custom_fields %}
|
|
|
|
|
{% if field.fieldName != '_id' %}
|
|
|
|
|
<div class="mb-3">
|
|
|
|
|
<label for="field_{{ field.fieldName }}" class="form-label">{{ field.label }}</label>
|
2025-10-20 17:11:26 -04:00
|
|
|
|
|
|
|
|
{# Find current value using selectattr filter #}
|
|
|
|
|
{% set matching_fields = product|selectattr('fieldName', 'equalto', field.fieldName)|list %}
|
|
|
|
|
{% set current_value = matching_fields[0].value if matching_fields else '' %}
|
|
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
{% 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>
|
2025-06-19 15:46:22 -04:00
|
|
|
<img src="{{ current_value }}" alt="Current image" class="image-preview" style="max-width: 200px;">
|
2025-05-08 20:49:15 -04:00
|
|
|
</div>
|
2025-06-19 15:46:22 -04:00
|
|
|
</div>
|
2025-05-08 20:49:15 -04:00
|
|
|
{% endif %}
|
2025-06-19 15:46:22 -04:00
|
|
|
|
|
|
|
|
<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>
|
2025-06-19 15:46:22 -04:00
|
|
|
{% 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-10-20 17:11:26 -04:00
|
|
|
<a href="/{{ 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>
|
2025-06-19 15:46:22 -04:00
|
|
|
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>
|
2025-06-19 15:46:22 -04:00
|
|
|
{% endblock %}
|