Skip to content

Commit 3282bdc

Browse files
committed
[Publication] Jquery usage cleaning
1 parent b153c2e commit 3282bdc

File tree

5 files changed

+146
-140
lines changed

5 files changed

+146
-140
lines changed

modules/publication/jsx/projectFields.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,23 @@ class ProjectFormFields extends React.Component {
141141
confirmButtonText: 'Yes, I am sure!',
142142
cancelButtonText: 'No, cancel it!',
143143
}, function(willDelete) {
144-
if (willDelete) {
144+
if (willDelete) {
145145
let url = loris.BaseURL
146146
+ '/publication/ajax/FileDelete.php?uploadID='
147147
+ uploadID;
148-
$.ajax(
149-
url,
150-
{
151-
method: 'DELETE',
152-
success: function() {
153-
self.props.fetchData();
154-
},
155-
});
148+
149+
fetch(url, {
150+
method: 'DELETE',
151+
}).then((response) => {
152+
if (response.status !== 200) {
153+
console.error(response.status);
154+
return;
155+
}
156+
157+
self.props.fetchData();
158+
}).catch((error) => {
159+
console.error(error);
160+
});
156161
}
157162
});
158163
}

modules/publication/jsx/publicationIndex.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ class PublicationIndex extends React.Component {
4141
* Fetch data
4242
*/
4343
fetchData() {
44-
$.ajax(this.props.DataURL, {
44+
fetch(this.props.DataURL, {
4545
method: 'GET',
46-
dataType: 'json',
47-
success: function(data) {
48-
this.setState({
49-
Data: data,
50-
isLoaded: true,
51-
});
52-
}.bind(this),
53-
error: function(error) {
54-
console.error(error);
55-
},
56-
});
46+
}).then(
47+
(response) => {
48+
if (response.status !== 200) {
49+
console.error(response.status);
50+
return;
51+
}
52+
53+
response.json().then(
54+
(data) => this.setState({
55+
Data: data,
56+
isLoaded: true,
57+
})
58+
);
59+
}).catch((error) => console.error(error));
5760
}
5861

5962
/**
@@ -186,7 +189,7 @@ class PublicationIndex extends React.Component {
186189
}
187190
}
188191

189-
$(function() {
192+
document.addEventListener('DOMContentLoaded', (event) => {
190193
const publicationIndex = (
191194
<div className="page-publications">
192195
<PublicationIndex DataURL={`${loris.BaseURL}/publication/?format=json`}/>

modules/publication/jsx/uploadForm.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,26 @@ class PublicationUploadForm extends React.Component {
3838
*/
3939
fetchData() {
4040
let self = this;
41-
$.ajax(this.props.DataURL, {
42-
dataType: 'json',
43-
success: function(data) {
44-
self.setState({
41+
42+
fetch(this.props.DataURL, {
43+
method: 'GET',
44+
}).then((response) => {
45+
if (response.status !== 200) {
46+
console.error(response.status);
47+
return;
48+
}
49+
50+
response.json().then(
51+
(data) => self.setState({
4552
Data: data,
4653
isLoaded: true,
47-
});
48-
},
49-
error: function(data, errorCode, errorMsg) {
50-
console.error(data, errorCode, errorMsg);
51-
self.setState({
52-
loadError: 'An error occurred when loading the form!',
53-
});
54-
},
54+
})
55+
);
56+
}).catch((error) => {
57+
console.error(error);
58+
self.setState({
59+
loadError: 'An error occurred when loading the form!',
60+
});
5561
});
5662
}
5763

@@ -155,41 +161,35 @@ class PublicationUploadForm extends React.Component {
155161
}
156162
}
157163

158-
$.ajax({
159-
type: 'POST',
160-
url: this.props.action,
161-
data: formObj,
162-
cache: false,
163-
contentType: false,
164-
processData: false,
165-
success: function() {
166-
// reset form data
167-
this.setState({
168-
formData: {},
169-
numFiles: 0,
170-
});
171-
swal.fire(
172-
{
173-
title: 'Submission Successful!',
174-
type: 'success',
175-
},
176-
function() {
177-
window.location.replace(loris.BaseURL + '/publication/');
178-
}
179-
);
180-
}.bind(this),
181-
error: function(jqXHR) {
182-
console.error(jqXHR);
183-
let resp = '';
184-
try {
185-
resp = JSON.parse(jqXHR.responseText).message;
186-
} catch (e) {
187-
console.error(e);
164+
fetch(this.props.action, {
165+
method: 'POST',
166+
body: formObj,
167+
}).then((response) => {
168+
if (response.status !== 200) {
169+
console.error(response.status);
170+
return;
171+
}
172+
173+
// reset form data
174+
this.setState({
175+
formData: {},
176+
numFiles: 0,
177+
});
178+
179+
swal.fire(
180+
{
181+
title: 'Submission Successful!',
182+
type: 'success',
183+
},
184+
function() {
185+
window.location.replace(loris.BaseURL + '/publication/');
188186
}
189-
swal.fire('Something went wrong!', resp, 'error');
190-
},
187+
);
188+
}).catch((error) => {
189+
console.error(error);
190+
swal.fire('Something went wrong!', '', 'error');
191191
});
192-
}
192+
}
193193

194194
/**
195195
* Renders the React component.

modules/publication/jsx/viewProject.js

Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -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

modules/publication/jsx/viewProjectIndex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ViewProject from './viewProject';
22

33
const args = QueryString.get(document.currentScript.src);
44

5-
$(function() {
5+
document.addEventListener('DOMContentLoaded', (event) => {
66
const viewProject = (
77
<div className="page-edit-form">
88
<div className="row">

0 commit comments

Comments
 (0)