|
| 1 | +import { controlZIndex } from './helpers/modal.helper'; |
| 2 | + |
1 | 3 | (function (global, doc, ibexa, Translator, Routing) { |
2 | 4 | let currentPageLink = null; |
3 | 5 | let getNotificationsStatusErrorShowed = false; |
4 | 6 | let lastFailedCountFetchNotificationNode = null; |
| 7 | + let selectedNotificationId = null; |
5 | 8 | const SELECTOR_MODAL_ITEM = '.ibexa-notifications-modal__item'; |
6 | 9 | const SELECTOR_MODAL_RESULTS = '.ibexa-notifications-modal__results .ibexa-scrollable-wrapper'; |
7 | 10 | const SELECTOR_MODAL_TITLE = '.ibexa-side-panel__header'; |
|
214 | 217 |
|
215 | 218 | currentTarget.textContent.trim() === markAsReadLabel ? markAsRead({ currentTarget }) : markAsUnread({ currentTarget }); |
216 | 219 | }; |
217 | | - const deleteNotification = ({ currentTarget }) => { |
218 | | - const { notificationId } = currentTarget.dataset; |
219 | | - const deleteLink = Routing.generate('ibexa.notifications.delete', { notificationId }); |
| 220 | + const deleteNotification = () => { |
| 221 | + const deleteLink = Routing.generate('ibexa.notifications.delete', { notificationId: selectedNotificationId }); |
220 | 222 | const message = Translator.trans( |
221 | 223 | /* @Desc("Cannot delete notification") */ 'notifications.modal.message.error.delete', |
222 | 224 | {}, |
|
227 | 229 | .then(getJsonFromResponse) |
228 | 230 | .then((response) => { |
229 | 231 | if (response.status === 'success') { |
230 | | - const notification = doc.querySelector(`.ibexa-notifications-modal__item[data-notification-id="${notificationId}"]`); |
231 | | - const menuBranch = currentTarget.closest('.ibexa-multilevel-popup-menu__branch'); |
232 | | - const menuInstance = ibexa.helpers.objectInstances.getInstance(menuBranch.menuInstanceElement); |
| 232 | + const notification = doc.querySelector( |
| 233 | + `.ibexa-notifications-modal__item[data-notification-id="${selectedNotificationId}"]`, |
| 234 | + ); |
233 | 235 |
|
234 | | - menuInstance.closeMenu(); |
235 | 236 | notification.remove(); |
236 | 237 | getNotificationsStatus(); |
237 | 238 | } else { |
|
245 | 246 | const attachActionsListeners = () => { |
246 | 247 | const attachListener = (node, callback) => node.addEventListener('click', callback, false); |
247 | 248 | const markAsButtons = doc.querySelectorAll('.ibexa-notifications-modal--mark-as'); |
248 | | - const deleteButtons = doc.querySelectorAll('.ibexa-notifications-modal--delete'); |
| 249 | + const deleteButtons = doc.querySelectorAll('.ibexa-notifications-open-modal-button'); |
| 250 | + const confirmDeleteButton = doc.querySelector('.ibexa-notifications-modal--delete--confirm'); |
| 251 | + const setNotificationId = ({ currentTarget }) => { |
| 252 | + const deleteModal = doc.querySelector('.modal-backdrop.show.fade'); |
| 253 | + controlZIndex(deleteModal, '199'); |
| 254 | + |
| 255 | + selectedNotificationId = currentTarget.dataset.notificationId; |
| 256 | + }; |
249 | 257 |
|
250 | 258 | markAsButtons.forEach((markAsButton) => { |
251 | 259 | attachListener(markAsButton, handleMarkAsAction); |
252 | 260 | }); |
253 | 261 |
|
254 | 262 | deleteButtons.forEach((deleteButton) => { |
255 | | - attachListener(deleteButton, deleteNotification); |
| 263 | + attachListener(deleteButton, setNotificationId); |
256 | 264 | }); |
| 265 | + |
| 266 | + if (confirmDeleteButton) { |
| 267 | + confirmDeleteButton.addEventListener('click', deleteNotification); |
| 268 | + } |
257 | 269 | }; |
258 | 270 | const showNotificationPage = (pageHtml) => { |
259 | 271 | const modalResults = panel.querySelector(SELECTOR_MODAL_RESULTS); |
|
0 commit comments