168 lines
4.9 KiB
HTML
168 lines
4.9 KiB
HTML
Absolutely—here’s a complete entry_edit.html that matches your current edit layout and adds the same “auto‑fill Talk Title from Talk Number” behavior you have on the new‑entry form. I also added a tiny convenience so if the title field contains just - or —, it’s treated as empty and will auto‑fill.
|
||
|
||
{% extends "base.html" %}
|
||
{% block body_class %}themed-bg{% endblock %}
|
||
{% load static %}
|
||
|
||
{% block content %}
|
||
<div class="page">
|
||
<!-- Top bar -->
|
||
<div class="result-toolbar">
|
||
<div class="rt-left">
|
||
<a class="btn btn-secondary" href="{% url 'entry_view' entry.id %}">← Back to Entry</a>
|
||
<span class="rt-count">Editing: #{{ entry.id }}</span>
|
||
</div>
|
||
<div class="rt-right">
|
||
<a class="btn" href="{% url 'entry_view' entry.id %}">Cancel</a>
|
||
<button form="entry-edit-form" class="btn btn-primary">Save</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Card -->
|
||
<div class="card entry-form modern-form">
|
||
<form id="entry-edit-form" method="post">
|
||
{% csrf_token %}
|
||
|
||
<div class="f-grid">
|
||
<div class="f-row">
|
||
<div class="f-label">Subject</div>
|
||
<div class="f-control">
|
||
{{ form.subject }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row tall">
|
||
<div class="f-label">Illustration</div>
|
||
<div class="f-control">
|
||
{{ form.illustration }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row tall">
|
||
<div class="f-label">Application</div>
|
||
<div class="f-control">
|
||
{{ form.application }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row">
|
||
<div class="f-label">Scripture</div>
|
||
<div class="f-control">
|
||
{{ form.scripture_raw }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row">
|
||
<div class="f-label">Source</div>
|
||
<div class="f-control">
|
||
{{ form.source }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row">
|
||
<div class="f-label">Talk Title</div>
|
||
<div class="f-control">
|
||
{{ form.talk_title }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row">
|
||
<div class="f-label">Talk Number</div>
|
||
<div class="f-control">
|
||
{{ form.talk_number }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row">
|
||
<div class="f-label">Entry Code</div>
|
||
<div class="f-control">
|
||
{{ form.entry_code }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row">
|
||
<div class="f-label">Date Added</div>
|
||
<div class="f-control">
|
||
{{ form.date_added }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="f-row">
|
||
<div class="f-label">Date Edited</div>
|
||
<div class="f-control">
|
||
{{ form.date_edited }}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- bottom actions (hidden by CSS if you prefer only the top bar) -->
|
||
<div class="form-actions bottom-actions">
|
||
<a class="btn btn-secondary" href="{% url 'entry_view' entry.id %}">Cancel</a>
|
||
<button class="btn btn-primary">Save</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Talk title auto-fill (same behavior as entry_add) -->
|
||
<script>
|
||
(function () {
|
||
// Location of your mapping file
|
||
const talksUrl = "{% static 'talks.json' %}";
|
||
|
||
function wireAutofill(talkMap) {
|
||
const numberEl = document.getElementById("id_talk_number");
|
||
const titleEl = document.getElementById("id_talk_title");
|
||
if (!numberEl || !titleEl) return;
|
||
|
||
// Consider "-" or "—" as empty (lets autofill replace them)
|
||
const isEffectivelyEmpty = (s) => {
|
||
const t = (s || "").trim();
|
||
return t === "" || t === "-" || t === "—";
|
||
};
|
||
|
||
// Track if user has typed something custom
|
||
let userTyped = false;
|
||
|
||
titleEl.addEventListener("input", () => {
|
||
userTyped = !isEffectivelyEmpty(titleEl.value);
|
||
if (!userTyped) titleEl.dataset.autofilled = "0";
|
||
});
|
||
|
||
function maybeAutofill() {
|
||
const n = numberEl.value;
|
||
const mapped = talkMap && talkMap[n] ? talkMap[n] : "";
|
||
|
||
if (!userTyped) {
|
||
if (mapped) {
|
||
titleEl.value = mapped;
|
||
titleEl.dataset.autofilled = "1";
|
||
} else if (titleEl.dataset.autofilled === "1") {
|
||
// Previously autofilled but new number has no title: clear it
|
||
titleEl.value = "";
|
||
titleEl.dataset.autofilled = "0";
|
||
}
|
||
}
|
||
}
|
||
|
||
// Change -> try to fill
|
||
numberEl.addEventListener("change", maybeAutofill);
|
||
|
||
// Initial fill on page load:
|
||
// If current title is empty/hyphen, allow autofill; otherwise respect user text
|
||
if (isEffectivelyEmpty(titleEl.value)) {
|
||
userTyped = false;
|
||
maybeAutofill();
|
||
} else {
|
||
userTyped = true;
|
||
}
|
||
}
|
||
|
||
// Fetch the mapping; if it fails, no worries—form still works
|
||
fetch(talksUrl, {cache: "no-store"})
|
||
.then(r => r.ok ? r.json() : {})
|
||
.then(map => wireAutofill(map))
|
||
.catch(() => wireAutofill({}));
|
||
})();
|
||
</script>
|
||
{% endblock %} |