Skip to content

Commit a462b4b

Browse files
committed
toast for ordering and deleting elements
1 parent b755ef9 commit a462b4b

File tree

6 files changed

+47
-24
lines changed

6 files changed

+47
-24
lines changed

src/cs_dynamicpages/browser/static/delete-row.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
if (modal) {
115115
modal.hide();
116116
}
117+
sessionStorage.setItem('toast-message', 'Element deleted successfully.');
117118
// Refresh the page after successful update
118119
window.location.reload();
119120
});

src/cs_dynamicpages/browser/static/reorder-rows.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,14 @@
1818
!document.body.classList.contains("template-dynamic-view") ||
1919
!document.body.classList.contains("userrole-manager")
2020
) {
21-
console.log(
22-
"Not in dynamic-view edit mode, skipping row reordering initialization"
23-
);
2421
return;
2522
}
2623

27-
console.log("Initializing row reordering...");
2824
// Find all move up/down buttons
2925
const moveUpButtons = document.querySelectorAll('a[data-action="move-up"]');
3026
const moveDownButtons = document.querySelectorAll(
3127
'a[data-action="move-down"]'
3228
);
33-
console.log(
34-
`Found ${moveUpButtons.length} move-up buttons and ${moveDownButtons.length} move-down buttons`
35-
);
3629

3730
// Add event listeners to move up buttons
3831
moveUpButtons.forEach((button) => {
@@ -46,11 +39,7 @@
4639
if (this.disabled) return;
4740
this.disabled = true;
4841

49-
console.log("Move up button clicked");
5042
const element = this.closest('[data-move-target="true"]');
51-
console.log(
52-
`Moving element with ID: ${element.dataset.elementid} up`
53-
);
5443

5544
// Re-habilitar el botón después de un tiempo
5645
setTimeout(() => {
@@ -75,11 +64,7 @@
7564
if (this.disabled) return;
7665
this.disabled = true;
7766

78-
console.log("Move down button clicked");
7967
const element = this.closest('[data-move-target="true"]');
80-
console.log(
81-
`Moving element with ID: ${element.dataset.elementid} down`
82-
);
8368

8469
// Re-habilitar el botón después de un tiempo
8570
setTimeout(() => {
@@ -97,15 +82,12 @@
9782
const elementId = element.dataset.elementid;
9883
if (!elementId) {
9984
const errorMsg = "No data-element-id attribute found on element";
100-
console.error(errorMsg);
10185
alert(errorMsg);
10286
return;
10387
}
10488

105-
console.log(`Preparing to move element ${elementId} with delta ${delta}`);
10689

10790
const baseUrl = element.dataset.parenturl || "";
108-
console.log(`Sending request to: ${baseUrl}`);
10991

11092
const requestBody = {
11193
ordering: {
@@ -114,7 +96,6 @@
11496
},
11597
};
11698

117-
console.log("Request payload:", JSON.stringify(requestBody, null, 2));
11899

119100
fetch(baseUrl, {
120101
method: "PATCH",
@@ -127,16 +108,13 @@
127108
credentials: "same-origin",
128109
})
129110
.then((response) => {
130-
console.log(`Received response with status: ${response.status}`);
131-
console.log("Response headers:", response.headers);
132-
console.log("Response ok:", response.ok);
133111
if (!response.ok) {
134112
const error = new Error(`HTTP error! status: ${response.status}`);
135-
console.error("Response not OK:", error);
136113
throw error;
137114
}
138115
})
139116
.finally(() => {
117+
sessionStorage.setItem('toast-message', 'Element reordered successfully.');
140118
// Refresh the page after successful update
141119
window.location.reload();
142120
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(function () {
2+
"use strict";
3+
4+
document.addEventListener("DOMContentLoaded", function () {
5+
const toastMessage = sessionStorage.getItem("toast-message");
6+
7+
if (toastMessage) {
8+
const toastLiveExample = document.getElementById("liveToast");
9+
if (toastLiveExample) {
10+
const toastBody = toastLiveExample.querySelector(".toast-body");
11+
if (toastBody) {
12+
toastBody.textContent = toastMessage;
13+
}
14+
15+
const toast = new bootstrap.Toast(toastLiveExample);
16+
toast.show();
17+
}
18+
19+
// Clear the message from session storage
20+
sessionStorage.removeItem("toast-message");
21+
}
22+
});
23+
})();

src/cs_dynamicpages/profiles/default/registry/dynamic_bundle.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
<value key="expression" />
3636
</records>
3737

38+
<records interface="Products.CMFPlone.interfaces.IBundleRegistry"
39+
prefix="plone.bundles/cs_dynamicpages.toast_handler"
40+
>
41+
<value key="enabled">True</value>
42+
<value key="jscompilation">++plone++cs_dynamicpages.edit/toast-handler.js</value>
43+
<value key="depends">plone</value>
44+
<value key="load_async">True</value>
45+
<value key="load_defer">False</value>
46+
<value key="expression" />
47+
</records>
48+
3849
<records interface="Products.CMFPlone.interfaces.IBundleRegistry"
3950
prefix="plone.bundles/cs_dynamicpages.editmode_toggle"
4051
>

src/cs_dynamicpages/views/dynamic_page_folder_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __call__(self):
4343
type="DynamicPageRow",
4444
container=self.context,
4545
row_type=row_type,
46-
title="New Row",
46+
title=row_type,
4747
description="Here goes the description",
4848
id=str(random_id),
4949
link_text="Link Text",

src/cs_dynamicpages/views/dynamic_view.pt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
<body>
1414
<metal:main fill-slot="main">
1515
<main id="content">
16+
<div class="toast-container position-fixed bottom-0 end-0 p-3">
17+
<div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
18+
<div class="toast-header">
19+
<strong class="me-auto">Notification</strong>
20+
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
21+
</div>
22+
<div class="toast-body">
23+
</div>
24+
</div>
25+
</div>
1626
<tal:condition-configuration condition="view/dynamic_page_folder_element">
1727
<div class="sticky-top right-0 d-flex justify-content-end py-2 me-2"
1828
tal:condition="view/can_edit"

0 commit comments

Comments
 (0)