Skip to content
Merged
4 changes: 2 additions & 2 deletions templates/repo/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
</div>

<div class="text right actions">
<button class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</button>
<button data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}" class="ui primary button" id="new_board_submit">{{$.locale.Tr "repo.projects.column.new_submit"}}</button>
<button class="ui cancel button board-cancel-button">{{$.locale.Tr "settings.cancel"}}</button>
<button data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}" class="ui primary button disabled new-board-create" id="new_board_submit">{{$.locale.Tr "repo.projects.column.new_submit"}}</button>
</div>
</form>
</div>
Expand Down
45 changes: 31 additions & 14 deletions web_src/js/features/repo-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ function updateIssueCount(cards) {
parent.getElementsByClassName('board-card-cnt')[0].textContent = cnt;
}

function createNewBoard(boardTitle, projectColorInput) {
$.ajax({
url: $(this).data('url'),
data: JSON.stringify({title: boardTitle.val(), color: projectColorInput.val()}),
headers: {
'X-Csrf-Token': csrfToken,
},
contentType: 'application/json',
method: 'POST',
}).done(() => {
boardTitle.closest('form').removeClass('dirty');
window.location.reload();
});
}
function moveIssue({item, from, to, oldIndex}) {
const columnCards = to.getElementsByClassName('board-card');
updateIssueCount(from);
Expand Down Expand Up @@ -168,24 +182,27 @@ export function initRepoProject() {
});
});

$('#new_board_submit').on('click', function (e) {
$('#new_board_submit').on('click', (e) => {
e.preventDefault();

const boardTitle = $('#new_board');
const projectColorInput = $('#new_board_color_picker');
if (boardTitle.val().length < 1) {
return false;
}
createNewBoard(boardTitle, projectColorInput);
});

$.ajax({
url: $(this).data('url'),
data: JSON.stringify({title: boardTitle.val(), color: projectColorInput.val()}),
headers: {
'X-Csrf-Token': csrfToken,
},
contentType: 'application/json',
method: 'POST',
}).done(() => {
boardTitle.closest('form').removeClass('dirty');
window.location.reload();
});
$('.new-board').on('keyup', (e) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use input instead.

Copy link
Member Author

@puni9869 puni9869 Jun 12, 2023

Choose a reason for hiding this comment

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

Are you referring to this $('<selector>').input((e) => {}).

I didn't find any api for this event in jquery docs https://api.jquery.com/category/events/
https://api.jquery.com/category/events/keyboard-events/

Please guide me.

Copy link
Contributor

Choose a reason for hiding this comment

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

input is the modern event, you do: on('input', ...)

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event

For example, right click, paste doesn't trigger 'keyup' but it triggers 'input'.

const boardTitle = $('#new_board');
const projectColorInput = $('#new_board_color_picker');
if (boardTitle.val().length < 1) {
$('#new_board_submit').addClass('disabled');
return false;
}
$(`#new_board_submit`).removeClass('disabled');
if (e.key === 'Enter' || e.keyCode === 13) {
createNewBoard(boardTitle, projectColorInput);
}
});
}

Expand Down