@@ -2,31 +2,31 @@ import $ from 'jquery';
2
2
import { useLightTextOnBackground } from '../utils/color.js' ;
3
3
import tinycolor from 'tinycolor2' ;
4
4
import { createSortable } from '../modules/sortable.js' ;
5
-
6
- const { csrfToken} = window . config ;
5
+ import { POST , DELETE , PUT } from '../modules/fetch.js' ;
7
6
8
7
function updateIssueCount ( cards ) {
9
8
const parent = cards . parentElement ;
10
9
const cnt = parent . getElementsByClassName ( 'issue-card' ) . length ;
11
10
parent . getElementsByClassName ( 'project-column-issue-count' ) [ 0 ] . textContent = cnt ;
12
11
}
13
12
14
- function createNewColumn ( url , columnTitle , projectColorInput ) {
15
- $ . ajax ( {
16
- url,
17
- data : JSON . stringify ( { title : columnTitle . val ( ) , color : projectColorInput . val ( ) } ) ,
18
- headers : {
19
- 'X-Csrf-Token' : csrfToken ,
20
- } ,
21
- contentType : 'application/json' ,
22
- method : 'POST' ,
23
- } ) . done ( ( ) => {
13
+ async function createNewColumn ( url , columnTitle , projectColorInput ) {
14
+ try {
15
+ await POST ( url , {
16
+ data : {
17
+ title : columnTitle . val ( ) ,
18
+ color : projectColorInput . val ( ) ,
19
+ } ,
20
+ } ) ;
21
+ } catch ( error ) {
22
+ console . error ( error ) ;
23
+ } finally {
24
24
columnTitle . closest ( 'form' ) . removeClass ( 'dirty' ) ;
25
25
window . location . reload ( ) ;
26
- } ) ;
26
+ }
27
27
}
28
28
29
- function moveIssue ( { item, from, to, oldIndex} ) {
29
+ async function moveIssue ( { item, from, to, oldIndex} ) {
30
30
const columnCards = to . getElementsByClassName ( 'issue-card' ) ;
31
31
updateIssueCount ( from ) ;
32
32
updateIssueCount ( to ) ;
@@ -38,18 +38,14 @@ function moveIssue({item, from, to, oldIndex}) {
38
38
} ) ) ,
39
39
} ;
40
40
41
- $ . ajax ( {
42
- url : `${ to . getAttribute ( 'data-url' ) } /move` ,
43
- data : JSON . stringify ( columnSorting ) ,
44
- headers : {
45
- 'X-Csrf-Token' : csrfToken ,
46
- } ,
47
- contentType : 'application/json' ,
48
- type : 'POST' ,
49
- error : ( ) => {
50
- from . insertBefore ( item , from . children [ oldIndex ] ) ;
51
- } ,
52
- } ) ;
41
+ try {
42
+ await POST ( `${ to . getAttribute ( 'data-url' ) } /move` , {
43
+ data : columnSorting ,
44
+ } ) ;
45
+ } catch ( error ) {
46
+ console . error ( error ) ;
47
+ from . insertBefore ( item , from . children [ oldIndex ] ) ;
48
+ }
53
49
}
54
50
55
51
async function initRepoProjectSortable ( ) {
@@ -67,20 +63,21 @@ async function initRepoProjectSortable() {
67
63
ghostClass : 'card-ghost' ,
68
64
delayOnTouchOnly : true ,
69
65
delay : 500 ,
70
- onSort : ( ) => {
66
+ onSort : async ( ) => {
71
67
boardColumns = mainBoard . getElementsByClassName ( 'project-column' ) ;
72
68
for ( let i = 0 ; i < boardColumns . length ; i ++ ) {
73
69
const column = boardColumns [ i ] ;
74
70
if ( parseInt ( $ ( column ) . data ( 'sorting' ) ) !== i ) {
75
- $ . ajax ( {
76
- url : $ ( column ) . data ( 'url' ) ,
77
- data : JSON . stringify ( { sorting : i , color : rgbToHex ( $ ( column ) . css ( 'backgroundColor' ) ) } ) ,
78
- headers : {
79
- 'X-Csrf-Token' : csrfToken ,
80
- } ,
81
- contentType : 'application/json' ,
82
- method : 'PUT' ,
83
- } ) ;
71
+ try {
72
+ await PUT ( $ ( column ) . data ( 'url' ) , {
73
+ data : {
74
+ sorting : i ,
75
+ color : rgbToHex ( $ ( column ) . css ( 'backgroundColor' ) ) ,
76
+ } ,
77
+ } ) ;
78
+ } catch ( error ) {
79
+ console . error ( error ) ;
80
+ }
84
81
}
85
82
}
86
83
} ,
@@ -118,26 +115,27 @@ export function initRepoProject() {
118
115
setLabelColor ( projectHeader , rgbToHex ( boardColumn . css ( 'backgroundColor' ) ) ) ;
119
116
}
120
117
121
- $ ( this ) . find ( '.edit-project-column-button' ) . on ( 'click' , function ( e ) {
118
+ $ ( this ) . find ( '.edit-project-column-button' ) . on ( 'click' , async function ( e ) {
122
119
e . preventDefault ( ) ;
123
120
124
- $ . ajax ( {
125
- url : $ ( this ) . data ( 'url' ) ,
126
- data : JSON . stringify ( { title : projectTitleInput . val ( ) , color : projectColorInput . val ( ) } ) ,
127
- headers : {
128
- 'X-Csrf-Token' : csrfToken ,
129
- } ,
130
- contentType : 'application/json' ,
131
- method : 'PUT' ,
132
- } ) . done ( ( ) => {
121
+ try {
122
+ await PUT ( $ ( this ) . data ( 'url' ) , {
123
+ data : {
124
+ title : projectTitleInput . val ( ) ,
125
+ color : projectColorInput . val ( ) ,
126
+ } ,
127
+ } ) ;
128
+ } catch ( error ) {
129
+ console . error ( error ) ;
130
+ } finally {
133
131
projectTitleLabel . text ( projectTitleInput . val ( ) ) ;
134
132
projectTitleInput . closest ( 'form' ) . removeClass ( 'dirty' ) ;
135
133
if ( projectColorInput . val ( ) ) {
136
134
setLabelColor ( projectHeader , projectColorInput . val ( ) ) ;
137
135
}
138
136
boardColumn . attr ( 'style' , `background: ${ projectColorInput . val ( ) } !important` ) ;
139
137
$ ( '.ui.modal' ) . modal ( 'hide' ) ;
140
- } ) ;
138
+ }
141
139
} ) ;
142
140
} ) ;
143
141
@@ -146,19 +144,16 @@ export function initRepoProject() {
146
144
const showButton = $ ( boardColumn ) . find ( '.default-project-column-show' ) ;
147
145
const commitButton = $ ( this ) . find ( '.actions > .ok.button' ) ;
148
146
149
- $ ( commitButton ) . on ( 'click' , ( e ) => {
147
+ $ ( commitButton ) . on ( 'click' , async ( e ) => {
150
148
e . preventDefault ( ) ;
151
149
152
- $ . ajax ( {
153
- method : 'POST' ,
154
- url : $ ( showButton ) . data ( 'url' ) ,
155
- headers : {
156
- 'X-Csrf-Token' : csrfToken ,
157
- } ,
158
- contentType : 'application/json' ,
159
- } ) . done ( ( ) => {
150
+ try {
151
+ await POST ( $ ( showButton ) . data ( 'url' ) ) ;
152
+ } catch ( error ) {
153
+ console . error ( error ) ;
154
+ } finally {
160
155
window . location . reload ( ) ;
161
- } ) ;
156
+ }
162
157
} ) ;
163
158
} ) ;
164
159
@@ -167,19 +162,16 @@ export function initRepoProject() {
167
162
const deleteColumnButton = deleteColumnModal . find ( '.actions > .ok.button' ) ;
168
163
const deleteUrl = $ ( this ) . attr ( 'data-url' ) ;
169
164
170
- deleteColumnButton . on ( 'click' , ( e ) => {
165
+ deleteColumnButton . on ( 'click' , async ( e ) => {
171
166
e . preventDefault ( ) ;
172
167
173
- $ . ajax ( {
174
- url : deleteUrl ,
175
- headers : {
176
- 'X-Csrf-Token' : csrfToken ,
177
- } ,
178
- contentType : 'application/json' ,
179
- method : 'DELETE' ,
180
- } ) . done ( ( ) => {
168
+ try {
169
+ await DELETE ( deleteUrl ) ;
170
+ } catch ( error ) {
171
+ console . error ( error ) ;
172
+ } finally {
181
173
window . location . reload ( ) ;
182
- } ) ;
174
+ }
183
175
} ) ;
184
176
} ) ;
185
177
@@ -190,7 +182,7 @@ export function initRepoProject() {
190
182
if ( ! columnTitle . val ( ) ) {
191
183
return ;
192
184
}
193
- const url = $ ( this ) . data ( ' url') ;
185
+ const url = e . target . getAttribute ( 'data- url') ;
194
186
createNewColumn ( url , columnTitle , projectColorInput ) ;
195
187
} ) ;
196
188
}
0 commit comments