Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-60866] Advanced button, build health, confirmation link, URI encoding monitor #5515

Merged
merged 5 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Behaviour.specify('#URICheckEncodingMonitor-message', 'URICheckEncodingMonitor', 0, function(element) {
var url = element.getAttribute('data-url');
var params = {value : '\u57f7\u4e8b'};
var checkAjax = new Ajax.Updater(
'URICheckEncodingMonitor-message', url,
{
method: 'get', parameters: params
}
);
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:if test="${it.checkEnabled}">
<script>
var url="${rootURL}/${it.url}/checkURIEncoding";
var params = {value : '\u57f7\u4e8b'};
var checkAjax = new Ajax.Updater(
'message', url,
{
method: 'get', parameters: params
}
);
</script>
<span id="message"></span>
<div id="URICheckEncodingMonitor-message" data-url="${rootURL}/${it.url}/checkURIEncoding"/>
<st:adjunct includes="jenkins.diagnostics.URICheckEncodingMonitor.adjunct"/>
</j:if>
</j:jelly>
11 changes: 1 addition & 10 deletions core/src/main/resources/lib/form/advanced.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,7 @@ THE SOFTWARE.
<d:invokeBody/>
</div></div>
<j:if test="${!customizedFields.isEmpty()}">
<script>
{
var span = $$('${id}');
if (span != null) {
span.style.display = '';
} else if (console &amp;&amp; console.log) {
console.log('no element ${id} for ${customizedFields}');
}
}
</script>
<div class="advanced-customized-fields-info" data-id="${id}" data-customized-fields="${customizedFields}"/>
</j:if>
</div>
</j:jelly>
11 changes: 11 additions & 0 deletions core/src/main/resources/lib/form/advanced/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ Behaviour.specify("INPUT.advanced-button", 'advanced', 0, function(e) {
});
e = null; // avoid memory leak
});

Behaviour.specify('.advanced-customized-fields-info', 'advanced', 0, function(element) {
var id = element.getAttribute('data-id');
var span = $(id)
if (span != null) {
span.style.display = '';
} else if (console && console.log) {
var customizedFields = element.getAttribute('data-customized-fields');
console.log('no element ' + id + ' for ' + customizedFields);
}
});
6 changes: 3 additions & 3 deletions core/src/main/resources/lib/form/validateButton.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ THE SOFTWARE.
</st:documentation>
<f:entry>
<div style="float:right">
<input type="button" value="${title}" class="yui-button validate-button ${attrs.clazz}"
<input type="button" value="${title}" class="yui-button validate-button ${attrs.clazz} Behaviour-validateButton"
data-validate-button-descriptor-url="${descriptor.descriptorFullUrl}"
data-validate-button-method="${method}"
data-validate-button-with="${with}"
onclick="safeValidateButton(this)" />
data-validate-button-with="${with}" />
</div>
<div style="display:none;">
<img src="${imagesURL}/spinner.gif" /> ${attrs.progress}
</div>
<div><!-- this is where the error message goes --></div>
<st:adjunct includes="lib.form.validateButton.adjunct"/>
</f:entry>
</j:jelly>
3 changes: 3 additions & 0 deletions core/src/main/resources/lib/form/validateButton/adjunct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Behaviour.specify('.Behaviour-validateButton', 'Behaviour-validateButton', 0, function(element) {
element.onclick = function() { safeValidateButton(this); };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Compared to current behavior, this could be executed after another script that is taken care of the existing onClick and wrap it, to have 2 listeners. Leading to erasing the previously (other) registered listener.

I am not aware of any of those for validateButton.onClick in Jenkins from memory, but if that could trigger someone's memory, that could be nice :)

Example of wrapping behavior: UploadedKeyStoreSource/config.jelly#L50-L55, AFAICT this one is executed after "inline" (like current) and Behaviour (proposed one).

});
3 changes: 0 additions & 3 deletions core/src/main/resources/lib/hudson/buildHealth.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ THE SOFTWARE.
<x:element name="${useTdElement!=null?'td':'div'}">
<x:attribute name="data">${buildHealth.score}</x:attribute>
<x:attribute name="class">healthReport</x:attribute>
<x:attribute name="onmouseover">this.className='healthReport hover';return true;
</x:attribute>
<x:attribute name="onmouseout">this.className='healthReport';return true;</x:attribute>
<j:if test="${buildHealth!=null}">
<j:if test="${iconSizeClass == null}">
<j:choose>
Expand Down
19 changes: 2 additions & 17 deletions core/src/main/resources/lib/layout/confirmationLink.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ THE SOFTWARE.
A CSS class to use to style the link.
</st:attribute>
</st:documentation>
<j:set var="id" value="${h.generateId()}"/>
<a href="#" class="${class}" onclick="confirmPOST_${id}(${post ? 'true' : 'false'}, '${h.jsStringEscape(attrs.href)}', '${h.jsStringEscape(message)}')"><d:invokeBody/></a>
<script>
function confirmPOST_${id}(post, href, message) {
if (confirm(message)) {
var form = document.createElement('form');
form.setAttribute('method', post ? 'POST' : 'GET');
form.setAttribute('action', href);
if (post) {
crumb.appendToForm(form);
}
document.body.appendChild(form);
form.submit();
}
return false;
}
</script>
<a href="#" class="${class} confirmation-link" data-post="${post}" data-url="${attrs.href}" data-message="${message}"><d:invokeBody/></a>
<st:adjunct includes="lib.layout.confirmationLink.adjunct "/>
</j:jelly>
18 changes: 18 additions & 0 deletions core/src/main/resources/lib/layout/confirmationLink/adjunct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Behaviour.specify("A.confirmation-link", 'confirmation-link', 0, function (element) {
element.onclick = function(event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for validateButton

var post = element.getAttribute('data-post');
var href = element.getAttribute('data-url');
var message = element.getAttribute('data-message');
if (confirm(message)) {
var form = document.createElement('form');
form.setAttribute('method', (post === "true") ? 'POST' : 'GET');
form.setAttribute('action', href);
if (post) {
crumb.appendToForm(form);
}
document.body.appendChild(form);
form.submit();
}
return false;
};
});
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/model/ManagementLinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void links() throws Exception {

for (int i=0; ; i++) {
HtmlPage page = wc.goTo("manage");
List<?> anchors = DomNodeUtil.selectNodes(page, "//div[contains(@class,'jenkins-section__item')]/a[not(@onclick)]");
List<?> anchors = DomNodeUtil.selectNodes(page, "//div[contains(@class,'jenkins-section__item')]/a[not(contains(@class,'confirmation-link'))]");
assertTrue(anchors.size()>=8);
if (i==anchors.size()) return; // done

Expand Down
3 changes: 0 additions & 3 deletions test/src/test/java/lib/layout/ConfirmationLinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ private void checkRegularCasePost(TestRootAction testParams) throws Exception {
testParams.paramPost = "true";
assertMethodPostAfterClick();

testParams.paramPost = "TruE";
daniel-beck marked this conversation as resolved.
Show resolved Hide resolved
assertMethodPostAfterClick();

testParams.paramPost = false;
assertMethodGetAfterClick();

Expand Down