uprawnienia do stacji i usuwanie firm
This commit is contained in:
+43
-18
@@ -39,36 +39,61 @@ F.bindFavoriteStations=()=>{
|
||||
if(form.dataset.favoriteSearchBound)return;
|
||||
form.dataset.favoriteSearchBound='1';
|
||||
const input=F.qs('.station-modal-search',form),tbody=F.qs('tbody',form);
|
||||
const pagination=F.qs('.favorite-pagination',form),summary=F.qs('.favorite-pagination-summary',form);
|
||||
if(!input||!tbody)return;
|
||||
const pageSize=Math.max(1,Number(form.dataset.pageSize||10));
|
||||
let currentPage=1;
|
||||
let empty=F.qs('.favorite-search-empty',tbody);
|
||||
if(!empty){
|
||||
empty=document.createElement('tr');empty.className='favorite-search-empty d-none';
|
||||
empty.innerHTML='<td colspan="3" class="text-center text-body-secondary py-4">Brak pasujących stacji.</td>';
|
||||
tbody.append(empty);
|
||||
}
|
||||
const filter=()=>{
|
||||
const rows=F.qsa('tr[data-station-name]',tbody);
|
||||
let visible=0;
|
||||
rows.forEach(row=>{
|
||||
const searchable=row.dataset.stationName||row.textContent;
|
||||
const show=matches(searchable,input.value);
|
||||
row.hidden=!show;
|
||||
row.classList.toggle('d-none',!show);
|
||||
if(show)visible++;
|
||||
});
|
||||
empty.hidden=visible!==0;
|
||||
empty.classList.toggle('d-none',visible!==0);
|
||||
const rows=()=>F.qsa('tr[data-station-name]',tbody);
|
||||
const filteredRows=()=>rows().filter(row=>matches(row.dataset.stationName||row.textContent,input.value));
|
||||
const renderPagination=(totalPages,totalItems)=>{
|
||||
if(summary)summary.textContent=totalItems?`Wyniki: ${totalItems} · strona ${currentPage} z ${totalPages}`:'Brak wyników';
|
||||
if(!pagination)return;
|
||||
pagination.innerHTML='';
|
||||
if(totalPages<=1)return;
|
||||
const add=(label,page,disabled=false,active=false)=>{
|
||||
const li=document.createElement('li');li.className=`page-item${disabled?' disabled':''}${active?' active':''}`;
|
||||
const button=document.createElement('button');button.type='button';button.className='page-link';button.textContent=label;
|
||||
button.disabled=disabled;button.addEventListener('click',()=>{currentPage=page;render()});
|
||||
li.append(button);pagination.append(li);
|
||||
};
|
||||
add('‹',Math.max(1,currentPage-1),currentPage===1);
|
||||
const first=Math.max(1,currentPage-2),last=Math.min(totalPages,first+4);
|
||||
for(let page=Math.max(1,last-4);page<=last;page++)add(String(page),page,false,page===currentPage);
|
||||
add('›',Math.min(totalPages,currentPage+1),currentPage===totalPages);
|
||||
};
|
||||
input.addEventListener('input',filter);
|
||||
input.addEventListener('search',filter);
|
||||
const render=()=>{
|
||||
const matching=filteredRows();
|
||||
const totalPages=Math.max(1,Math.ceil(matching.length/pageSize));
|
||||
currentPage=Math.min(currentPage,totalPages);
|
||||
const visibleSet=new Set(matching.slice((currentPage-1)*pageSize,currentPage*pageSize));
|
||||
rows().forEach(row=>{
|
||||
const show=visibleSet.has(row);
|
||||
row.hidden=!show;row.classList.toggle('d-none',!show);
|
||||
});
|
||||
empty.hidden=matching.length!==0;empty.classList.toggle('d-none',matching.length!==0);
|
||||
renderPagination(totalPages,matching.length);
|
||||
};
|
||||
input.addEventListener('input',()=>{currentPage=1;render()});
|
||||
input.addEventListener('search',()=>{currentPage=1;render()});
|
||||
const modal=form.closest('.modal');
|
||||
modal?.addEventListener('shown.bs.modal',()=>{input.focus();filter()});
|
||||
modal?.addEventListener('hidden.bs.modal',()=>{input.value='';filter()});
|
||||
filter();
|
||||
modal?.addEventListener('shown.bs.modal',()=>{input.focus();render()});
|
||||
modal?.addEventListener('hidden.bs.modal',()=>{input.value='';currentPage=1;render()});
|
||||
form.addEventListener('change',event=>{
|
||||
if(!event.target.matches('input[name="station_ids"]'))return;
|
||||
const checked=F.qsa('input[name="station_ids"]:checked',form).length;
|
||||
const max=Number(form.dataset.maxFavorites||25);
|
||||
if(checked>max){event.target.checked=false;F.notify(`Możesz wybrać maksymalnie ${max} stacji.`,'danger')}
|
||||
});
|
||||
render();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
F.bindStationFavoriteToggles=()=>{
|
||||
F.qsa('.station-favorite-toggle').forEach(button=>{
|
||||
if(button.dataset.bound)return;
|
||||
|
||||
Reference in New Issue
Block a user