diff options
Diffstat (limited to 'web_src/js/features/repo-projects.js')
-rw-r--r-- | web_src/js/features/repo-projects.js | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/web_src/js/features/repo-projects.js b/web_src/js/features/repo-projects.js index 986ada2956..5b3f54f8a6 100644 --- a/web_src/js/features/repo-projects.js +++ b/web_src/js/features/repo-projects.js @@ -1,5 +1,29 @@ const {csrfToken} = window.config; +function moveIssue({item, from, to, oldIndex}) { + const columnCards = to.getElementsByClassName('board-card'); + + const columnSorting = { + issues: [...columnCards].map((card, i) => ({ + issueID: parseInt($(card).attr('data-issue')), + sorting: i + })) + }; + + $.ajax({ + url: `${to.getAttribute('data-url')}/move`, + data: JSON.stringify(columnSorting), + headers: { + 'X-Csrf-Token': csrfToken, + }, + contentType: 'application/json', + type: 'POST', + error: () => { + from.insertBefore(item, from.children[oldIndex]); + } + }); +} + async function initRepoProjectSortable() { const els = document.querySelectorAll('#project-board > .board'); if (!els.length) return; @@ -40,20 +64,8 @@ async function initRepoProjectSortable() { group: 'shared', animation: 150, ghostClass: 'card-ghost', - onAdd: ({item, from, to, oldIndex}) => { - const url = to.getAttribute('data-url'); - const issue = item.getAttribute('data-issue'); - $.ajax(`${url}/${issue}`, { - headers: { - 'X-Csrf-Token': csrfToken, - }, - contentType: 'application/json', - type: 'POST', - error: () => { - from.insertBefore(item, from.children[oldIndex]); - }, - }); - }, + onAdd: moveIssue, + onUpdate: moveIssue, }); } } |