|
| 1 | +{% extends get_active_back_theme()+'/base.html' %} |
| 2 | + |
| 3 | +{% block content %} |
| 4 | +<div class="container-xxl flex-grow-1 container-p-y"> |
| 5 | + <h4 class="fw-bold py-3 mb-4"> |
| 6 | + <span class="text-muted fw-light">Content / {{ content_type.name }} /</span> |
| 7 | + {% if item %}Edit{% else %}Add{% endif %} Item |
| 8 | + </h4> |
| 9 | + |
| 10 | + <div class="row"> |
| 11 | + <div class="col-xl"> |
| 12 | + <div class="card mb-4"> |
| 13 | + <div class="card-header d-flex justify-content-between align-items-center"> |
| 14 | + <h5 class="mb-0">{% if item %}Edit{% else %}New{% endif %} {{ content_type.name }}</h5> |
| 15 | + </div> |
| 16 | + <div class="card-body"> |
| 17 | + <form method="POST"> |
| 18 | + <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> |
| 19 | + |
| 20 | + {% for field in content_type.schema %} |
| 21 | + <div class="mb-3"> |
| 22 | + <label class="form-label" for="{{ field.name }}">{{ field.name|capitalize }}</label> |
| 23 | + |
| 24 | + {% if field.type == 'text' %} |
| 25 | + <input type="text" class="form-control" id="{{ field.name }}" name="{{ field.name }}" |
| 26 | + value="{{ item.data.get(field.name, '') if item else '' }}" required /> |
| 27 | + |
| 28 | + {% elif field.type == 'textarea' %} |
| 29 | + <textarea id="{{ field.name }}" name="{{ field.name }}" class="form-control" rows="5" required>{{ item.data.get(field.name, '') if item else '' }}</textarea> |
| 30 | + |
| 31 | + {% elif field.type == 'richtext' %} |
| 32 | + <textarea id="{{ field.name }}" name="{{ field.name }}" class="form-control richtext" rows="10">{{ item.data.get(field.name, '') if item else '' }}</textarea> |
| 33 | + |
| 34 | + {% elif field.type == 'image' %} |
| 35 | + <div class="input-group"> |
| 36 | + <span class="input-group-text"><i class="bx bx-image"></i></span> |
| 37 | + <input type="text" class="form-control image-input" id="{{ field.name }}" name="{{ field.name }}" |
| 38 | + placeholder="https://..." value="{{ item.data.get(field.name, '') if item else '' }}" /> |
| 39 | + </div> |
| 40 | + <div class="mt-2 image-preview-container" id="preview-{{ field.name }}"> |
| 41 | + {% if item and item.data.get(field.name) %} |
| 42 | + <img src="{{ item.data.get(field.name) }}" class="img-thumbnail" style="max-height: 200px;"> |
| 43 | + {% endif %} |
| 44 | + </div> |
| 45 | + |
| 46 | + {% elif field.type == 'number' %} |
| 47 | + <input type="number" class="form-control" id="{{ field.name }}" name="{{ field.name }}" |
| 48 | + value="{{ item.data.get(field.name, '') if item else '' }}" required /> |
| 49 | + |
| 50 | + {% elif field.type == 'date' %} |
| 51 | + <input type="date" class="form-control" id="{{ field.name }}" name="{{ field.name }}" |
| 52 | + value="{{ item.data.get(field.name, '') if item else '' }}" required /> |
| 53 | + {% endif %} |
| 54 | + </div> |
| 55 | + {% endfor %} |
| 56 | + |
| 57 | + <div class="mt-4"> |
| 58 | + <button type="submit" class="btn btn-primary">Save Item</button> |
| 59 | + <a href="{{ url_for('contenttype.items', type_id=content_type.id) }}" class="btn btn-outline-secondary">Cancel</a> |
| 60 | + </div> |
| 61 | + </form> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | +</div> |
| 67 | + |
| 68 | +<script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script> |
| 69 | +<script> |
| 70 | + tinymce.init({ |
| 71 | + selector: '.richtext', |
| 72 | + plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount', |
| 73 | + toolbar: 'undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat', |
| 74 | + height: 500 |
| 75 | + }); |
| 76 | + |
| 77 | + // Simple Image Preview |
| 78 | + document.querySelectorAll('.image-input').forEach(input => { |
| 79 | + input.addEventListener('input', function() { |
| 80 | + const previewId = 'preview-' + this.id; |
| 81 | + const container = document.getElementById(previewId); |
| 82 | + if (this.value) { |
| 83 | + container.innerHTML = `<img src="${this.value}" class="img-thumbnail" style="max-height: 200px;" onerror="this.style.display='none'">`; |
| 84 | + } else { |
| 85 | + container.innerHTML = ''; |
| 86 | + } |
| 87 | + }); |
| 88 | + }); |
| 89 | +</script> |
| 90 | +{% endblock %} |
0 commit comments