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

Disable Create column button while the column name is empty #25192

Merged
merged 12 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
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
2 changes: 1 addition & 1 deletion templates/repo/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<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 data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}" class="ui primary button disabled" id="new_board_submit">{{$.locale.Tr "repo.projects.column.new_submit"}}</button>
</div>
</form>
</div>
Expand Down
54 changes: 37 additions & 17 deletions web_src/js/features/repo-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ function updateIssueCount(cards) {
parent.getElementsByClassName('board-card-cnt')[0].textContent = cnt;
}

function createNewBoard(url, boardTitle, projectColorInput) {
$.ajax({
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 All @@ -17,8 +32,8 @@ function moveIssue({item, from, to, oldIndex}) {
const columnSorting = {
issues: Array.from(columnCards, (card, i) => ({
issueID: parseInt($(card).attr('data-issue')),
sorting: i
}))
sorting: i,
})),
};

$.ajax({
Expand All @@ -31,7 +46,7 @@ function moveIssue({item, from, to, oldIndex}) {
type: 'POST',
error: () => {
from.insertBefore(item, from.children[oldIndex]);
}
},
});
}

Expand Down Expand Up @@ -168,24 +183,29 @@ 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()) {
return;
}
const url = $(this).data('url');
createNewBoard(url, 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('input keyup', (e) => {
puni9869 marked this conversation as resolved.
Show resolved Hide resolved
const boardTitle = $('#new_board');
const projectColorInput = $('#new_board_color_picker');
if (!boardTitle.val()) {
$('#new_board_submit').addClass('disabled');
return;
}
$('#new_board_submit').removeClass('disabled');
if (e.key === 'Enter') {
const url = $(this).data('url');
createNewBoard(url, boardTitle, projectColorInput);
}
});
}

Expand Down