Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/main/resources/hudson/security/table.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Behaviour, dialog, FormChecker, findElementsBySelector, findAncestor */
/* global Behaviour, dialog, FormChecker, findElementsBySelector */

function matrixAuthEscapeHtml(html) {
return html.replace(/'/g, "&apos;").replace(/"/g, "&quot;").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
Expand Down Expand Up @@ -64,7 +64,7 @@ Behaviour.specify(".matrix-auth-add-button", "GlobalMatrixAuthorizationStrategy"
}
});
table.appendChild(copy);
Behaviour.applySubtree(findAncestor(table, "TABLE"), true);
Behaviour.applySubtree(table.closest("TABLE"), true);
},
() => {},
);
Expand All @@ -78,9 +78,9 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.remove"
e.onclick = function () {
// Run ambiguity warning removal code: If all ambiguous rows are deleted, the warning needs to go as well
// Order of operations: Find table ancestor, remove row, iterate over leftover rows
const table = findAncestor(this, "TABLE");
const table = this.closest("TABLE");

const tr = findAncestor(this, "TR");
const tr = this.closest("TR");
tr.parentNode.removeChild(tr);

const tableRows = table.getElementsByTagName("tr");
Expand Down Expand Up @@ -110,14 +110,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.remove"
*/
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.selectall", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
e.onclick = function () {
const tr = findAncestor(this, "TR");
const tr = this.closest("TR");
const inputs = tr.getElementsByTagName("INPUT");
for (let i = 0; i < inputs.length; i++) {
if (inputs[i].type === "checkbox") {
inputs[i].checked = true;
}
}
Behaviour.applySubtree(findAncestor(this, "TABLE"), true);
Behaviour.applySubtree(this.closest("TABLE"), true);
return false;
};
});
Expand All @@ -127,14 +127,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.selecta
*/
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.unselectall", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
e.onclick = function () {
const tr = findAncestor(this, "TR");
const tr = this.closest("TR");
const inputs = tr.getElementsByTagName("INPUT");
for (let i = 0; i < inputs.length; i++) {
if (inputs[i].type === "checkbox") {
inputs[i].checked = false;
}
}
Behaviour.applySubtree(findAncestor(this, "TABLE"), true);
Behaviour.applySubtree(this.closest("TABLE"), true);
return false;
};
});
Expand All @@ -144,15 +144,15 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.unselec
*/
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
e.onclick = function () {
const tr = findAncestor(this, "TR");
const tr = this.closest("TR");
const name = tr.getAttribute("name");

let newName = name.replace("[EITHER:", "[USER:"); // migrate_user behavior
if (this.classList.contains("migrate_group")) {
newName = name.replace("[EITHER:", "[GROUP:");
}

const table = findAncestor(this, "TABLE");
const table = this.closest("TABLE");
const tableRows = table.getElementsByTagName("tr");
let newNameElement = null;
for (let i = 0; i < tableRows.length; i++) {
Expand All @@ -171,7 +171,7 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
tr.removeAttribute("data-checked");

// remove migration buttons from updated row
const buttonContainer = findAncestor(this, "DIV");
const buttonContainer = this.closest("DIV");
const migrateButtons = buttonContainer.getElementsByClassName("migrate");
for (let i = migrateButtons.length - 1; i >= 0; i--) {
buttonContainer.removeChild(migrateButtons[i]);
Expand Down Expand Up @@ -218,19 +218,19 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
* Whenever permission assignments change, this ensures that implied permissions get their checkboxes disabled.
*/
Behaviour.specify(".global-matrix-authorization-strategy-table td input", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
const table = findAncestor(e, "TABLE");
const table = e.closest("TABLE");
if (table.classList.contains("read-only")) {
// if this is a read-only UI (ExtendedRead / SystemRead), do not enable checkboxes
return;
}

const tooltipAttributeName = "data-html-tooltip";

const impliedByString = findAncestor(e, "TD").getAttribute("data-implied-by-list");
const impliedByString = e.closest("TD").getAttribute("data-implied-by-list");
const impliedByList = impliedByString.split(" ");
const tr = findAncestor(e, "TR");
const tr = e.closest("TR");
e.disabled = false;
let tooltip = matrixAuthEscapeHtml(findAncestor(e, "TD").getAttribute("data-tooltip-enabled"));
let tooltip = matrixAuthEscapeHtml(e.closest("TD").getAttribute("data-tooltip-enabled"));
e.nextSibling.setAttribute(tooltipAttributeName, tooltip);

for (let i = 0; i < impliedByList.length; i++) {
Expand All @@ -239,14 +239,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table td input", "Globa
if (reference !== null) {
if (reference.checked) {
e.disabled = true;
let tooltip = matrixAuthEscapeHtml(findAncestor(e, "TD").getAttribute("data-tooltip-disabled"));
let tooltip = matrixAuthEscapeHtml(e.closest("TD").getAttribute("data-tooltip-disabled"));
e.nextSibling.setAttribute(tooltipAttributeName, tooltip);
}
}
}

e.onchange = function () {
Behaviour.applySubtree(findAncestor(this, "TABLE"), true);
Behaviour.applySubtree(this.closest("TABLE"), true);
return true;
};
});
Expand Down
Loading