Wire up bulk action toggle

This commit is contained in:
Rob Garrison 2018-11-28 07:50:54 -06:00
parent a1b78476bb
commit 17e1860ba6
3 changed files with 35 additions and 2 deletions

View File

@ -320,6 +320,7 @@
<path class="indeterminate" d="M3.5 6.3h7v1.4h-7z"/> <path class="indeterminate" d="M3.5 6.3h7v1.4h-7z"/>
</svg> </svg>
</label> </label>
<span id="bulk-filter-count"></span>
<span i18n-text="bulkActions"></span> <span i18n-text="bulkActions"></span>
<span class="select-resizer bulk-actions-select"> <span class="select-resizer bulk-actions-select">
<select id="bulk-actions" i18n-title="manageOnlyLocalTooltip"> <select id="bulk-actions" i18n-title="manageOnlyLocalTooltip">

View File

@ -86,6 +86,8 @@ function initGlobalEvents() {
} }
}); });
document.addEventListener('change', updateBulkFilters);
$$('[data-toggle-on-click]').forEach(el => { $$('[data-toggle-on-click]').forEach(el => {
// dataset on SVG doesn't work in Chrome 49-??, works in 57+ // dataset on SVG doesn't work in Chrome 49-??, works in 57+
const target = $(el.getAttribute('data-toggle-on-click')); const target = $(el.getAttribute('data-toggle-on-click'));
@ -419,6 +421,34 @@ function onVisibilityChange() {
} }
} }
function updateBulkFilters({target}) {
// total is undefined until initialized
if (!installed.dataset.total) return;
// ignore filter checkboxes
if (target.type === 'checkbox' && !target.dataset.filter) {
$('#manage-bulk-actions').classList.remove('hidden');
const bulk = $('#toggle-all-filters');
const state = target.checked;
const visibleEntries = $$('.entry-filter-toggle')
.filter(entry => !entry.closest('.entry').classList.contains('hidden'));
bulk.indeterminate = false;
if (target === bulk) {
visibleEntries.forEach(entry => {
entry.checked = state;
});
} else {
if (visibleEntries.length === visibleEntries.filter(entry => entry.checked === state).length) {
bulk.checked = state;
} else {
bulk.checked = false;
bulk.indeterminate = true;
}
}
const count = $$('.entry-filter-toggle').filter(entry => entry.checked).length;
$('#bulk-filter-count').textContent = count || '';
}
}
function lazyLoad() { function lazyLoad() {
setTimeout(() => { setTimeout(() => {
$$('link[data-href]').forEach(link => { $$('link[data-href]').forEach(link => {

View File

@ -538,7 +538,7 @@ details.applies-to-extra[open] {
} }
#filters, #filters,
.toggle-all { #bulk-filter-count {
margin-right: 20px; margin-right: 20px;
} }
@ -593,9 +593,11 @@ details.applies-to-extra[open] {
border: 1px solid transparent; border: 1px solid transparent;
} }
.active #filters-stats { .active #filters-stats,
#bulk-filter-count:not(:empty) {
background-color: darkcyan; background-color: darkcyan;
border-color: darkcyan; border-color: darkcyan;
border-radius: 2px;
color: white; color: white;
font-size: 0.7rem; font-size: 0.7rem;
font-weight: normal; font-weight: normal;