Files
NodeBB/public/src/admin/modules/checkboxRowSelector.js
gasoved 61f02f17d8 feat: column based view on wide priv. tables (#9699)
* 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
2021-08-30 10:42:58 -04:00

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;
});