Disable appending to an empty result list
This commit is contained in:
@@ -1250,6 +1250,15 @@ const searchPagination=document.querySelector('#searchPagination');
|
||||
let displayedSearchRows=[];
|
||||
let searchResultGroups=[];
|
||||
const searchResultsByPanel=new Map();
|
||||
const syncSearchAddButton=panel=>{
|
||||
if(!panel)return;
|
||||
const addButton=panel.querySelector('[data-search-action="append"]');
|
||||
if(!addButton)return;
|
||||
const hasResults=Boolean(searchResultsByPanel.get(panel.id)?.rows.length);
|
||||
addButton.disabled=!hasResults;
|
||||
addButton.setAttribute('aria-disabled',String(!hasResults));
|
||||
addButton.title=hasResults?'Добавить результаты к текущему списку':'Сначала выполните поиск';
|
||||
};
|
||||
const getSearchRows=panel=>{
|
||||
const registryChecked=[...panel.querySelectorAll('.filter-check')].some(label=>label.textContent.includes('Входящие в Реестр ОПК')&&label.querySelector('input')?.checked);
|
||||
const systemformingChecked=[...panel.querySelectorAll('.filter-check')].some(label=>label.textContent.includes('Системообразующие организации')&&label.querySelector('input')?.checked);
|
||||
@@ -1490,6 +1499,7 @@ const updateSearchResults=(panel,action='replace')=>{
|
||||
searchResultGroups=[{action:'replace',filters,rows:[...rows]}];
|
||||
}
|
||||
searchResultsByPanel.set(panel.id,{rows:displayedSearchRows,groups:searchResultGroups});
|
||||
syncSearchAddButton(panel);
|
||||
renderSearchResults();
|
||||
resetSearchPanel(panel);
|
||||
};
|
||||
@@ -1517,7 +1527,10 @@ searchResults.addEventListener('click',event=>{
|
||||
searchResultGroups.splice(groupIndex,1);
|
||||
displayedSearchRows=searchResultGroups.flatMap(item=>item.rows);
|
||||
const activePanel=document.querySelector('.filter-panel:not([hidden])');
|
||||
if(activePanel)searchResultsByPanel.set(activePanel.id,{rows:displayedSearchRows,groups:searchResultGroups});
|
||||
if(activePanel){
|
||||
searchResultsByPanel.set(activePanel.id,{rows:displayedSearchRows,groups:searchResultGroups});
|
||||
syncSearchAddButton(activePanel);
|
||||
}
|
||||
renderSearchResults();
|
||||
}
|
||||
});
|
||||
@@ -1544,6 +1557,7 @@ const setFilterPanel=panelName=>{
|
||||
const panelState=searchResultsByPanel.get(panelId);
|
||||
displayedSearchRows=panelState?.rows||[];
|
||||
searchResultGroups=panelState?.groups||[];
|
||||
syncSearchAddButton(document.getElementById(panelId));
|
||||
renderSearchResults();
|
||||
};
|
||||
const createFilterTab=panelName=>{
|
||||
@@ -1696,6 +1710,7 @@ const initializeFilterSelect=select=>{
|
||||
sync();
|
||||
};
|
||||
const initializeFilterPanel=panel=>{
|
||||
syncSearchAddButton(panel);
|
||||
panel.querySelectorAll('select').forEach(initializeFilterSelect);
|
||||
panel.querySelectorAll('.search-field').forEach(field=>{
|
||||
updateFilterFieldState(field);
|
||||
|
||||
Reference in New Issue
Block a user