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][JENKINS-71051][JENKINS-71048] Un-inline 'Build Now' JS #7635

Merged
merged 14 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 4 additions & 9 deletions core/src/main/resources/lib/hudson/project/configurable.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<!-- Displayed by projects (assignable to ParameterizedJobMixIn.ParameterizedJob) which can be configured and built. -->
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
<j:if test="${it.buildable}">
<j:set var="id" value="${h.generateId()}"/>
daniel-beck marked this conversation as resolved.
Show resolved Hide resolved
<l:task href="${url}/build?delay=0sec" icon="icon-clock icon-md" onclick="${it.parameterized?null:'return build_' + id + '(this)'}" permission="${it.BUILD}" post="${!it.parameterized}" title="${it.buildNowText}"/>
<script>
function build_${id}(a) {
new Ajax.Request(a.href);
hoverNotification('${%Build scheduled}',a.parentNode);
return false;
}
</script>
<st:adjunct includes="lib.hudson.project.configurable.adjunct"/>
<div id="callback${id}" data-callback="lib_hudson_project_configurable_build_now_callback" data-success="${%Build scheduled}" data-parameterized="${it.parameterized}" />
<l:task href="${url}/build?delay=0sec" icon="icon-clock icon-md" permission="${it.BUILD}" post="${!it.parameterized}" callbackElementId="callback${id}" title="${it.buildNowText}"/>
</j:if>
<j:choose>
<j:when test="${h.hasPermission(it,it.CONFIGURE)}">
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/resources/lib/hudson/project/configurable/adjunct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
window["lib_hudson_project_configurable_build_now_callback"] = function (
el,
ev
) {
let parameterized = el.dataset.parameterized;
let success = el.dataset.success;
if (parameterized === "false") {
daniel-beck marked this conversation as resolved.
Show resolved Hide resolved
new Ajax.Request(ev.target.href);
hoverNotification(success, ev.target.parentNode);
ev.preventDefault();
}
};
21 changes: 10 additions & 11 deletions core/src/main/resources/lib/layout/task.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,18 @@ THE SOFTWARE.
(onclick supersedes this except in the context menu.)
(since 1.512)
</st:attribute>
<st:attribute name="onclick" deprecated="true">
Onclick inline JS handler. Deprecated, use callbackElementId instead.
</st:attribute>
<st:attribute name="confirmationMessage">
Message to use for confirmation, if requested; defaults to title.
(since 1.512)
</st:attribute>
<st:attribute name="callbackElementId">
This is the ID attribute of an HTML element that will be looked up to invoke a callback when clicked.
The HTML element is expected to have the attribute data-callback (a global function).
The global function will be invoked with the HTML element and event as arguments.
</st:attribute>
</st:documentation>

<!--
Expand Down Expand Up @@ -149,16 +157,6 @@ THE SOFTWARE.
<l:icon src="${icon}" />
</j:set>
${taskTags!=null and attrs.contextMenu!='false' ? taskTags.add(href, iconSrc, iconXml, title, post == 'true', requiresConfirmation == 'true') : null}
<j:set var="id" value="${h.generateId()}"/>
<j:if test="${attrs.onclick == null and post and not requiresConfirmation}">
<script>
function postRequest_${id}(a) {
new Ajax.Request(a.href);
hoverNotification('${%Done.}', a.parentNode);
return false;
}
</script>
</j:if>

<j:choose>
<j:when test="${requiresConfirmation and not attrs.onClick}">
Expand All @@ -171,12 +169,13 @@ THE SOFTWARE.
</j:when>

<j:otherwise>
<a href="${href}" class="task-link ${isCurrent ? 'task-link--active' : ''}" onclick="${attrs.onclick ?: (post ? 'return postRequest_' + id + '(this)' : null)}">
<a href="${href}" class="task-link task-link-no-confirm ${isCurrent ? 'task-link--active' : ''}" data-success="${%Done.}" data-post="${attrs.post}" data-callback="${attrs.callbackElementId}" onclick="${attrs.onclick}">
<span class="task-icon-link">
<l:icon src="${icon}" />
</span>
<span class="task-link-text">${title}</span>
</a>
<st:adjunct includes="lib.layout.task.task" />
daniel-beck marked this conversation as resolved.
Show resolved Hide resolved
</j:otherwise>
</j:choose>
</span>
Expand Down
27 changes: 27 additions & 0 deletions core/src/main/resources/lib/layout/task/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Behaviour.specify("a.task-link-no-confirm", "task-link", 0, function (el) {
if (el.onclick !== null) {
return;
}

let post = el.dataset.post;
let callbackElementId = el.dataset.callback;
let success = el.dataset.success;
let href = el.href;

if (callbackElementId !== undefined) {
el.onclick = function (ev) {
let callbackElement = document.getElementById(callbackElementId);
let callback = callbackElement.dataset.callback;
window[callback](callbackElement, ev);
};
return;
}

if (post === "true") {
el.onclick = function (ev) {
new Ajax.Request(href);
hoverNotification(success, el.parentNode);
ev.preventDefault();
};
}
});