Add survey question drag-sort and backend assets
- Frontend editor: drag-to-sort questions with dedicated sort assets/JS - Backend list/search refinements for tl_survey and tl_survey_content - Repository helpers for survey/question/editor queries - Translations and AI handover notes update
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
(function () {
|
||||
function isSurveyListPage() {
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
|
||||
return params.get('do') === 'survey_bundle_surveys';
|
||||
}
|
||||
|
||||
function isSurveyQuestionListPage() {
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
|
||||
return params.get('do') === 'survey_bundle_surveys' && params.get('table') === 'tl_survey_content' && !params.get('act');
|
||||
}
|
||||
|
||||
function toggleQuestionListClass() {
|
||||
document.body.classList.toggle('survey-question-list-page', isSurveyQuestionListPage());
|
||||
document.body.classList.toggle('survey-question-list-clipboard-active', isSurveyQuestionListPage() && hasQuestionListClipboardState());
|
||||
}
|
||||
|
||||
function hasQuestionListClipboardState() {
|
||||
if (!isSurveyQuestionListPage()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (document.querySelector('#paste_hint')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Array.from(document.querySelectorAll('button')).some(function (button) {
|
||||
return (button.textContent || '').trim() === 'Ablage leeren';
|
||||
});
|
||||
}
|
||||
|
||||
function getSearchSelect() {
|
||||
return document.querySelector('select[name="tl_search"]');
|
||||
}
|
||||
|
||||
function getSearchForm(select) {
|
||||
return select ? select.closest('form') : null;
|
||||
}
|
||||
|
||||
function removeIdOption(select) {
|
||||
if (!select) {
|
||||
return;
|
||||
}
|
||||
|
||||
var idOption = select.querySelector('option[value="id"]');
|
||||
|
||||
if (!idOption) {
|
||||
return;
|
||||
}
|
||||
|
||||
var wasSelected = idOption.selected;
|
||||
idOption.remove();
|
||||
|
||||
if (wasSelected) {
|
||||
var fallback = select.querySelector('option[value="title"]') || select.options[0];
|
||||
|
||||
if (fallback) {
|
||||
fallback.selected = true;
|
||||
select.value = fallback.value;
|
||||
select.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeIdChoicesUi() {
|
||||
document.querySelectorAll('.choices__item[data-value="id"]').forEach(function (node) {
|
||||
node.remove();
|
||||
});
|
||||
|
||||
document.querySelectorAll('.choices__item--choice[data-value="id"]').forEach(function (node) {
|
||||
node.remove();
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeSearchField() {
|
||||
toggleQuestionListClass();
|
||||
|
||||
if (!isSurveyListPage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var select = getSearchSelect();
|
||||
|
||||
if (!select) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeIdOption(select);
|
||||
removeIdChoicesUi();
|
||||
|
||||
var form = getSearchForm(select);
|
||||
|
||||
if (form && !form.dataset.surveySearchNormalized) {
|
||||
form.dataset.surveySearchNormalized = '1';
|
||||
form.addEventListener('submit', function () {
|
||||
if (select.value === 'id') {
|
||||
var fallback = select.querySelector('option[value="title"]') || select.options[0];
|
||||
|
||||
if (fallback) {
|
||||
select.value = fallback.value;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', normalizeSearchField);
|
||||
document.addEventListener('turbo:load', normalizeSearchField);
|
||||
|
||||
var observer = new MutationObserver(function () {
|
||||
normalizeSearchField();
|
||||
});
|
||||
|
||||
observer.observe(document.documentElement, { childList: true, subtree: true });
|
||||
})();
|
||||
Reference in New Issue
Block a user