@@ -24,7 +24,7 @@ import {initRepoPullRequestCommitStatus} from './repo-issue-pr-status.js';
24
24
import { hideElem , showElem } from '../utils/dom.js' ;
25
25
import { getComboMarkdownEditor , initComboMarkdownEditor } from './comp/ComboMarkdownEditor.js' ;
26
26
import { attachRefIssueContextPopup } from './contextpopup.js' ;
27
- import { POST } from '../modules/fetch.js' ;
27
+ import { POST , GET } from '../modules/fetch.js' ;
28
28
29
29
const { csrfToken} = window . config ;
30
30
@@ -83,7 +83,7 @@ export function initRepoCommentForm() {
83
83
await POST ( form . attr ( 'action' ) , { data : params } ) ;
84
84
window . location . reload ( ) ;
85
85
} catch ( error ) {
86
- console . error ( 'Error:' , error ) ;
86
+ console . error ( error ) ;
87
87
}
88
88
} else if ( editMode === '' ) {
89
89
$selectBranch . find ( '.ui .branch-name' ) . text ( selectedValue ) ;
@@ -355,23 +355,26 @@ async function onEditContent(event) {
355
355
const input = $ ( `<input id="${ data . uuid } " name="files" type="hidden">` ) . val ( data . uuid ) ;
356
356
$dropzone . find ( '.files' ) . append ( input ) ;
357
357
} ) ;
358
- this . on ( 'removedfile' , ( file ) => {
358
+ this . on ( 'removedfile' , async ( file ) => {
359
359
if ( disableRemovedfileEvent ) return ;
360
360
$ ( `#${ file . uuid } ` ) . remove ( ) ;
361
361
if ( $dropzone . attr ( 'data-remove-url' ) && ! fileUuidDict [ file . uuid ] . submitted ) {
362
- $ . post ( $dropzone . attr ( 'data-remove-url' ) , {
363
- file : file . uuid ,
364
- _csrf : csrfToken ,
365
- } ) ;
362
+ try {
363
+ await POST ( $dropzone . attr ( 'data-remove-url' ) , { data : new URLSearchParams ( { file : file . uuid } ) } ) ;
364
+ } catch ( error ) {
365
+ console . error ( error ) ;
366
+ }
366
367
}
367
368
} ) ;
368
369
this . on ( 'submit' , ( ) => {
369
370
$ . each ( fileUuidDict , ( fileUuid ) => {
370
371
fileUuidDict [ fileUuid ] . submitted = true ;
371
372
} ) ;
372
373
} ) ;
373
- this . on ( 'reload' , ( ) => {
374
- $ . getJSON ( $editContentZone . attr ( 'data-attachment-url' ) , ( data ) => {
374
+ this . on ( 'reload' , async ( ) => {
375
+ try {
376
+ const response = await GET ( $editContentZone . attr ( 'data-attachment-url' ) ) ;
377
+ const data = await response . json ( ) ;
375
378
// do not trigger the "removedfile" event, otherwise the attachments would be deleted from server
376
379
disableRemovedfileEvent = true ;
377
380
dz . removeAllFiles ( true ) ;
@@ -390,7 +393,9 @@ async function onEditContent(event) {
390
393
const input = $ ( `<input id="${ attachment . uuid } " name="files" type="hidden">` ) . val ( attachment . uuid ) ;
391
394
$dropzone . find ( '.files' ) . append ( input ) ;
392
395
}
393
- } ) ;
396
+ } catch ( error ) {
397
+ console . error ( error ) ;
398
+ }
394
399
} ) ;
395
400
} ,
396
401
} ) ;
@@ -406,22 +411,25 @@ async function onEditContent(event) {
406
411
}
407
412
} ;
408
413
409
- const saveAndRefresh = ( dz ) => {
414
+ const saveAndRefresh = async ( dz ) => {
410
415
showElem ( $renderContent ) ;
411
416
hideElem ( $editContentZone ) ;
412
- $ . post ( $editContentZone . attr ( 'data-update-url' ) , {
413
- _csrf : csrfToken ,
414
- content : comboMarkdownEditor . value ( ) ,
415
- context : $editContentZone . attr ( 'data-context' ) ,
416
- files : dz . files . map ( ( file ) => file . uuid ) ,
417
- } , ( data ) => {
417
+
418
+ try {
419
+ const params = new URLSearchParams ( {
420
+ content : comboMarkdownEditor . value ( ) ,
421
+ context : $editContentZone . attr ( 'data-context' ) ,
422
+ } ) ;
423
+ for ( const file of dz . files ) params . append ( 'files[]' , file . uuid ) ;
424
+
425
+ const response = await POST ( $editContentZone . attr ( 'data-update-url' ) , { data : params } ) ;
426
+ const data = await response . json ( ) ;
418
427
if ( ! data . content ) {
419
428
$renderContent . html ( $ ( '#no-content' ) . html ( ) ) ;
420
429
$rawContent . text ( '' ) ;
421
430
} else {
422
431
$renderContent . html ( data . content ) ;
423
432
$rawContent . text ( comboMarkdownEditor . value ( ) ) ;
424
-
425
433
const refIssues = $renderContent . find ( 'p .ref-issue' ) ;
426
434
attachRefIssueContextPopup ( refIssues ) ;
427
435
}
@@ -442,7 +450,9 @@ async function onEditContent(event) {
442
450
}
443
451
initMarkupContent ( ) ;
444
452
initCommentContent ( ) ;
445
- } ) ;
453
+ } catch ( error ) {
454
+ console . error ( error ) ;
455
+ }
446
456
} ;
447
457
448
458
if ( ! $editContentZone . html ( ) ) {
0 commit comments