mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-19 11:01:11 +01:00
* feat: column based view on wide priv. tables * fix: add group/user * feat: copy buttons to work on visible privs * feat: show what's being copied in modal * feat: optional title and message for category selector modal
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
define('admin/modules/checkboxRowSelector', function () {
|
|
const self = {};
|
|
let $tableContainer;
|
|
|
|
self.toggling = false;
|
|
|
|
self.init = function (tableCssSelector) {
|
|
$tableContainer = $(tableCssSelector);
|
|
$tableContainer.on('change', 'input.checkbox-helper', handleChange);
|
|
};
|
|
|
|
self.updateAll = function () {
|
|
$tableContainer.find('input.checkbox-helper').each((idx, el) => {
|
|
self.updateState($(el));
|
|
});
|
|
};
|
|
|
|
self.updateState = function ($checkboxEl) {
|
|
if (self.toggling) {
|
|
return;
|
|
}
|
|
const checkboxes = $checkboxEl.closest('tr').find('input:not([disabled]):visible').toArray();
|
|
const $toggler = $(checkboxes.shift());
|
|
const rowState = checkboxes.length && checkboxes.every(el => el.checked);
|
|
$toggler.prop('checked', rowState);
|
|
};
|
|
|
|
function handleChange(ev) {
|
|
const $checkboxEl = $(ev.target);
|
|
toggleAll($checkboxEl);
|
|
}
|
|
|
|
function toggleAll($checkboxEl) {
|
|
self.toggling = true;
|
|
const state = $checkboxEl.prop('checked');
|
|
$checkboxEl.closest('tr').find('input:not(.checkbox-helper):visible').each((idx, el) => {
|
|
const $checkbox = $(el);
|
|
if ($checkbox.prop('checked') === state) {
|
|
return;
|
|
}
|
|
$checkbox.click();
|
|
});
|
|
self.toggling = false;
|
|
}
|
|
|
|
return self;
|
|
});
|