@@ -348,39 +348,46 @@ class IssueForm extends Component {
348348 * Creates an ajax request and sets the state with the result
349349 */
350350 getFormData ( ) {
351- $ . ajax ( this . props . DataURL , {
352- dataType : 'json' ,
353- success : function ( data ) {
354- let newIssue = ! data . issueData . issueID ;
355- let formData = data . issueData ;
356- // ensure that if the user is at multiple sites and
357- // its a new issue, the centerID (which is a dropdown)
358- // is set to the empty option instead of an array of
359- // the user's sites.
360- if ( newIssue ) {
361- formData . centerID = null ;
362- } else {
363- // if we edit an issue
364- // a NULL centerID (= All Sites) is converted to the ALL Sites option
365- if ( formData . centerID == null ) {
366- formData . centerID = 'all' ;
351+ fetch ( this . props . DataURL , {
352+ method : 'GET' ,
353+ } ) . then ( ( response ) => {
354+ if ( response . status !== 200 ) {
355+ console . error ( response . status ) ;
356+ return ;
357+ }
358+
359+ response . json ( ) . then (
360+ ( data ) => {
361+ let newIssue = ! data . issueData . issueID ;
362+ let formData = data . issueData ;
363+ // ensure that if the user is at multiple sites and
364+ // its a new issue, the centerID (which is a dropdown)
365+ // is set to the empty option instead of an array of
366+ // the user's sites.
367+ if ( newIssue ) {
368+ formData . centerID = null ;
369+ } else {
370+ // if we edit an issue
371+ // a NULL centerID (= All Sites) is converted to the ALL Sites option
372+ if ( formData . centerID == null ) {
373+ formData . centerID = 'all' ;
374+ }
367375 }
368- }
369376
370- this . setState ( {
371- Data : data ,
372- isLoaded : true ,
373- issueData : data . issueData ,
374- formData : formData ,
375- isNewIssue : ! data . issueData . issueID ,
376- } ) ;
377- } . bind ( this ) ,
378- error : function ( err ) {
379- this . setState ( {
380- error : 'An error occurred when loading the form!\n Error: ' +
381- err . status + ' (' + err . statusText + ')' ,
382- } ) ;
383- } . bind ( this ) ,
377+ this . setState ( {
378+ Data : data ,
379+ isLoaded : true ,
380+ issueData : data . issueData ,
381+ formData : formData ,
382+ isNewIssue : ! data . issueData . issueID ,
383+ } ) ;
384+ }
385+ ) ;
386+ } ) . catch ( ( error ) => {
387+ console . error ( error ) ;
388+ this . setState ( {
389+ loadError : 'An error occurred when loading the form!' ,
390+ } ) ;
384391 } ) ;
385392 }
386393
@@ -415,15 +422,16 @@ class IssueForm extends Component {
415422 }
416423 }
417424
418- $ . ajax ( {
419- type : 'POST' ,
420- url : this . props . action ,
421- data : formData ,
422- cache : false ,
423- dataType : 'json' ,
424- contentType : false ,
425- processData : false ,
426- success : function ( data ) {
425+ fetch ( this . props . action , {
426+ method : 'POST' ,
427+ body : formData ,
428+ } ) . then ( ( response ) => {
429+ if ( response . status !== 200 ) {
430+ console . error ( response . status ) ;
431+ return ;
432+ }
433+
434+ response . json ( ) . then ( ( data ) => {
427435 let msgType = 'success' ;
428436 let message = this . state . isNewIssue ?
429437 'You will be redirected to main page in 2 seconds!' :
@@ -433,15 +441,14 @@ class IssueForm extends Component {
433441 submissionResult : 'success' ,
434442 issueID : data . issueID ,
435443 } ) ;
436- } . bind ( this ) ,
437- error : function ( err ) {
438- console . error ( err ) ;
439- this . setState ( { submissionResult : 'error' } ) ;
440- let msgType = 'error' ;
441- let message = err . responseJSON . message || 'Failed to submit issue :(' ;
442-
443- this . showAlertMessage ( msgType , message ) ;
444- } . bind ( this ) ,
444+ } ) ;
445+ } ) . catch ( ( error ) => {
446+ console . error ( error ) ;
447+
448+ this . setState ( { submissionResult : 'error' } ) ;
449+ let msgType = 'error' ;
450+ let message = 'Failed to submit issue :(' ;
451+ this . showAlertMessage ( msgType , message ) ;
445452 } ) ;
446453 }
447454
0 commit comments