Skip to content

Commit

Permalink
Getting there...
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Faracik committed Aug 16, 2021
1 parent 88f4c62 commit 956ff65
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 365 deletions.
33 changes: 17 additions & 16 deletions core/src/main/resources/hudson/model/View/newJob.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ THE SOFTWARE.
<l:layout type="one-column" permission="${permission}" title="${%NewJob(it.newPronoun)}">

<l:js src="jsbundles/add-item.js" />
<l:css src="jsbundles/add-itaem.css" />

<l:main-panel>
<h1>${%New item}</h1>

<div class="" id="add-item-panel" style="display: none;">
<div class="jenkins-form" id="add-item-panel">
<div >
<div>
<form method="post" action="createItem" name="createItem" id="createItem">

<div class="jenkins-form-item add-item-name">
<div class="jenkins-form-item">
<label for="name" class="jenkins-form-label">${%ItemName.label}</label>
<input name="name" class="jenkins-input" id="name" data-valid="false" type="text" tabindex="0" />
<div class="input-help">&#187; ${%ItemName.help}</div>
Expand All @@ -48,21 +47,23 @@ THE SOFTWARE.
<div id="itemtype-required" class="input-validation-message input-message-disabled">&#187; ${%ItemType.validation.required}</div>
</div>

<div id="items" class="categories flat" role="radiogroup" aria-labelledby="Items" data-valid="false" />

<j:if test="${!empty(app.itemMap)}">
<div class="item-copy">
<p class="description"></p>
<div class="add-item-copy jenkins-radio">
<input class="jenkins-radio__input" type="radio" name="mode" value="copy" />
<label class="jenkins-radio__label">${%CopyOption.label}</label>
<p class="jenkins-radio__description">${%CopyOption.description}</p>
<div>
<s:textbox id="from" data-valid="false" name="from" placeholder="${%CopyOption.placeholder}" field="copyNewItemFrom"/>
<div class="jenkins-form-item">
<div id="items" class="categories flat" role="radiogroup" aria-labelledby="Items" data-valid="false" />

<j:if test="${!empty(app.itemMap)}">
<div class="item-copy">
<p class="description"></p>
<div class="add-item-copy jenkins-radio">
<input class="jenkins-radio__input" id="copy" type="radio" name="mode" value="copy" />
<label class="jenkins-radio__label" for="copy">${%CopyOption.label}</label>
<p class="jenkins-radio__description">${%CopyOption.description}</p>
<div class="jenkins-radio__content">
<s:textbox id="from" data-valid="false" name="from" placeholder="${%CopyOption.placeholder}" field="copyNewItemFrom"/>
</div>
</div>
</div>
</div>
</j:if>
</j:if>
</div>

<div class="footer">
<div class="btn-decorator">
Expand Down
28 changes: 13 additions & 15 deletions war/src/main/js/add-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $.when(getItems()).done(function(data) {
}

function isItemNameEmpty() {
var itemName = $('input[name="name"]', '#createItem').val();
var itemName = $('#name', '#createItem').val();
return (itemName === '') ? true : false;
}

Expand Down Expand Up @@ -135,7 +135,6 @@ $.when(getItems()).done(function(data) {
setFieldValidationStatus('from', false);
}


//////////////////////////////////
// Draw functions

Expand All @@ -144,7 +143,7 @@ $.when(getItems()).done(function(data) {
var $items = $('<div/>');
var $catHeader = $('<div />');
var title = '<label class="jenkins-form-label">' + category.name + '</label>';
var description = '<p>' + category.description + '</p>';
var description = '<p class="jenkins-form-description">' + category.description + '</p>';

// Add items
$.each(category.items, function(i, elem) {
Expand Down Expand Up @@ -272,22 +271,21 @@ $.when(getItems()).done(function(data) {
$("#add-item-panel").find("#name").focus();

// Init NameField
$('input[name="name"]', '#createItem').on("blur input", function() {
$('#name', '#createItem').on("blur input", function() {

if (!isItemNameEmpty()) {
var itemName = $('input[name="name"]', '#createItem').val();
var itemName = $('#name', '#createItem').val();

console.log(itemName)

$.get("checkJobName", { value: itemName }).done(function(data) {
var message = parseResponseFromCheckJobName(data);

console.log(message)

if (message !== '') {
activateValidationMessage('#itemname-invalid', '.add-item-name', message);
activateValidationMessage('#itemname-invalid', '#name', message);
} else {
cleanValidationMessages('.add-item-name');
showInputHelp('.add-item-name');
cleanValidationMessages('#name');
showInputHelp('#name');
setFieldValidationStatus('name', true);
if (getFormValidationStatus()) {
enableSubmit(true);
Expand All @@ -297,8 +295,8 @@ $.when(getItems()).done(function(data) {
} else {
enableSubmit(false);
setFieldValidationStatus('name', false);
cleanValidationMessages('.add-item-name');
activateValidationMessage('#itemname-required', '.add-item-name');
cleanValidationMessages('#name');
activateValidationMessage('#itemname-required', '#name');
}
});

Expand All @@ -311,7 +309,7 @@ $.when(getItems()).done(function(data) {
$('#createItem').find('input[type="radio"][value="copy"]').prop('checked', true);
setFieldValidationStatus('from', true);
if (!getFieldValidationStatus('name')) {
activateValidationMessage('#itemname-required', '.add-item-name');
activateValidationMessage('#itemname-required', '#name');
setTimeout(function() {
$('input[name="name"][type="text"]', '#createItem').focus();
}, 400);
Expand All @@ -328,11 +326,11 @@ $.when(getItems()).done(function(data) {
if (!getFormValidationStatus()) {
event.preventDefault();
if (!getFieldValidationStatus('name')) {
activateValidationMessage('#itemname-required', '.add-item-name');
activateValidationMessage('#itemname-required', '#name');
$('input[name="name"][type="text"]', '#createItem').focus();
} else {
if (!getFieldValidationStatus('items') && !getFieldValidationStatus('from')) {
activateValidationMessage('#itemtype-required', '.add-item-name');
activateValidationMessage('#itemtype-required', '#name');
$('input[name="name"][type="text"]', '#createItem').focus();
}
}
Expand Down
Loading

0 comments on commit 956ff65

Please sign in to comment.