refactor: var to const

isekai-main
gasoved 3 years ago committed by Julian Lam
parent ca9bae3a1c
commit 1272da6539

@ -9,9 +9,9 @@ define('admin/manage/privileges', [
'mousetrap',
'admin/modules/checkboxRowSelector',
], function (api, autocomplete, bootbox, translator, categorySelector, mousetrap, checkboxRowSelector) {
var Privileges = {};
const Privileges = {};
var cid;
let cid;
// number of columns to skip in category privilege tables
const SKIP_PRIV_COLS = 3;
@ -40,16 +40,16 @@ define('admin/manage/privileges', [
Privileges.setupPrivilegeTable = function () {
$('.privilege-table-container').on('change', 'input[type="checkbox"]:not(.checkbox-helper)', function () {
var checkboxEl = $(this);
var wrapperEl = checkboxEl.parent();
var privilege = wrapperEl.attr('data-privilege');
var state = checkboxEl.prop('checked');
var rowEl = checkboxEl.parents('tr');
var member = rowEl.attr('data-group-name') || rowEl.attr('data-uid');
var isPrivate = parseInt(rowEl.attr('data-private') || 0, 10);
var isGroup = rowEl.attr('data-group-name') !== undefined;
var isBanned = (isGroup && rowEl.attr('data-group-name') === 'banned-users') || rowEl.attr('data-banned') !== undefined;
var delta = checkboxEl.prop('checked') === (wrapperEl.attr('data-value') === 'true') ? null : state;
const checkboxEl = $(this);
const wrapperEl = checkboxEl.parent();
const privilege = wrapperEl.attr('data-privilege');
const state = checkboxEl.prop('checked');
const rowEl = checkboxEl.parents('tr');
const member = rowEl.attr('data-group-name') || rowEl.attr('data-uid');
const isPrivate = parseInt(rowEl.attr('data-private') || 0, 10);
const isGroup = rowEl.attr('data-group-name') !== undefined;
const isBanned = (isGroup && rowEl.attr('data-group-name') === 'banned-users') || rowEl.attr('data-banned') !== undefined;
const delta = checkboxEl.prop('checked') === (wrapperEl.attr('data-value') === 'true') ? null : state;
if (member) {
if (isGroup && privilege === 'groups:moderate' && !isPrivate && state) {
@ -110,7 +110,7 @@ define('admin/manage/privileges', [
throwConfirmModal('copyToChildren', Privileges.copyPrivilegesToChildren.bind(null, cid, ''));
});
$privTableCon.on('click', '[data-action="copyToChildrenGroup"]', function () {
var groupName = $(this).parents('[data-group-name]').attr('data-group-name');
const groupName = $(this).parents('[data-group-name]').attr('data-group-name');
throwConfirmModal('copyToChildrenGroup', Privileges.copyPrivilegesToChildren.bind(null, cid, groupName));
});
@ -118,7 +118,7 @@ define('admin/manage/privileges', [
Privileges.copyPrivilegesFromCategory(cid, '');
});
$privTableCon.on('click', '[data-action="copyPrivilegesFromGroup"]', function () {
var groupName = $(this).parents('[data-group-name]').attr('data-group-name');
const groupName = $(this).parents('[data-group-name]').attr('data-group-name');
Privileges.copyPrivilegesFromCategory(cid, groupName);
});
@ -126,7 +126,7 @@ define('admin/manage/privileges', [
throwConfirmModal('copyToAll', Privileges.copyPrivilegesToAllCategories.bind(null, cid, ''));
});
$privTableCon.on('click', '[data-action="copyToAllGroup"]', function () {
var groupName = $(this).parents('[data-group-name]').attr('data-group-name');
const groupName = $(this).parents('[data-group-name]').attr('data-group-name');
throwConfirmModal('copyToAllGroup', Privileges.copyPrivilegesToAllCategories.bind(null, cid, groupName));
});
@ -148,12 +148,12 @@ define('admin/manage/privileges', [
};
Privileges.commit = function () {
var tableEl = document.querySelector('.privilege-table-container');
var requests = $.map(tableEl.querySelectorAll('td[data-delta]'), function (el) {
var privilege = el.getAttribute('data-privilege');
var rowEl = el.parentNode;
var member = rowEl.getAttribute('data-group-name') || rowEl.getAttribute('data-uid');
var state = el.getAttribute('data-delta') === 'true' ? 1 : 0;
const tableEl = document.querySelector('.privilege-table-container');
const requests = $.map(tableEl.querySelectorAll('td[data-delta]'), function (el) {
const privilege = el.getAttribute('data-privilege');
const rowEl = el.parentNode;
const member = rowEl.getAttribute('data-group-name') || rowEl.getAttribute('data-uid');
const state = el.getAttribute('data-delta') === 'true' ? 1 : 0;
return Privileges.setPrivilege(member, privilege, state);
});
@ -180,7 +180,7 @@ define('admin/manage/privileges', [
Privileges.refreshPrivilegeTable = function (groupToHighlight) {
api.get(`/categories/${cid}/privileges`, {}).then((privileges) => {
ajaxify.data.privileges = { ...ajaxify.data.privileges, ...privileges };
var tpl = parseInt(cid, 10) ? 'admin/partials/privileges/category' : 'admin/partials/privileges/global';
const tpl = parseInt(cid, 10) ? 'admin/partials/privileges/category' : 'admin/partials/privileges/global';
app.parseAndTranslate(tpl, { privileges }).then((html) => {
// Get currently selected filters
const btnIndices = $('.privilege-filters button.btn-warning').map((idx, el) => $(el).index()).get();
@ -224,14 +224,14 @@ define('admin/manage/privileges', [
Privileges.setPrivilege = (member, privilege, state) => api[state ? 'put' : 'delete'](`/categories/${isNaN(cid) ? 0 : cid}/privileges/${privilege}`, { member });
Privileges.addUserToPrivilegeTable = function () {
var modal = bootbox.dialog({
const modal = bootbox.dialog({
title: '[[admin/manage/categories:alert.find-user]]',
message: '<input class="form-control input-lg" placeholder="[[admin/manage/categories:alert.user-search]]" />',
show: true,
});
modal.on('shown.bs.modal', function () {
var inputEl = modal.find('input');
const inputEl = modal.find('input');
inputEl.focus();
autocomplete.user(inputEl, function (ev, ui) {
@ -243,14 +243,14 @@ define('admin/manage/privileges', [
};
Privileges.addGroupToPrivilegeTable = function () {
var modal = bootbox.dialog({
const modal = bootbox.dialog({
title: '[[admin/manage/categories:alert.find-group]]',
message: '<input class="form-control input-lg" placeholder="[[admin/manage/categories:alert.group-search]]" />',
show: true,
});
modal.on('shown.bs.modal', function () {
var inputEl = modal.find('input');
const inputEl = modal.find('input');
inputEl.focus();
autocomplete.group(inputEl, function (ev, ui) {
@ -347,7 +347,7 @@ define('admin/manage/privileges', [
function hightlightRowByDataAttr(attrName, attrValue) {
if (attrValue) {
var el = $('[' + attrName + ']').filter(function () {
const el = $('[' + attrName + ']').filter(function () {
return $(this).attr(attrName) === String(attrValue);
});
@ -370,13 +370,13 @@ define('admin/manage/privileges', [
function addGroupToCategory(group, cb) {
cb = cb || function () {};
var groupRow = document.querySelector('.privilege-table [data-group-name="' + group + '"]');
const groupRow = document.querySelector('.privilege-table [data-group-name="' + group + '"]');
if (groupRow) {
hightlightRowByDataAttr('data-group-name', group);
return cb();
}
// Generate data for new row
var privilegeSet = ajaxify.data.privileges.keys.groups.reduce(function (memo, cur) {
const privilegeSet = ajaxify.data.privileges.keys.groups.reduce(function (memo, cur) {
memo[cur] = false;
return memo;
}, {});
@ -392,7 +392,7 @@ define('admin/manage/privileges', [
],
},
}, function (html) {
var tbodyEl = document.querySelector('.privilege-table tbody');
const tbodyEl = document.querySelector('.privilege-table tbody');
const btnIdx = $('.privilege-filters').first().find('button.btn-warning').index();
tbodyEl.append(html.get(0));
Privileges.exposeAssumedPrivileges();
@ -404,13 +404,13 @@ define('admin/manage/privileges', [
async function addUserToCategory(user, cb) {
cb = cb || function () {};
var userRow = document.querySelector('.privilege-table [data-uid="' + user.uid + '"]');
const userRow = document.querySelector('.privilege-table [data-uid="' + user.uid + '"]');
if (userRow) {
hightlightRowByDataAttr('data-uid', user.uid);
return cb();
}
// Generate data for new row
var privilegeSet = ajaxify.data.privileges.keys.users.reduce(function (memo, cur) {
const privilegeSet = ajaxify.data.privileges.keys.users.reduce(function (memo, cur) {
memo[cur] = false;
return memo;
}, {});
@ -431,7 +431,7 @@ define('admin/manage/privileges', [
},
});
var tbodyEl = document.querySelectorAll('.privilege-table tbody');
const tbodyEl = document.querySelectorAll('.privilege-table tbody');
const btnIdx = $('.privilege-filters').last().find('button.btn-warning').index();
tbodyEl[1].append(html.get(0));
Privileges.exposeAssumedPrivileges();

Loading…
Cancel
Save