@@ -11,7 +11,7 @@ import {htmlEscape} from 'escape-goat';
11
11
import { showTemporaryTooltip } from '../modules/tippy.js' ;
12
12
import { confirmModal } from './comp/ConfirmModal.js' ;
13
13
import { showErrorToast } from '../modules/toast.js' ;
14
- import { request , POST } from '../modules/fetch.js' ;
14
+ import { request , POST , GET } from '../modules/fetch.js' ;
15
15
import '../htmx.js' ;
16
16
17
17
const { appUrl, appSubUrl, csrfToken, i18n} = window . config ;
@@ -37,11 +37,10 @@ export function initHeadNavbarContentToggle() {
37
37
}
38
38
39
39
export function initFootLanguageMenu ( ) {
40
- function linkLanguageAction ( ) {
40
+ async function linkLanguageAction ( ) {
41
41
const $this = $ ( this ) ;
42
- $ . get ( $this . data ( 'url' ) ) . always ( ( ) => {
43
- window . location . reload ( ) ;
44
- } ) ;
42
+ await GET ( $this . data ( 'url' ) ) ;
43
+ window . location . reload ( ) ;
45
44
}
46
45
47
46
$ ( '.language-menu a[lang]' ) . on ( 'click' , linkLanguageAction ) ;
@@ -309,27 +308,26 @@ export function initGlobalLinkActions() {
309
308
310
309
dialog . modal ( {
311
310
closable : false ,
312
- onApprove ( ) {
311
+ onApprove : async ( ) => {
313
312
if ( $this . data ( 'type' ) === 'form' ) {
314
313
$ ( $this . data ( 'form' ) ) . trigger ( 'submit' ) ;
315
314
return ;
316
315
}
317
-
318
- const postData = {
319
- _csrf : csrfToken ,
320
- } ;
316
+ const postData = new FormData ( ) ;
321
317
for ( const [ key , value ] of Object . entries ( dataArray ) ) {
322
318
if ( key && key . startsWith ( 'data' ) ) {
323
- postData [ key . slice ( 4 ) ] = value ;
319
+ postData . append ( key . slice ( 4 ) , value ) ;
324
320
}
325
321
if ( key === 'id' ) {
326
- postData [ 'id' ] = value ;
322
+ postData . append ( 'id' , value ) ;
327
323
}
328
324
}
329
325
330
- $ . post ( $this . data ( 'url' ) , postData ) . done ( ( data ) => {
326
+ const response = await POST ( $this . data ( 'url' ) , { data : postData } ) ;
327
+ if ( response . ok ) {
328
+ const data = await response . json ( ) ;
331
329
window . location . href = data . redirect ;
332
- } ) ;
330
+ }
333
331
}
334
332
} ) . modal ( 'show' ) ;
335
333
}
0 commit comments