-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Minor
-
Component/s: _unsorted
Problem
== Inline Script Block
Line: 71
----
<script>
(function(Q){
var toggleHelpText = function(instanceInput) {
const hostingType = Q(instanceInput).first().find('select[name="hosting"]')[0].value;
const $fieldCloudHelperWrapper = Q(instanceInput).first().find('.cloud-instance-help-header').parent().parent();
const $fieldServerHelperWrapper = Q(instanceInput).first().find('.server-instance-help-header').parent().parent();
if(hostingType === '${descriptor.cloudHostingTypeName}'){
$fieldCloudHelperWrapper.show();
$fieldServerHelperWrapper.hide();
} else if(hostingType === '${descriptor.serverHostingTypeName}'){
$fieldCloudHelperWrapper.hide();
$fieldServerHelperWrapper.show();
}
};
var hideServerAddressInput = function (instanceInput) {
var hostingType = Q(instanceInput).first().find('select[name="hosting"]')[0].value;
const $fieldWrapper = Q(instanceInput).first().find('input[name="_.serverAddress"]').parent().parent();
if(hostingType === '${descriptor.cloudHostingTypeName}'){
$fieldWrapper.hide();
} else if(hostingType === '${descriptor.serverHostingTypeName}'){
$fieldWrapper.show();
}
toggleHelpText(instanceInput);
};
var hideServerAddressInputs = function(){
Q('div[name="serverInstances"]').each(function(){
hideServerAddressInput(this);
toggleHelpText(this);
});
};
var observeNewInstance = new MutationObserver(function () {
var lastInstanceAdded = Q('select[name="hosting"]').last();
Q(lastInstanceAdded).on('change',function(e){
var serverInstance = Q(e.currentTarget).first().parents('div[name="serverInstances"]').first();
hideServerAddressInput(serverInstance);
});
toggleHelpText(Q('div[name="serverInstances"]').last());
observeNewInstance.disconnect();
});
var observeHostings = function() {
hideServerAddressInputs();
Q('select[name="hosting"]').on('change',function(e){
var serverInstance = Q(e.currentTarget).first().parents('div[name="serverInstances"]').first();
hideServerAddressInput(serverInstance);
});
var addInstanceButton = Q('div[name="serverInstances"]').first().parent().find('button').last();
Q(addInstanceButton).click(function () {
// When adding this event, it will stay on top of the click events stack for this button.
// Once clicked, this event will trigger first and the new server instance will not be there.
// So there is a need to use a mutation observer in order to wait that a new server instance is
// created and added to the Dom.
observeNewInstance.observe(document.querySelector('div[name="serverInstances"]').parentNode, {
childList: true,
subtree: true
});
});
var testConnectionButton = Q('.test-connection-button-wrapper button');
Q(testConnectionButton).click(function(evt) {
Q(evt.target).parents('.test-connection-button-wrapper').find('.error,.ok').remove();
});
};
Q(window).load(function() {
observeHostings();
});
})(jQuery);
</script>
----
Solution
https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks