Skip to content

Commit

Permalink
[JENKINS-74110][JENKINS-74109] Extract inline JavaScript (#335)
Browse files Browse the repository at this point in the history
* [JENKINS-74109] Extract inline JavaScript from `AbstractClaimBuildAction/summary.jelly`

* [JENKINS-74109] Extract JavaScript from `AbstractClaimBuildAction/tablerow.jelly`
  • Loading branch information
yaroslavafenkin authored Dec 16, 2024
1 parent 6217bea commit 619f52a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function showPopup() {
var hp = document.getElementById("claimHoverPopup");
hp.style.display = "block";
}

function hidePopup() {
var hp = document.getElementById("claimHoverPopup");
hp.style.display = "none";
}

function display(error) {
var reasonText = document.getElementById("errordesc");
claimBuildAction.getReason(error, function(content) {
reasonText.textContent = content.responseObject();
});
}

Behaviour.specify("A#claim", "AbstractClaimBuildAction_claim", 0, function (element) {
element.addEventListener("click", (event) => {
event.preventDefault();
showPopup();
});
});

Behaviour.specify("A#reassign", "AbstractClaimBuildAction_reassign", 0, function (element) {
element.addEventListener("click", (event) => {
event.preventDefault();
showPopup();
});
});

Behaviour.specify(".claim-hide-popup", "AbstractClaimBuildAction_hide-popup", 0, function (element) {
element.addEventListener("click", (event) => {
hidePopup();
});
});

Behaviour.specify(".claim-bfa-display-error", "AbstractClaimBuildAction_display-bfa-error", 0, function (element) {
element.addEventListener("change", (event) => {
display(event.target.value);
});
});
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<script type="text/javascript">
function ShowPopup(hoveritem) {
var hp = document.getElementById("claimHoverPopup");
hp.style.display = "block";
}

function HidePopup() {
var hp = document.getElementById("claimHoverPopup");
hp.style.display = "none";
var action = <st:bind value="${it}" />;
}

function Display(error) {
var reasonText = document.getElementById("errordesc");
var action = <st:bind value="${it}" />;
action.getReason(error, function(content) {
reasonText.textContent = content.responseObject();
});
}
</script>
<st:bind var="claimBuildAction" value="${it}"/>
<st:adjunct includes="hudson.plugins.claim.AbstractClaimBuildAction.resource"/>

<t:summary icon="symbol-solid/user-doctor plugin-font-awesome-api">
<p>
Expand All @@ -30,7 +12,7 @@
<j:set var="linkWritten" value="false"/>
<j:if test="${it.canClaim()}">
<j:if test="${linkWritten}"><st:nbsp/></j:if>
<a id="claim" href="#" onClick="ShowPopup(this); return false;">
<a id="claim" href="#">
<j:out value="${it.messageProvider.getClaimActionText()}"/>
</a>
<j:set var="linkWritten" value="true"/>
Expand All @@ -44,7 +26,7 @@
</j:if>
<j:if test="${it.canReassign()}">
<j:if test="${linkWritten}"><st:nbsp/></j:if>
<a id="reassign" href="#" onClick="ShowPopup(this); return false;">
<a id="reassign" href="#">
<j:out value="${it.messageProvider.getReassignActionText()}"/>
</a>
<j:set var="linkWritten" value="true"/>
Expand All @@ -67,7 +49,7 @@
</f:entry>
<j:if test="${it.isBFAEnabled()}">
<f:entry title="${%Error}" field="errors" help="/plugin/claim/help-errors.html">
<f:select onChange="Display(this.value);"/>
<f:select clazz="claim-bfa-display-error"/>
</f:entry>
<f:entry title="${%Description}" help="/plugin/claim/help-description.html">
<f:textarea name="errordesc" id="errordesc" value="${it.getReason(it.error)}" readonly="true"/>
Expand All @@ -85,7 +67,8 @@
<f:block>
<div class="jenkins-buttons-row jenkins-buttons-row--equal-width" style="justify-content: right;">
<f:submit value="${%Claim}"/>
<button type="button" name="Cancel" formNoValidate="formNoValidate" class="jenkins-button jenkins-submit-button}" onClick="HidePopup();">
<button type="button" name="Cancel" formNoValidate="formNoValidate"
class="jenkins-button jenkins-submit-button claim-hide-popup">
${%Cancel}
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function showPopup(hoveritem) {
var row = hoveritem.closest('tr');
var hp = row.querySelector(".claimHoverPopup");
if (hp) {
hp.style.display = "block";
} else {
console.error("Claim popup not found in the same row.");
}
}

function hidePopup(hoveritem) {
var row = hoveritem.closest('tr');
var hp = row.querySelector(".claimHoverPopup");
if (hp) {
hp.style.display = "none";
} else {
console.error("Claim popup not found in the same row.");
}
}

function display(hoveritem, error) {
var row = hoveritem.closest('tr');
var reasonText = row.querySelector('#errordesc');
claimBuildAction.getReason(error, function(content) {
reasonText.textContent = content.responseObject();
});
}

Behaviour.specify("A#claim", "AbstractClaimBuildAction_claim", 0, function (element) {
element.addEventListener("click", (event) => {
event.preventDefault();
showPopup(event.target.closest("a#claim"));
});
});

Behaviour.specify("A#reassign", "AbstractClaimBuildAction_reassign", 0, function (element) {
element.addEventListener("click", (event) => {
event.preventDefault();
showPopup(event.target.closest("a#reassign"));
});
});

Behaviour.specify(".claim-hide-popup", "AbstractClaimBuildAction_hide-popup", 0, function (element) {
element.addEventListener("click", (event) => {
hidePopup(event.target);
});
});

Behaviour.specify(".claim-bfa-display-error", "AbstractClaimBuildAction_display-bfa-error", 0, function (element) {
element.addEventListener("change", (event) => {
display(event.target, event.target.value);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,13 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
<j:if test="${it.isColumnDisplayed()}">
<td class="pane">
<script type="text/javascript">
function ShowPopup(hoveritem) {
var row = hoveritem.closest('tr');
var hp = row.querySelector(".claimHoverPopup");
if (hp) {
hp.style.display = "block";
} else {
console.error("Claim popup not found in the same row.");
}
}

function HidePopup(hoveritem) {
var row = hoveritem.closest('tr');
var hp = row.querySelector(".claimHoverPopup");
if (hp) {
hp.style.display = "none";
} else {
console.error("Claim popup not found in the same row.");
}
var action = <st:bind value="${it}" />;
}

function Display(hoveritem, error) {
var row = hoveritem.closest('tr');
var reasonText = row.querySelector('#errordesc');
var action = <st:bind value="${it}" />;
action.getReason(error, function(content) {
reasonText.textContent = content.responseObject();
});
}
</script>
<st:bind var="claimBuildAction" value="${it}"/>
<st:adjunct includes="hudson.plugins.claim.AbstractClaimBuildAction.tablerow-resource"/>

<j:set var="linkWritten" value="false"/>
<j:if test="${it.canClaim()}">
<j:if test="${linkWritten}"><st:nbsp/></j:if>
<a id="claim" href="#" onClick="ShowPopup(this); return false;">
<a id="claim" href="#">
<j:out value="${it.messageProvider.getClaimActionText()}"/>
</a>
<j:set var="linkWritten" value="true"/>
Expand All @@ -51,7 +22,7 @@
</j:if>
<j:if test="${it.canReassign()}">
<j:if test="${linkWritten}"><st:nbsp/></j:if>
<a id="reassign" href="#" onClick="ShowPopup(this); return false;">
<a id="reassign" href="#">
<j:out value="${it.messageProvider.getReassignActionText()}"/>
</a>
<j:set var="linkWritten" value="true"/>
Expand All @@ -65,7 +36,7 @@
</f:entry>
<j:if test="${it.isBFAEnabled()}">
<f:entry title="${%Error}" field="errors" help="/plugin/claim/help-errors.html">
<f:select onChange="Display(this, this.value);"/>
<f:select clazz="claim-bfa-display-error"/>
</f:entry>
<f:entry title="${%Description}" help="/plugin/claim/help-description.html">
<f:textarea name="errordesc" id="errordesc" value="${it.getReason(it.error)}" readonly="true"/>
Expand All @@ -83,7 +54,8 @@
<f:block>
<div class="jenkins-buttons-row jenkins-buttons-row--equal-width" style="justify-content: right;">
<f:submit value="${%Claim}"/>
<button type="button" name="Cancel" formNoValidate="formNoValidate" class="jenkins-button jenkins-submit-button}" onClick="HidePopup(this);">
<button type="button" name="Cancel" formNoValidate="formNoValidate"
class="jenkins-button jenkins-submit-button claim-hide-popup">
${%Cancel}
</button>
</div>
Expand Down

0 comments on commit 619f52a

Please sign in to comment.