Toggle based on majority checkbox state

This commit is contained in:
realies
2018-10-08 23:30:02 +01:00
committed by GitHub
parent d96bd77677
commit f2ef9d54fe

View File

@@ -119,6 +119,12 @@ function vm() {
buttons(document.vm);
});
}
function thread2containers(n) {
const selector = $('form[name=ct]').find(`[name$=":${n}"]`);
const checkboxes = selector.length;
const checked = selector.filter(':checked').length;
selector.prop('checked', (checkboxes - checked > checked ? true : false)).change();
}
function ct() {
// fetch the current container assignments
$.post('/webGui/include/CPUset.php',{id:'ct',cpus:'<?=$cpuset?>'},function(d){
@@ -126,9 +132,9 @@ function ct() {
$('#table-ct').html(data[0]);
$('#names-ct').val(data[1]);
buttons(document.ct);
// inject global cpu pinning links
// inject thread to containers toggles
$('form[name=ct]').find('thead tr th:gt(1)').each((i, elem) => {
elem.innerHTML = elem.innerHTML.replace(/(\d+)/g, `<a href="javascript:void(0)" data-state="false" onclick="$(this).data('state', !$(this).data('state')); $('form[name=ct]').find('[name$=&quot;:$1&quot;]').prop('checked', $(this).data('state')).change()">$1</a>`);
elem.innerHTML = elem.innerHTML.replace(/(\d+)/g, `<a href="#" onclick="thread2containers(this.innerText);return false;" title="Toggle thread to containers">$1</a>`);
});
});
}