Skip to content

Commit fe552ed

Browse files
authored
Merge pull request #501 from basil/remove-prototype
Replace Prototype.js with native JavaScript
2 parents db736a0 + 2954f1e commit fe552ed

File tree

2 files changed

+64
-52
lines changed
  • src/main/resources/org/jenkinsci/plugins/scriptsecurity

2 files changed

+64
-52
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// https://issues.jenkins-ci.org/browse/JENKINS-15604 workaround:
22
function cmChange(editor, change) {
33
editor.save();
4-
$$('.validated').each(function (e) {e.onchange();});
4+
document.querySelectorAll('.validated').forEach(function (e) {e.onchange();});
55
}

src/main/resources/org/jenkinsci/plugins/scriptsecurity/scripts/ScriptApproval/index.jelly

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ THE SOFTWARE.
3030
<script>
3131
var mgr = <st:bind value="${it}"/>;
3232
function hideScript(hash) {
33-
$('ps-' + hash).remove();
33+
document.getElementById('ps-' + hash).remove();
3434
}
3535
function approveScript(hash) {
3636
mgr.approveScript(hash);
@@ -41,13 +41,15 @@ THE SOFTWARE.
4141
hideScript(hash);
4242
}
4343
function hideSignature(hash) {
44-
$('s-' + hash).style.display = 'none';
44+
document.getElementById('s-' + hash).style.display = 'none';
4545
}
4646
function updateApprovedSignatures(r) {
4747
var both = r.responseObject();
48-
$('approvedSignatures').value = both[0].join('\n');
49-
$('aclApprovedSignatures').value = both[1].join('\n');
50-
$('dangerousApprovedSignatures').value = both[2].join('\n');
48+
document.getElementById('approvedSignatures').value = both[0].join('\n');
49+
document.getElementById('aclApprovedSignatures').value = both[1].join('\n');
50+
if (document.getElementById('dangerousApprovedSignatures')) {
51+
document.getElementById('dangerousApprovedSignatures').value = both[2].join('\n');
52+
}
5153
}
5254
function approveSignature(signature, hash) {
5355
mgr.approveSignature(signature, function(r) {
@@ -78,12 +80,12 @@ THE SOFTWARE.
7880

7981
function renderPendingClasspathEntries(pendingClasspathEntries) {
8082
if (pendingClasspathEntries.length == 0) {
81-
$('pendingClasspathEntries-none').show();
82-
$('pendingClasspathEntries').childElements().each(function(e){e.remove()});
83-
$('pendingClasspathEntries').hide();
83+
document.getElementById('pendingClasspathEntries-none').style.display = '';
84+
Array.from(document.getElementById('pendingClasspathEntries').children).forEach(function(e){e.remove()});
85+
document.getElementById('pendingClasspathEntries').style.display = 'none';
8486
} else {
85-
$('pendingClasspathEntries-none').hide();
86-
$('pendingClasspathEntries').childElements().each(function(e){e.remove()});
87+
document.getElementById('pendingClasspathEntries-none').style.display = 'none';
88+
Array.from(document.getElementById('pendingClasspathEntries').children).forEach(function(e){e.remove()});
8789
/*
8890
Create a list like:
8991
<p id="pcp-${pcp.hash}">
@@ -92,64 +94,74 @@ THE SOFTWARE.
9294
${pcp.hash} (${pcp.path})
9395
</p>
9496
*/
95-
pendingClasspathEntries.each(function(e) {
96-
var block = new Element('p', { 'id': 'pcp-' + e.hash });
97-
var approveButton = new Element('button', { 'class': 'approve', 'hash': e.hash});
98-
approveButton.insert('Approve');
99-
approveButton.observe('click', function() {
100-
approveClasspathEntry(this.readAttribute('hash'));
97+
pendingClasspathEntries.forEach(function(e) {
98+
var block = document.createElement('p');
99+
block.setAttribute('id', 'pcp-' + e.hash);
100+
var approveButton = document.createElement('button');
101+
approveButton.setAttribute('class', 'approve');
102+
approveButton.setAttribute('hash', e.hash);
103+
approveButton.textContent = 'Approve';
104+
approveButton.addEventListener('click', function() {
105+
approveClasspathEntry(this.getAttribute('hash'));
101106
});
102-
var denyButton = new Element('button', { 'class': 'deny', 'hash': e.hash});
103-
denyButton.insert('Deny');
104-
denyButton.observe('click', function() {
105-
denyClasspathEntry(this.readAttribute('hash'));
107+
var denyButton = document.createElement('button');
108+
denyButton.setAttribute('class', 'deny');
109+
denyButton.setAttribute('hash', e.hash);
110+
denyButton.textContent = 'Deny';
111+
denyButton.addEventListener('click', function() {
112+
denyClasspathEntry(this.getAttribute('hash'));
106113
});
107-
block.insert(approveButton);
108-
block.insert(denyButton);
109-
var code = new Element('code', { 'title': e.hash });
114+
block.appendChild(approveButton);
115+
block.appendChild(denyButton);
116+
var code = document.createElement('code');
117+
code.setAttribute('title', e.hash);
110118
code.textContent = e.path;
111-
block.insert(code);
119+
block.appendChild(code);
112120

113-
$('pendingClasspathEntries').insert(block);
121+
document.getElementById('pendingClasspathEntries').appendChild(block);
114122
});
115-
$('pendingClasspathEntries').show();
123+
document.getElementById('pendingClasspathEntries').style.display = '';
116124
}
117125
}
118126

119127
function renderApprovedClasspathEntries(approvedClasspathEntries) {
120128
if (approvedClasspathEntries.length == 0) {
121-
$('approvedClasspathEntries-none').show();
122-
$('approvedClasspathEntries').childElements().each(function(e){e.remove()});
123-
$('approvedClasspathEntries').hide();
124-
$('approvedClasspathEntries-clear').hide();
129+
document.getElementById('approvedClasspathEntries-none').style.display = '';
130+
Array.from(document.getElementById('approvedClasspathEntries').children).forEach(function(e){e.remove()});
131+
document.getElementById('approvedClasspathEntries').style.display = 'none';
132+
document.getElementById('approvedClasspathEntries-clear').style.display = 'none';
125133
} else {
126-
$('approvedClasspathEntries-none').hide();
127-
$('approvedClasspathEntries').childElements().each(function(e){e.remove()});
134+
document.getElementById('approvedClasspathEntries-none').style.display = 'none';
135+
Array.from(document.getElementById('approvedClasspathEntries').children).forEach(function(e){e.remove()});
128136
/*
129137
Create a list like:
130138
<p id="acp-${acp.hash}">
131139
<button class="delete" onclick="denyApprovedClasspathEntry('${pcp.hash}')">Delete</button>
132140
${acp.hash} (${acp.path})
133141
</p>
134142
*/
135-
approvedClasspathEntries.each(function(e) {
136-
var block = new Element('p', { 'id': 'acp-' + e.hash });
137-
var deleteButton = new Element('button', { 'class': 'delete', 'hash': e.hash});
138-
deleteButton.insert('Delete');
139-
deleteButton.observe('click', function() {
143+
approvedClasspathEntries.forEach(function(e) {
144+
var block = document.createElement('p');
145+
block.setAttribute('id', 'acp-' + e.hash);
146+
var deleteButton = document.createElement('button');
147+
deleteButton.setAttribute('class', 'delete');
148+
deleteButton.setAttribute('hash', e.hash);
149+
deleteButton.textContent = 'Delete';
150+
deleteButton.addEventListener('click', function() {
140151
if (confirm('Really delete this approved classpath entry? Any existing scripts using it will need to be rerun and the entry reapproved.')) {
141-
denyApprovedClasspathEntry(this.readAttribute('hash'));
152+
denyApprovedClasspathEntry(this.getAttribute('hash'));
142153
}
143154
});
144-
block.insert(deleteButton);
145-
var code = new Element('code', { 'title': e.hash });
155+
block.appendChild(deleteButton);
156+
var code = document.createElement('code');
157+
code.setAttribute('title', e.hash);
146158
code.textContent = e.path;
147-
block.insert(code);
159+
block.appendChild(code);
148160

149-
$('approvedClasspathEntries').insert(block);
161+
document.getElementById('approvedClasspathEntries').appendChild(block);
150162
});
151-
$('approvedClasspathEntries').show();
152-
$('approvedClasspathEntries-clear').show();
163+
document.getElementById('approvedClasspathEntries').style.display = '';
164+
document.getElementById('approvedClasspathEntries-clear').style.display = '';
153165
}
154166
}
155167

@@ -179,7 +191,7 @@ THE SOFTWARE.
179191
});
180192
}
181193

182-
Event.observe(window, "load", function(){
194+
window.addEventListener("load", function(){
183195
mgr.getClasspathRenderInfo(function(r) {
184196
renderClasspaths(r);
185197
});
@@ -206,7 +218,7 @@ THE SOFTWARE.
206218
<j:if test="${it.hasDeprecatedApprovedScriptHashes()}">
207219
<p id="deprecated-approvedScripts-clear">
208220
You have <st:out value="${it.countDeprecatedApprovedScriptHashes()}"/> script approvals with deprecated hashes:
209-
<button onclick="if (confirm('Really delete all deprecated approvals? Any existing scripts will need to be requeued and reapproved.')) {mgr.clearDeprecatedApprovedScripts(); $('deprecated-approvedScripts-clear').hide();}">Clear Deprecated Approvals</button>
221+
<button onclick="if (confirm('Really delete all deprecated approvals? Any existing scripts will need to be requeued and reapproved.')) {mgr.clearDeprecatedApprovedScripts(); document.getElementById('deprecated-approvedScripts-clear').style.display = 'none';}">Clear Deprecated Approvals</button>
210222
</p>
211223
<p class="setting-description">
212224
Script approvals are stored in Jenkins as the hashed value of the script. Old approvals were hashed using SHA-1, which is deprecated.
@@ -286,7 +298,7 @@ THE SOFTWARE.
286298
<p id="deprecated-approvedClasspaths-clear">
287299
You have ${it.countDeprecatedApprovedClasspathHashes()} approved classpath entries with deprecated hashes:
288300
<span id="deprecated-approvedClasspaths-clear-btn">
289-
<button onclick="if (confirm('This will be scheduled on a background thread. You can follow the progress in the system log')) {mgr.convertDeprecatedApprovedClasspathEntries(); $('deprecated-approvedClasspaths-clear-btn').hide(); $('deprecated-approvedClasspaths-clear-spinner').show();}">Rehash Deprecated Approvals</button>
301+
<button onclick="if (confirm('This will be scheduled on a background thread. You can follow the progress in the system log')) {mgr.convertDeprecatedApprovedClasspathEntries(); document.getElementById('deprecated-approvedClasspaths-clear-btn').style.display = 'none'; document.getElementById('deprecated-approvedClasspaths-clear-spinner').style.display = '';}">Rehash Deprecated Approvals</button>
290302
</span>
291303
<span id="deprecated-approvedClasspaths-clear-spinner">
292304
<l:icon alt="${%Converting...}" class="${it.spinnerIconClassName} icon-md"/>
@@ -300,14 +312,14 @@ THE SOFTWARE.
300312
<j:choose>
301313
<j:when test="${it.isConvertingDeprecatedApprovedClasspathEntries()}">
302314
<script>
303-
$('deprecated-approvedClasspaths-clear-btn').hide();
304-
$('deprecated-approvedClasspaths-clear-spinner').show();
315+
document.getElementById('deprecated-approvedClasspaths-clear-btn').style.display = 'none';
316+
document.getElementById('deprecated-approvedClasspaths-clear-spinner').style.display = '';
305317
</script>
306318
</j:when>
307319
<j:otherwise>
308320
<script>
309-
$('deprecated-approvedClasspaths-clear-btn').show();
310-
$('deprecated-approvedClasspaths-clear-spinner').hide();
321+
document.getElementById('deprecated-approvedClasspaths-clear-btn').style.display = '';
322+
document.getElementById('deprecated-approvedClasspaths-clear-spinner').style.display = 'none';
311323
</script>
312324
</j:otherwise>
313325
</j:choose>

0 commit comments

Comments
 (0)