@@ -59,26 +59,18 @@ class ViewProject extends React.Component {
5959 }
6060 }
6161
62- $ . ajax ( {
63- type : 'POST' ,
64- url : this . props . action ,
65- data : formObj ,
66- cache : false ,
67- contentType : false ,
68- processData : false ,
69- success : function ( ) {
70- swal . fire ( 'Edit Successful!' , '' , 'success' ) ;
71- } ,
72- error : function ( jqXHR ) {
73- console . error ( jqXHR ) ;
74- let resp = 'Something went wrong!' ;
75- try {
76- resp = JSON . parse ( jqXHR . responseText ) . message ;
77- } catch ( e ) {
78- console . error ( e ) ;
79- }
80- swal . fire ( 'Edit failed!' , resp , 'error' ) ;
81- } ,
62+ fetch ( this . props . action , {
63+ method : 'POST' ,
64+ body : formObj ,
65+ } ) . then ( ( response ) => {
66+ if ( response . status !== 200 ) {
67+ console . error ( response . status ) ;
68+ return ;
69+ }
70+ swal . fire ( 'Edit Successful!' , '' , 'success' ) ;
71+ } ) . catch ( ( error ) => {
72+ console . error ( error ) ;
73+ swal . fire ( 'Edit failed!' , 'Something went wrong!' , 'error' ) ;
8274 } ) ;
8375 }
8476
@@ -87,60 +79,66 @@ class ViewProject extends React.Component {
8779 */
8880 fetchData ( ) {
8981 let self = this ;
90- $ . ajax ( this . props . DataURL , {
91- dataType : 'json' ,
92- success : function ( data ) {
93- let formData = {
94- title : data . title ,
95- description : data . description ,
96- leadInvestigator : data . leadInvestigator ,
97- leadInvestigatorEmail : data . leadInvestigatorEmail ,
98- notifyLead : false ,
99- status : data . status ,
100- voiFields : data . voi ,
101- keywords : data . keywords ,
102- collaborators : data . collaborators ,
103- usersWithEditPerm : data . usersWithEditPerm ,
104- rejectedReason : data . rejectedReason ,
105- } ;
106- // set formdata for file meta data
107- if ( data . files ) {
108- data . files . forEach ( function ( f ) {
109- let existFileFlag = 'existingUpload_' ;
110- let pubType = existFileFlag
111- + 'publicationType_'
112- + f . PublicationUploadID ;
113- let pubCit = existFileFlag
114- + 'publicationCitation_'
115- + f . PublicationUploadID ;
116- let pubVer = existFileFlag
117- + 'publicationVersion_'
118- + f . PublicationUploadID ;
119- formData [ pubType ] = f . PublicationUploadTypeID ;
120- formData [ pubCit ] = f . Citation ;
121- formData [ pubVer ] = f . Version ;
122- } ) ;
123- }
82+ fetch ( this . props . DataURL , {
83+ method : 'GET' ,
84+ } ) . then ( ( response ) => {
85+ if ( response . status !== 200 ) {
86+ console . error ( response . status ) ;
87+ return ;
88+ }
12489
125- self . setState ( {
126- formData : formData ,
127- users : data . users ,
128- statusOpts : data . statusOpts ,
129- userCanEdit : data . userCanEdit ,
130- allVOIs : data . allVOIs ,
131- allKWs : data . allKWs ,
132- allCollabs : data . allCollabs ,
133- uploadTypes : data . uploadTypes ,
134- files : data . files ,
135- isLoaded : true ,
136- } ) ;
137- } ,
138- error : function ( error , errorCode , errorMsg ) {
139- console . error ( error , errorCode , errorMsg ) ;
140- self . setState ( {
141- error : 'An error occurred when loading the form!' ,
90+ response . json ( ) . then (
91+ ( data ) => {
92+ let formData = {
93+ title : data . title ,
94+ description : data . description ,
95+ leadInvestigator : data . leadInvestigator ,
96+ leadInvestigatorEmail : data . leadInvestigatorEmail ,
97+ notifyLead : false ,
98+ status : data . status ,
99+ voiFields : data . voi ,
100+ keywords : data . keywords ,
101+ collaborators : data . collaborators ,
102+ usersWithEditPerm : data . usersWithEditPerm ,
103+ rejectedReason : data . rejectedReason ,
104+ } ;
105+ // set formdata for file meta data
106+ if ( data . files ) {
107+ data . files . forEach ( function ( f ) {
108+ let existFileFlag = 'existingUpload_' ;
109+ let pubType = existFileFlag
110+ + 'publicationType_'
111+ + f . PublicationUploadID ;
112+ let pubCit = existFileFlag
113+ + 'publicationCitation_'
114+ + f . PublicationUploadID ;
115+ let pubVer = existFileFlag
116+ + 'publicationVersion_'
117+ + f . PublicationUploadID ;
118+ formData [ pubType ] = f . PublicationUploadTypeID ;
119+ formData [ pubCit ] = f . Citation ;
120+ formData [ pubVer ] = f . Version ;
121+ } ) ;
122+ }
123+
124+ self . setState ( {
125+ formData : formData ,
126+ users : data . users ,
127+ statusOpts : data . statusOpts ,
128+ userCanEdit : data . userCanEdit ,
129+ allVOIs : data . allVOIs ,
130+ allKWs : data . allKWs ,
131+ allCollabs : data . allCollabs ,
132+ uploadTypes : data . uploadTypes ,
133+ files : data . files ,
134+ isLoaded : true ,
135+ } ) ;
142136 } ) ;
143- } ,
137+ } ) . catch ( ( error ) => {
138+ console . error ( error ) ;
139+ self . setState ( {
140+ error : 'An error occurred when loading the form!' ,
141+ } ) ;
144142 } ) ;
145143 }
146144
0 commit comments