Skip to content

Commit

Permalink
[JENKINS-73951][JENKINS-73952] Improve CSP compatibility (#321)
Browse files Browse the repository at this point in the history
* [JENKINS-73952] Extract inline event handler from SubversionTagAction/tagForm.jelly

* [JENKINS-73951] Extract event handler from SubversionSCM/DescriptorImpl/credentialOK.jelly

* Fix adjunct name

* Address review feedback
  • Loading branch information
yaroslavafenkin authored Oct 17, 2024
1 parent 2eba787 commit b8220b2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
window.addEventListener("DOMContentLoaded", () => {
document.querySelector(".svn-credential-ok-close").addEventListener("click", () => {
window.close();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ THE SOFTWARE.
<p>
${%Authentication was successful. Information is stored in Jenkins now.}
</p>
<input type="button" value="${%Close}" class="yui-button" onclick="window.close()" />
<st:adjunct includes="hudson.scm.SubversionSCM.DescriptorImpl.credential-ok"/>
<button class="jenkins-button svn-credential-ok-close">${%Close}</button>
</l:main-panel>
</l:layout>
</j:jelly>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// update the visual feedback depending on the checkbox state
function updateRow(changeEvent) {
const checkbox = changeEvent.target;
checkbox.parentNode.parentNode.style.color = checkbox.checked ? "inherit" : "grey";

const index = checkbox.getAttribute("data-index");
document.querySelector(`input[name="name${index}"]`).disabled = !checkbox.checked;
}

window.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll(".svn-tagform-tag-checkbox").forEach((checkbox) => {
checkbox.addEventListener("change", updateRow);
});
});
12 changes: 3 additions & 9 deletions src/main/resources/hudson/scm/SubversionTagAction/tagForm.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ THE SOFTWARE.
<j:if test="${it.isTagged()}">
<h2>${%Create more tags}</h2>
</j:if>
<st:adjunct includes="hudson.scm.SubversionTagAction.svn-tagform-update-row"/>
<form action="submit" method="post" enctype="multipart/form-data" name="tag">
<table class="middle-align">
<tr>
Expand All @@ -78,8 +79,8 @@ THE SOFTWARE.
<j:forEach var="m" items="${tags.keySet()}" varStatus="loop">
<tr>
<td><j:if test="${tags.size()!=1}">
<input type="checkbox" name="tag${loop.index}" checked="true"
id="tag${loop.index}" onchange="updateRow(this,${loop.index})" />
<input type="checkbox" name="tag${loop.index}" checked="true" class="svn-tagform-tag-checkbox"
id="tag${loop.index}" data-index="${loop.index}" />
</j:if></td>
<td style="white-space:nowrap;"><label for="tag${loop.index}">
${m.url} (rev.${m.revision})
Expand All @@ -103,13 +104,6 @@ THE SOFTWARE.
</f:entry>
</table>
<f:submit value="${%Tag}" />
<script>
<!-- update the visual feedback depending on the checkbox state -->
function updateRow(e,i) {
e.parentNode.parentNode.style.color = e.checked ? "inherit" : "grey";
$("name"+i).disabled = !e.checked;
}
</script>
</form>
</j:if>
</l:main-panel>
Expand Down

0 comments on commit b8220b2

Please sign in to comment.