Skip to content

Commit 7093bc6

Browse files
committed
Merge branch '4.1' into 'main'
2 parents 3f388a4 + 32a4b6d commit 7093bc6

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

phpmyfaq/admin/assets/src/content/glossary.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import { createGlossary, deleteGlossary, getGlossary, updateGlossary } from '../api';
1717
import { addElement, pushNotification } from '../../../../assets/src/utils';
18+
import bootstrap, { Modal } from 'bootstrap';
1819

1920
export const handleDeleteGlossary = (): void => {
2021
const deleteButtons: NodeListOf<HTMLButtonElement> = document.querySelectorAll('.pmf-admin-delete-glossary');
@@ -42,7 +43,6 @@ export const handleDeleteGlossary = (): void => {
4243
export const handleAddGlossary = (): void => {
4344
const saveGlossaryButton = document.getElementById('pmf-admin-glossary-add') as HTMLButtonElement | null;
4445
const modal = document.getElementById('addGlossaryModal') as HTMLElement | null;
45-
const modalBackdrop: HTMLCollectionOf<Element> = document.getElementsByClassName('modal-backdrop fade show');
4646

4747
if (saveGlossaryButton) {
4848
saveGlossaryButton.addEventListener('click', async (event: Event) => {
@@ -57,11 +57,13 @@ export const handleAddGlossary = (): void => {
5757

5858
if (response) {
5959
if (modal) {
60-
modal.style.display = 'none';
61-
modal.classList.remove('show');
62-
}
63-
if (modalBackdrop[0]) {
64-
modalBackdrop[0].parentNode?.removeChild(modalBackdrop[0]);
60+
// Close modal properly using Bootstrap
61+
const bootstrapModal = bootstrap.Modal.getInstance(modal) as Modal;
62+
bootstrapModal.hide();
63+
64+
// Reset form fields for the next entry
65+
(document.getElementById('item') as HTMLInputElement).value = '';
66+
(document.getElementById('definition') as HTMLInputElement).value = '';
6567
}
6668

6769
const tableBody = document.querySelector('#pmf-admin-glossary-table tbody') as HTMLElement;
@@ -130,7 +132,6 @@ export const onOpenUpdateGlossaryModal = (): void => {
130132
export const handleUpdateGlossary = (): void => {
131133
const updateGlossaryButton = document.getElementById('pmf-admin-glossary-update') as HTMLButtonElement | null;
132134
const modal = document.getElementById('updateGlossaryModal') as HTMLElement | null;
133-
const modalBackdrop: HTMLCollectionOf<Element> = document.getElementsByClassName('modal-backdrop fade show');
134135

135136
if (updateGlossaryButton) {
136137
updateGlossaryButton.addEventListener('click', async (event: Event): Promise<void> => {
@@ -146,11 +147,9 @@ export const handleUpdateGlossary = (): void => {
146147

147148
if (response) {
148149
if (modal) {
149-
modal.style.display = 'none';
150-
modal.classList.remove('show');
151-
}
152-
if (modalBackdrop[0]) {
153-
modalBackdrop[0].parentNode?.removeChild(modalBackdrop[0]);
150+
// Close modal properly using Bootstrap
151+
const bootstrapModal = bootstrap.Modal.getInstance(modal) as Modal;
152+
bootstrapModal.hide();
154153
}
155154

156155
const itemLink = document.querySelector(

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/GlossaryController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public function create(Request $request): JsonResponse
9090
$data = json_decode($request->getContent());
9191

9292
$glossaryLanguage = Filter::filterVar($data->language, FILTER_SANITIZE_SPECIAL_CHARS);
93-
$glossaryItem = Filter::filterVar($data->item, FILTER_SANITIZE_SPECIAL_CHARS);
94-
$glossaryDefinition = Filter::filterVar($data->definition, FILTER_SANITIZE_SPECIAL_CHARS);
93+
$glossaryItem = $data->item;
94+
$glossaryDefinition = $data->definition;
9595

9696
if (!Token::getInstance($this->session)->verifyToken('add-glossary', $data->csrf)) {
9797
return $this->json(['error' => Translation::get(key: 'msgNoPermission')], Response::HTTP_UNAUTHORIZED);
@@ -119,8 +119,8 @@ public function update(Request $request): JsonResponse
119119

120120
$glossaryId = Filter::filterVar($data->id, FILTER_VALIDATE_INT);
121121
$glossaryLanguage = Filter::filterVar($data->lang, FILTER_SANITIZE_SPECIAL_CHARS);
122-
$glossaryItem = Filter::filterVar($data->item, FILTER_SANITIZE_SPECIAL_CHARS);
123-
$glossaryDefinition = Filter::filterVar($data->definition, FILTER_SANITIZE_SPECIAL_CHARS);
122+
$glossaryItem = $data->item;
123+
$glossaryDefinition = $data->definition;
124124

125125
if (!Token::getInstance($this->session)->verifyToken('update-glossary', $data->csrf)) {
126126
return $this->json(['error' => Translation::get(key: 'msgNoPermission')], Response::HTTP_UNAUTHORIZED);

0 commit comments

Comments
 (0)