Skip to content

Commit 9cff605

Browse files
authored
Merge pull request #165 from basil/prettier
Format file with Prettier
2 parents 8a51460 + 9a0a438 commit 9cff605

File tree

2 files changed

+97
-86
lines changed

2 files changed

+97
-86
lines changed

.git-blame-ignore-revs

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# mvn spotless:apply
22
4d0e23d0861ee54bcf40dc3070969584c4eb2de5
3+
4+
# https://github.com/jenkinsci/matrix-auth-plugin/pull/165
5+
# npx prettier --print-width 999 -w src/main/resources/hudson/security/table.js
6+
b5ff96ff53ffb8f5abef09575acb05c38a17b811

src/main/resources/hudson/security/table.js

+93-86
Original file line numberDiff line numberDiff line change
@@ -7,105 +7,112 @@ function matrixAuthEscapeHtml(html) {
77
/*
88
* This handles the addition of new users/groups to the list.
99
*/
10-
Behaviour.specify(".matrix-auth-add-button", 'GlobalMatrixAuthorizationStrategy', 0, function(e) {
10+
Behaviour.specify(".matrix-auth-add-button", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
1111
e.onclick = function (e) {
1212
const dataReference = e.target;
13-
const master = document.getElementById(dataReference.getAttribute('data-table-id'));
13+
const master = document.getElementById(dataReference.getAttribute("data-table-id"));
1414
const table = master.parentNode;
15-
const type = dataReference.getAttribute('data-type');
16-
const typeLabel = dataReference.getAttribute('data-type-label');
15+
const type = dataReference.getAttribute("data-type");
16+
const typeLabel = dataReference.getAttribute("data-type-label");
1717

18-
dialog.prompt(dataReference.getAttribute('data-message-title'), {
19-
message: dataReference.getAttribute('data-message-prompt')
20-
}).then ((name) => {
21-
if (findElementsBySelector(table, "TR").find(function(n){
22-
return n.getAttribute("name") === '[' + type + ':' + name + ']';
23-
}) != null) {
24-
dialog.alert(dataReference.getAttribute('data-message-error'));
25-
return;
26-
}
18+
dialog
19+
.prompt(dataReference.getAttribute("data-message-title"), {
20+
message: dataReference.getAttribute("data-message-prompt"),
21+
})
22+
.then(
23+
(name) => {
24+
if (
25+
findElementsBySelector(table, "TR").find(function (n) {
26+
return n.getAttribute("name") === "[" + type + ":" + name + "]";
27+
}) != null
28+
) {
29+
dialog.alert(dataReference.getAttribute("data-message-error"));
30+
return;
31+
}
2732

28-
const copy = document.importNode(master, true);
29-
copy.removeAttribute("id");
30-
copy.removeAttribute("style");
31-
copy.firstChild.innerHTML = matrixAuthEscapeHtml(name); // TODO consider setting innerText
32-
copy.setAttribute("name", '[' + type + ':' + name + ']');
33+
const copy = document.importNode(master, true);
34+
copy.removeAttribute("id");
35+
copy.removeAttribute("style");
36+
copy.firstChild.innerHTML = matrixAuthEscapeHtml(name); // TODO consider setting innerText
37+
copy.setAttribute("name", "[" + type + ":" + name + "]");
3338

34-
for (let child = copy.firstChild; child !== null; child = child.nextSibling) {
35-
if (child.hasAttribute('data-permission-id')) {
36-
child.setAttribute("data-tooltip-enabled", child.getAttribute("data-tooltip-enabled").replace("__SID__", name).replace("__TYPE__", typeLabel));
37-
child.setAttribute("data-tooltip-disabled", child.getAttribute("data-tooltip-disabled").replace("__SID__", name).replace("__TYPE__", typeLabel));
38-
}
39-
}
39+
for (let child = copy.firstChild; child !== null; child = child.nextSibling) {
40+
if (child.hasAttribute("data-permission-id")) {
41+
child.setAttribute("data-tooltip-enabled", child.getAttribute("data-tooltip-enabled").replace("__SID__", name).replace("__TYPE__", typeLabel));
42+
child.setAttribute("data-tooltip-disabled", child.getAttribute("data-tooltip-disabled").replace("__SID__", name).replace("__TYPE__", typeLabel));
43+
}
44+
}
4045

41-
const tooltipAttributeName = 'data-html-tooltip';
46+
const tooltipAttributeName = "data-html-tooltip";
4247

43-
findElementsBySelector(copy, ".stop a").forEach(function(item) {
44-
// TODO Clean this up, `title` should be long obsolete.
45-
let oldTitle = item.getAttribute("title");
46-
if (oldTitle !== null) {
47-
item.setAttribute("title", oldTitle.replace("__SID__", name).replace("__TYPE__", typeLabel));
48-
}
49-
item.setAttribute(tooltipAttributeName, item.getAttribute(tooltipAttributeName).replace("__SID__", name).replace("__TYPE__", typeLabel));
50-
});
48+
findElementsBySelector(copy, ".stop a").forEach(function (item) {
49+
// TODO Clean this up, `title` should be long obsolete.
50+
let oldTitle = item.getAttribute("title");
51+
if (oldTitle !== null) {
52+
item.setAttribute("title", oldTitle.replace("__SID__", name).replace("__TYPE__", typeLabel));
53+
}
54+
item.setAttribute(tooltipAttributeName, item.getAttribute(tooltipAttributeName).replace("__SID__", name).replace("__TYPE__", typeLabel));
55+
});
5156

52-
findElementsBySelector(copy, "input[type=checkbox]").forEach(function(item) {
53-
const tooltip = item.nextSibling.getAttribute(tooltipAttributeName);
54-
if (tooltip) {
55-
item.nextSibling.setAttribute(tooltipAttributeName, tooltip.replace("__SID__", name).replace("__TYPE__", typeLabel));
56-
} else {
57-
// TODO Clean this up, `title` should be long obsolete.
58-
item.nextSibling.setAttribute("title", item.getAttribute("title").replace("__SID__", name).replace("__TYPE__", typeLabel));
59-
}
60-
});
61-
table.appendChild(copy);
62-
Behaviour.applySubtree(findAncestor(table, "TABLE"), true);
63-
}, () => {});
64-
}
57+
findElementsBySelector(copy, "input[type=checkbox]").forEach(function (item) {
58+
const tooltip = item.nextSibling.getAttribute(tooltipAttributeName);
59+
if (tooltip) {
60+
item.nextSibling.setAttribute(tooltipAttributeName, tooltip.replace("__SID__", name).replace("__TYPE__", typeLabel));
61+
} else {
62+
// TODO Clean this up, `title` should be long obsolete.
63+
item.nextSibling.setAttribute("title", item.getAttribute("title").replace("__SID__", name).replace("__TYPE__", typeLabel));
64+
}
65+
});
66+
table.appendChild(copy);
67+
Behaviour.applySubtree(findAncestor(table, "TABLE"), true);
68+
},
69+
() => {},
70+
);
71+
};
6572
});
6673

6774
/*
6875
* Behavior for the element removing a permission assignment row for a user/group
6976
*/
70-
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.remove", 'GlobalMatrixAuthorizationStrategy', 0, function(e) {
71-
e.onclick = function() {
77+
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.remove", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
78+
e.onclick = function () {
7279
// Run ambiguity warning removal code: If all ambiguous rows are deleted, the warning needs to go as well
7380
// Order of operations: Find table ancestor, remove row, iterate over leftover rows
7481
const table = findAncestor(this, "TABLE");
7582

7683
const tr = findAncestor(this, "TR");
7784
tr.parentNode.removeChild(tr);
7885

79-
const tableRows = table.getElementsByTagName('tr');
86+
const tableRows = table.getElementsByTagName("tr");
8087

8188
let hasAmbiguousRows = false;
8289

8390
for (let i = 0; i < tableRows.length; i++) {
84-
if (tableRows[i].getAttribute('name') !== null && tableRows[i].getAttribute('name').startsWith('[EITHER')) {
91+
if (tableRows[i].getAttribute("name") !== null && tableRows[i].getAttribute("name").startsWith("[EITHER")) {
8592
hasAmbiguousRows = true;
8693
}
8794
}
8895
if (!hasAmbiguousRows) {
8996
const alertElements = document.getElementsByClassName("alert");
9097
for (let i = 0; i < alertElements.length; i++) {
91-
if (alertElements[i].hasAttribute('data-table-id') && alertElements[i].getAttribute('data-table-id') === table.getAttribute('data-table-id')) {
92-
alertElements[i].style.display = 'none'; // TODO animate this?
98+
if (alertElements[i].hasAttribute("data-table-id") && alertElements[i].getAttribute("data-table-id") === table.getAttribute("data-table-id")) {
99+
alertElements[i].style.display = "none"; // TODO animate this?
93100
}
94101
}
95102
}
96103

97104
return false;
98-
}
105+
};
99106
});
100107

101108
/*
102109
* Behavior for 'Select all' element that exists for each row of permissions checkboxes
103110
*/
104-
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.selectall", 'GlobalMatrixAuthorizationStrategy', 0, function(e) {
105-
e.onclick = function() {
111+
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.selectall", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
112+
e.onclick = function () {
106113
const tr = findAncestor(this, "TR");
107114
const inputs = tr.getElementsByTagName("INPUT");
108-
for (let i=0; i < inputs.length; i++) {
115+
for (let i = 0; i < inputs.length; i++) {
109116
if (inputs[i].type === "checkbox") {
110117
inputs[i].checked = true;
111118
}
@@ -118,8 +125,8 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.selecta
118125
/*
119126
* Behavior for 'Unselect all' element that exists for each row of permissions checkboxes
120127
*/
121-
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.unselectall", 'GlobalMatrixAuthorizationStrategy', 0, function(e) {
122-
e.onclick = function() {
128+
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.unselectall", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
129+
e.onclick = function () {
123130
const tr = findAncestor(this, "TR");
124131
const inputs = tr.getElementsByTagName("INPUT");
125132
for (let i = 0; i < inputs.length; i++) {
@@ -135,21 +142,21 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.unselec
135142
/*
136143
* Behavior for 'Migrate to user' element that exists for each ambiguous row
137144
*/
138-
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate", 'GlobalMatrixAuthorizationStrategy', 0, function(e) {
139-
e.onclick = function() {
145+
Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
146+
e.onclick = function () {
140147
const tr = findAncestor(this, "TR");
141-
const name = tr.getAttribute('name');
148+
const name = tr.getAttribute("name");
142149

143-
let newName = name.replace('[EITHER:', '[USER:'); // migrate_user behavior
144-
if (this.classList.contains('migrate_group')) {
145-
newName = name.replace('[EITHER:', '[GROUP:');
150+
let newName = name.replace("[EITHER:", "[USER:"); // migrate_user behavior
151+
if (this.classList.contains("migrate_group")) {
152+
newName = name.replace("[EITHER:", "[GROUP:");
146153
}
147154

148155
const table = findAncestor(this, "TABLE");
149-
const tableRows = table.getElementsByTagName('tr');
156+
const tableRows = table.getElementsByTagName("tr");
150157
let newNameElement = null;
151158
for (let i = 0; i < tableRows.length; i++) {
152-
if (tableRows[i].getAttribute('name') === newName) {
159+
if (tableRows[i].getAttribute("name") === newName) {
153160
newNameElement = tableRows[i];
154161
break;
155162
}
@@ -160,12 +167,12 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
160167
}
161168
if (newNameElement == null) {
162169
// no row for this name exists yet, so transform the ambiguous row to unambiguous
163-
tr.setAttribute('name', newName);
164-
tr.removeAttribute('data-checked');
170+
tr.setAttribute("name", newName);
171+
tr.removeAttribute("data-checked");
165172

166173
// remove migration buttons from updated row
167174
const buttonContainer = findAncestor(this, "DIV");
168-
const migrateButtons = buttonContainer.getElementsByClassName('migrate');
175+
const migrateButtons = buttonContainer.getElementsByClassName("migrate");
169176
for (let i = migrateButtons.length - 1; i >= 0; i--) {
170177
buttonContainer.removeChild(migrateButtons[i]);
171178
}
@@ -175,11 +182,11 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
175182
// migrate permissions from this row
176183
const ambiguousPermissionInputs = tr.getElementsByTagName("INPUT");
177184
const unambiguousPermissionInputs = newNameElement.getElementsByTagName("INPUT");
178-
for (let i = 0; i < ambiguousPermissionInputs.length; i++){
185+
for (let i = 0; i < ambiguousPermissionInputs.length; i++) {
179186
if (ambiguousPermissionInputs[i].type === "checkbox") {
180187
unambiguousPermissionInputs[i].checked |= ambiguousPermissionInputs[i].checked;
181188
}
182-
newNameElement.classList.add('highlight-entry');
189+
newNameElement.classList.add("highlight-entry");
183190
}
184191

185192
// remove this row
@@ -190,15 +197,15 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
190197
let hasAmbiguousRows = false;
191198

192199
for (let i = 0; i < tableRows.length; i++) {
193-
if (tableRows[i].getAttribute('name') !== null && tableRows[i].getAttribute('name').startsWith('[EITHER')) {
200+
if (tableRows[i].getAttribute("name") !== null && tableRows[i].getAttribute("name").startsWith("[EITHER")) {
194201
hasAmbiguousRows = true;
195202
}
196203
}
197204
if (!hasAmbiguousRows) {
198205
let alertElements = document.getElementsByClassName("alert");
199206
for (let i = 0; i < alertElements.length; i++) {
200-
if (alertElements[i].hasAttribute('data-table-id') && alertElements[i].getAttribute('data-table-id') === table.getAttribute('data-table-id')) {
201-
alertElements[i].style.display = 'none'; // TODO animate this?
207+
if (alertElements[i].hasAttribute("data-table-id") && alertElements[i].getAttribute("data-table-id") === table.getAttribute("data-table-id")) {
208+
alertElements[i].style.display = "none"; // TODO animate this?
202209
}
203210
}
204211
}
@@ -210,20 +217,20 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
210217
/*
211218
* Whenever permission assignments change, this ensures that implied permissions get their checkboxes disabled.
212219
*/
213-
Behaviour.specify(".global-matrix-authorization-strategy-table td input", 'GlobalMatrixAuthorizationStrategy', 0, function(e) {
220+
Behaviour.specify(".global-matrix-authorization-strategy-table td input", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
214221
const table = findAncestor(e, "TABLE");
215-
if (table.classList.contains('read-only')) {
222+
if (table.classList.contains("read-only")) {
216223
// if this is a read-only UI (ExtendedRead / SystemRead), do not enable checkboxes
217224
return;
218225
}
219226

220-
const tooltipAttributeName = 'data-html-tooltip';
227+
const tooltipAttributeName = "data-html-tooltip";
221228

222-
const impliedByString = findAncestor(e, "TD").getAttribute('data-implied-by-list');
229+
const impliedByString = findAncestor(e, "TD").getAttribute("data-implied-by-list");
223230
const impliedByList = impliedByString.split(" ");
224231
const tr = findAncestor(e, "TR");
225232
e.disabled = false;
226-
let tooltip = matrixAuthEscapeHtml(findAncestor(e, "TD").getAttribute('data-tooltip-enabled'));
233+
let tooltip = matrixAuthEscapeHtml(findAncestor(e, "TD").getAttribute("data-tooltip-enabled"));
227234
e.nextSibling.setAttribute(tooltipAttributeName, tooltip);
228235

229236
for (let i = 0; i < impliedByList.length; i++) {
@@ -232,13 +239,13 @@ Behaviour.specify(".global-matrix-authorization-strategy-table td input", 'Globa
232239
if (reference !== null) {
233240
if (reference.checked) {
234241
e.disabled = true;
235-
let tooltip = matrixAuthEscapeHtml(findAncestor(e, "TD").getAttribute('data-tooltip-disabled'));
242+
let tooltip = matrixAuthEscapeHtml(findAncestor(e, "TD").getAttribute("data-tooltip-disabled"));
236243
e.nextSibling.setAttribute(tooltipAttributeName, tooltip);
237244
}
238245
}
239246
}
240247

241-
e.onchange = function() {
248+
e.onchange = function () {
242249
Behaviour.applySubtree(findAncestor(this, "TABLE"), true);
243250
return true;
244251
};
@@ -247,12 +254,12 @@ Behaviour.specify(".global-matrix-authorization-strategy-table td input", 'Globa
247254
/*
248255
* Each newly added row needs to have the name checked. Triggered by explicit Behaviour#applySubtree calls elsewhere.
249256
*/
250-
Behaviour.specify(".global-matrix-authorization-strategy-table TR.permission-row", 'GlobalMatrixAuthorizationStrategy', 0, function(e) {
251-
if (e.getAttribute('name') === '__unused__') {
257+
Behaviour.specify(".global-matrix-authorization-strategy-table TR.permission-row", "GlobalMatrixAuthorizationStrategy", 0, function (e) {
258+
if (e.getAttribute("name") === "__unused__") {
252259
return;
253260
}
254-
if (!e.hasAttribute('data-checked')) {
255-
FormChecker.delayedCheck(e.getAttribute('data-descriptor-url') + "/checkName?value=" + encodeURIComponent(e.getAttribute("name")), "GET", e.firstChild);
256-
e.setAttribute('data-checked', 'true');
261+
if (!e.hasAttribute("data-checked")) {
262+
FormChecker.delayedCheck(e.getAttribute("data-descriptor-url") + "/checkName?value=" + encodeURIComponent(e.getAttribute("name")), "GET", e.firstChild);
263+
e.setAttribute("data-checked", "true");
257264
}
258265
});

0 commit comments

Comments
 (0)