Skip to content

Commit

Permalink
Fix automatic slug update on sbs form
Browse files Browse the repository at this point in the history
  • Loading branch information
lunars97 authored and JoeyStk committed Aug 9, 2024
1 parent ad8c5e8 commit 4c34720
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
5 changes: 3 additions & 2 deletions integreat_cms/cms/templates/pages/page_sbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ <h1 class="heading">
</label>
{% translate "Not saved yet" %}
{% endif %}
<label for="{{ page_translation_form.slug.id_for_label }}">
<label for="{{ page_translation_form.slug.id_for_label }}"
data-slugify-url="{% url 'slugify_ajax' region_slug=request.region.slug language_slug=target_language.slug model_type='page' %}{% if page_translation_form.instance.id %}?data-model-id={{ page_translation_form.instance.id }}{% endif %}">
{{ page_translation_form.slug.label }}
</label>
<div class="slug-field">
Expand All @@ -183,7 +184,7 @@ <h1 class="heading">
<label for="{{ page_translation_form.title.id_for_label }}">
{{ page_translation_form.title.label }}
</label>
{% render_field page_translation_form.title|add_error_class:"border-red-500" id="target_translation_title" %}
{% render_field page_translation_form.title|add_error_class:"border-red-500" %}
<label for="{{ page_translation_form.content.id_for_label }}">
{{ page_translation_form.content.label }}
</label>
Expand Down
2 changes: 2 additions & 0 deletions integreat_cms/release_notes/current/unreleased/2797.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en: Fix automatic url update after changing a title of the page on side by side view
de: Behebe einen Fehler bei der automatischen Aktualisierung der Seiten-URL nach Änderung des Seitentitels in der Seitenansicht
30 changes: 16 additions & 14 deletions integreat_cms/static/src/js/forms/update-permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,25 @@ window.addEventListener("load", () => {
.setAttribute("data-copy-to-clipboard", encodeURI(updatedLink.concat(currentSlug)));
};

if (
document.getElementById("id_title") &&
(document.querySelector('[for="id_title"]') as HTMLElement)?.dataset?.slugifyUrl
) {
document.getElementById("id_title").addEventListener("focusout", ({ target }) => {
document.querySelectorAll("#id_title").forEach((item) => {
item.addEventListener("focusout", ({ target }) => {
const submissionLock = new SubmissionPrevention(".no-premature-submission");
const currentTitle = (target as HTMLInputElement).value;
const dataset = (document.querySelector('[for="id_title"]') as HTMLElement).dataset;
slugify(dataset.slugifyUrl, { title: currentTitle, model_id: dataset.modelId })
.then((response) => {
/* on success write response to both slug field and permalink */
slugField.value = response.unique_slug;
updatePermalink(response.unique_slug);
})
.finally(() => submissionLock.release());
const nodeList: NodeListOf<HTMLInputElement> = document.querySelectorAll(
'[for="id_title"],[for="id_slug"]'
);
for (const node of nodeList) {
const datasetItem = node.dataset;
slugify(datasetItem.slugifyUrl, { title: currentTitle, model_id: datasetItem.modelId })
.then((response) => {
/* on success write response to both slug field and permalink */
slugField.value = response.unique_slug;
updatePermalink(response.unique_slug);
})
.finally(() => submissionLock.release());
}
});
}
});

const toggleSlugMode = () => {
// Toggle all permalink buttons (and the rendered link)
Expand Down

0 comments on commit 4c34720

Please sign in to comment.