|
119 | 119 | };
|
120 | 120 | const markAllAsRead = () => {
|
121 | 121 | const markAllAsReadLink = Routing.generate('ibexa.notifications.mark_all_as_read');
|
| 122 | + const message = Translator.trans( |
| 123 | + /* @Desc("Cannot mark all notifications as read") */ 'notifications.modal.message.error.mark_all_as_read', |
| 124 | + {}, |
| 125 | + 'ibexa_notifications', |
| 126 | + ); |
122 | 127 |
|
123 | 128 | fetch(markAllAsReadLink, { mode: 'same-origin', credentials: 'same-origin' })
|
124 | 129 | .then(getJsonFromResponse)
|
|
128 | 133 |
|
129 | 134 | allUnreadNotifications.forEach((notification) => notification.classList.add('ibexa-notifications-modal__item--read'));
|
130 | 135 | getNotificationsStatus();
|
| 136 | + } else { |
| 137 | + showErrorNotification(message); |
131 | 138 | }
|
132 | 139 | })
|
133 | 140 | .catch(() => {
|
134 |
| - const message = Translator.trans( |
135 |
| - /* @Desc("Cannot mark all notifications as read") */ 'notifications.modal.message.error.mark_all_as_read', |
136 |
| - {}, |
137 |
| - 'ibexa_notifications', |
138 |
| - ); |
139 |
| - |
140 | 141 | showErrorNotification(message);
|
141 | 142 | });
|
142 | 143 | };
|
143 | 144 | const markAsRead = ({ currentTarget }) => {
|
144 | 145 | const { notificationId } = currentTarget.dataset;
|
145 | 146 | const markAsReadLink = Routing.generate('ibexa.notifications.mark_as_read', { notificationId });
|
| 147 | + const message = Translator.trans( |
| 148 | + /* @Desc("Cannot mark notification as read") */ 'notifications.modal.message.error.mark_as_read', |
| 149 | + {}, |
| 150 | + 'ibexa_notifications', |
| 151 | + ); |
146 | 152 |
|
147 | 153 | fetch(markAsReadLink, { mode: 'same-origin', credentials: 'same-origin' })
|
148 | 154 | .then(getJsonFromResponse)
|
|
155 | 161 | menuInstance.closeMenu();
|
156 | 162 | notification.classList.add('ibexa-notifications-modal__item--read');
|
157 | 163 | getNotificationsStatus();
|
| 164 | + } else { |
| 165 | + showErrorNotification(message); |
158 | 166 | }
|
159 | 167 | })
|
160 | 168 | .catch(() => {
|
161 |
| - const message = Translator.trans( |
162 |
| - /* @Desc("Cannot mark notification as read") */ 'notifications.modal.message.error.mark_as_read', |
163 |
| - {}, |
164 |
| - 'ibexa_notifications', |
165 |
| - ); |
166 |
| - |
167 | 169 | showErrorNotification(message);
|
168 | 170 | });
|
169 | 171 | };
|
170 | 172 | const markAsUnread = ({ currentTarget }) => {
|
171 | 173 | const { notificationId } = currentTarget.dataset;
|
172 | 174 | const markAsUnreadLink = Routing.generate('ibexa.notifications.mark_as_unread', { notificationId });
|
| 175 | + const message = Translator.trans( |
| 176 | + /* @Desc("Cannot mark notification as unread") */ 'notifications.modal.message.error.mark_as_unread', |
| 177 | + {}, |
| 178 | + 'ibexa_notifications', |
| 179 | + ); |
173 | 180 |
|
174 | 181 | fetch(markAsUnreadLink, { mode: 'same-origin', credentials: 'same-origin' })
|
175 | 182 | .then(getJsonFromResponse)
|
|
182 | 189 | menuInstance.closeMenu();
|
183 | 190 | notification.classList.remove('ibexa-notifications-modal__item--read');
|
184 | 191 | getNotificationsStatus();
|
| 192 | + } else { |
| 193 | + showErrorNotification(message); |
185 | 194 | }
|
186 | 195 | })
|
187 | 196 | .catch(() => {
|
188 |
| - const message = Translator.trans( |
189 |
| - /* @Desc("Cannot mark notification as unread") */ 'notifications.modal.message.error.mark_as_unread', |
190 |
| - {}, |
191 |
| - 'ibexa_notifications', |
192 |
| - ); |
193 |
| - |
194 | 197 | showErrorNotification(message);
|
195 | 198 | });
|
196 | 199 | };
|
197 | 200 | const deleteNotification = ({ currentTarget }) => {
|
198 | 201 | const { notificationId } = currentTarget.dataset;
|
199 | 202 | const deleteLink = Routing.generate('ibexa.notifications.delete', { notificationId });
|
| 203 | + const message = Translator.trans( |
| 204 | + /* @Desc("Cannot delete notification") */ 'notifications.modal.message.error.delete', |
| 205 | + {}, |
| 206 | + 'ibexa_notifications', |
| 207 | + ); |
200 | 208 |
|
201 | 209 | fetch(deleteLink, { mode: 'same-origin', credentials: 'same-origin' })
|
202 | 210 | .then(getJsonFromResponse)
|
|
208 | 216 |
|
209 | 217 | menuInstance.closeMenu();
|
210 | 218 | notification.remove();
|
| 219 | + } else { |
| 220 | + showErrorNotification(message); |
211 | 221 | }
|
212 | 222 | })
|
213 | 223 | .catch(() => {
|
214 |
| - const message = Translator.trans( |
215 |
| - /* @Desc("Cannot delete notification") */ 'notifications.modal.message.error.delete', |
216 |
| - {}, |
217 |
| - 'ibexa_notifications', |
218 |
| - ); |
219 |
| - |
220 | 224 | showErrorNotification(message);
|
221 | 225 | });
|
222 | 226 | };
|
|
0 commit comments