Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix automatic slug update on sbs form #2842

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading