-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrated from JavaScript to TypeScript
- Loading branch information
Showing
26 changed files
with
675 additions
and
574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './attachment'; | ||
export * from './category'; | ||
export * from './faqs'; | ||
export * from './forms'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Attachment administration stuff | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <thorsten@phpmyfaq.de> | ||
* @copyright 2022-2025 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2022-03-22 | ||
*/ | ||
|
||
import { deleteAttachments, refreshAttachments } from '../api'; | ||
import { pushErrorNotification, pushNotification } from '../../../../assets/src/utils'; | ||
|
||
export const handleDeleteAttachments = (): void => { | ||
const deleteButtons = document.querySelectorAll<HTMLButtonElement>('.btn-delete-attachment'); | ||
|
||
if (deleteButtons.length > 0) { | ||
deleteButtons.forEach((button) => { | ||
const newButton = button.cloneNode(true) as HTMLButtonElement; | ||
button.replaceWith(newButton); | ||
|
||
newButton.addEventListener('click', async (event: MouseEvent) => { | ||
event.preventDefault(); | ||
|
||
const attachmentId = newButton.getAttribute('data-attachment-id'); | ||
const csrf = newButton.getAttribute('data-csrf'); | ||
|
||
if (attachmentId && csrf) { | ||
const response = await deleteAttachments(attachmentId, csrf); | ||
|
||
if (response.success) { | ||
pushNotification(response.success); | ||
const row = document.getElementById(`attachment_${attachmentId}`) as HTMLElement; | ||
row.style.opacity = '0'; | ||
row.addEventListener('transitionend', () => row.remove()); | ||
} | ||
if (response.error) { | ||
pushErrorNotification(response.error); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
export const handleRefreshAttachments = (): void => { | ||
const refreshButtons = document.querySelectorAll<HTMLButtonElement>('.btn-refresh-attachment'); | ||
|
||
if (refreshButtons.length > 0) { | ||
refreshButtons.forEach((button) => { | ||
const newButton = button.cloneNode(true) as HTMLButtonElement; | ||
button.replaceWith(newButton); | ||
|
||
newButton.addEventListener('click', async (event: MouseEvent) => { | ||
event.preventDefault(); | ||
|
||
const attachmentId = newButton.getAttribute('data-attachment-id'); | ||
const csrf = newButton.getAttribute('data-csrf'); | ||
|
||
if (attachmentId && csrf) { | ||
const response = await refreshAttachments(attachmentId, csrf); | ||
|
||
if (response.success) { | ||
pushNotification(response.success); | ||
if (response.delete) { | ||
const row = document.getElementById(`attachment_${attachmentId}`) as HTMLElement; | ||
row.style.opacity = '0'; | ||
row.addEventListener('transitionend', () => row.remove()); | ||
} | ||
} | ||
if (response.error) { | ||
pushErrorNotification(response.error); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.