Skip to content

Commit

Permalink
feat: removed toggle for sticky and active FAQs (#3049)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Aug 23, 2024
1 parent fdefc5e commit d3d8ca3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 89 deletions.
73 changes: 0 additions & 73 deletions phpmyfaq/admin/assets/src/content/faqs.overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ export const handleFaqOverview = async () => {
const faqs = await fetchAllFaqsByCategory(categoryId, language, onlyInactive, onlyNew);
await populateCategoryTable(categoryId, faqs.faqs);
const deleteFaqButtons = document.querySelectorAll('.pmf-button-delete-faq');
const toggleStickyAllFaqs = document.querySelectorAll('.pmf-admin-faqs-all-sticky');
const toggleStickyFaq = document.querySelectorAll('.pmf-admin-sticky-faq');
const toggleActiveAllFaqs = document.querySelectorAll('.pmf-admin-faqs-all-active');
const toggleActiveFaq = document.querySelectorAll('.pmf-admin-active-faq');
const translationDropdown = document.querySelectorAll('#dropdownAddNewTranslation');

allFaqsAreActive(categoryId);
allFaqsAreSticky(categoryId);

deleteFaqButtons.forEach((element) => {
element.addEventListener('click', async (event) => {
event.preventDefault();
Expand Down Expand Up @@ -98,29 +93,6 @@ export const handleFaqOverview = async () => {
});
});

toggleStickyAllFaqs.forEach((element) => {
element.addEventListener('change', async (event) => {
event.preventDefault();

const categoryId = event.target.getAttribute('data-pmf-category-id');
const faqIds = [];
const token = event.target.getAttribute('data-pmf-csrf');

const checkboxes = document.querySelectorAll('input[type=checkbox]');
if (checkboxes) {
checkboxes.forEach((checkbox) => {
if (checkbox.getAttribute('data-pmf-category-id-sticky') === categoryId) {
checkbox.checked = element.checked;
if (checkbox.checked === true) {
faqIds.push(checkbox.getAttribute('data-pmf-faq-id'));
}
}
});
await saveStatus(categoryId, faqIds, token, event.target.checked, 'sticky');
}
});
});

toggleStickyFaq.forEach((element) => {
element.addEventListener('change', async (event) => {
event.preventDefault();
Expand All @@ -133,29 +105,6 @@ export const handleFaqOverview = async () => {
});
});

toggleActiveAllFaqs.forEach((element) => {
element.addEventListener('change', async (event) => {
event.preventDefault();

const categoryId = event.target.getAttribute('data-pmf-category-id');
const faqIds = [];
const token = event.target.getAttribute('data-pmf-csrf');

const checkboxes = document.querySelectorAll('input[type=checkbox]');
if (checkboxes) {
checkboxes.forEach((checkbox) => {
if (checkbox.getAttribute('data-pmf-category-id-active') === categoryId) {
checkbox.checked = element.checked;
if (checkbox.checked === true) {
faqIds.push(checkbox.getAttribute('data-pmf-faq-id'));
}
}
});
await saveStatus(categoryId, faqIds, token, event.target.checked, 'active');
}
});
});

toggleActiveFaq.forEach((element) => {
element.addEventListener('change', async (event) => {
event.preventDefault();
Expand Down Expand Up @@ -349,28 +298,6 @@ const clearCategoryTable = (categoryId) => {
tableBody.innerHTML = '';
};

const allFaqsAreActive = (categoryId) => {
const checkboxes = document.querySelectorAll('.pmf-admin-active-faq');
const allChecked = Array.from(checkboxes).every((checkbox) => checkbox.checked);
if (allChecked) {
const mainCheckboxToggle = document.getElementById(`active_category_block_${categoryId}`);
if (mainCheckboxToggle) {
mainCheckboxToggle.checked = true;
}
}
};

const allFaqsAreSticky = (categoryId) => {
const checkboxes = document.querySelectorAll('.pmf-admin-sticky-faq');
const allChecked = Array.from(checkboxes).every((checkbox) => checkbox.checked);
if (allChecked) {
const mainCheckboxToggle = document.getElementById(`sticky_category_block_${categoryId}`);
if (mainCheckboxToggle) {
mainCheckboxToggle.checked = true;
}
}
};

const initializeCheckboxState = () => {
const filterForInactive = document.getElementById('pmf-checkbox-filter-inactive');
const filterForNew = document.getElementById('pmf-checkbox-filter-new');
Expand Down
18 changes: 2 additions & 16 deletions phpmyfaq/assets/templates/admin/content/faq.overview.twig
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,10 @@
{{ msgDate }}
</th>
<th class="align-middle">
<div class="form-check">
<input class="form-check-input pmf-admin-faqs-all-sticky" type="checkbox" value=""
data-pmf-category-id="{{ category.id }}" data-pmf-csrf="{{ csrfTokenOverview }}"
id="sticky_category_block_{{ category.id }}">
<label class="form-check-label" for="sticky_category_block_{{ category.id }}">
{{ msgSticky }}
</label>
</div>
{{ msgSticky }}
</th>
<th class="align-middle">
<div class="form-check">
<input class="form-check-input pmf-admin-faqs-all-active" type="checkbox" value=""
data-pmf-category-id="{{ category.id }}" data-pmf-csrf="{{ csrfTokenOverview }}"
id="active_category_block_{{ category.id }}">
<label class="form-check-label" for="sticky_category_block_{{ category.id }}">
{{ msgActive }}
</label>
</div>
{{ msgActive }}
</th>
<th colspan="4" class="align-middle">
Actions
Expand Down

0 comments on commit d3d8ca3

Please sign in to comment.