|
12 | 12 | * @link https://www.phpmyfaq.de
|
13 | 13 | * @since 2022-07-22
|
14 | 14 | */
|
| 15 | + |
15 | 16 | import { deleteAttachments } from '../api/attachment';
|
16 | 17 | import { pushNotification } from '../utils';
|
17 | 18 |
|
@@ -59,8 +60,7 @@ export const handleFaqForm = () => {
|
59 | 60 | const categoryOptions = document.querySelector('#phpmyfaq-categories');
|
60 | 61 |
|
61 | 62 | if (categoryOptions) {
|
62 |
| - let categories = Array.from(categoryOptions.selectedOptions).map(({ value }) => value); |
63 |
| - |
| 63 | + Array.from(categoryOptions.selectedOptions).map(({ value }) => value); |
64 | 64 | // Override FAQ permissions with Category permission to avoid confused users
|
65 | 65 | categoryOptions.addEventListener('click', (event) => {
|
66 | 66 | event.preventDefault();
|
@@ -101,33 +101,31 @@ const setPermissions = (permissions) => {
|
101 | 101 | }
|
102 | 102 |
|
103 | 103 | // Groups
|
104 |
| - if (-1 === parseInt(perms.group[0])) { |
105 |
| - document.getElementById('restrictedgroups').checked = false; |
106 |
| - document.getElementById('restrictedgroups').disabled = false; |
107 |
| - document.getElementById('allgroups').checked = true; |
108 |
| - document.getElementById('allgroups').disabled = false; |
109 |
| - } else { |
110 |
| - document.getElementById('allgroups').checked = false; |
111 |
| - document.getElementById('allgroups').disabled = true; |
112 |
| - document.getElementById('restrictedgroups').checked = true; |
113 |
| - document.getElementById('restrictedgroups').disabled = false; |
114 |
| - perms.group.forEach((value) => { |
115 |
| - document.querySelector(`#selected-groups option[value='${value}']`).selected = true; |
| 104 | + const restrictedGroups = document.getElementById('restrictedgroups'); |
| 105 | + if (restrictedGroups) { |
| 106 | + const options = document.querySelectorAll('#restrictedgroups option'); |
| 107 | + const allGroups = document.getElementById('allgroups'); |
| 108 | + options.forEach((option) => { |
| 109 | + option.removeAttribute('selected'); |
116 | 110 | });
|
| 111 | + if (-1 === parseInt(perms.group[0])) { |
| 112 | + restrictedGroups.checked = false; |
| 113 | + restrictedGroups.disabled = false; |
| 114 | + allGroups.checked = true; |
| 115 | + allGroups.disabled = false; |
| 116 | + } else { |
| 117 | + allGroups.checked = false; |
| 118 | + allGroups.disabled = true; |
| 119 | + restrictedGroups.checked = true; |
| 120 | + restrictedGroups.disabled = false; |
| 121 | + perms.group.forEach((value) => { |
| 122 | + const optionSelected = document.querySelector(`#restrictedgroups option[value='${value}']`); |
| 123 | + optionSelected.setAttribute('selected', 'selected'); |
| 124 | + }); |
| 125 | + } |
117 | 126 | }
|
118 | 127 | };
|
119 | 128 |
|
120 |
| -const getFaqPermissions = (faqId) => { |
121 |
| - const csrfToken = document.getElementById('csrf').value; |
122 |
| - fetch(`./api/faq/permissions/${faqId}`) |
123 |
| - .then((response) => { |
124 |
| - return response.json(); |
125 |
| - }) |
126 |
| - .then((permissions) => { |
127 |
| - setPermissions(permissions); |
128 |
| - }); |
129 |
| -}; |
130 |
| - |
131 | 129 | const checkForHash = () => {
|
132 | 130 | const questionInputValue = document.getElementById('question').value;
|
133 | 131 | const questionHelp = document.getElementById('questionHelp');
|
|
0 commit comments