-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticleJS.js
More file actions
139 lines (97 loc) · 3.56 KB
/
articleJS.js
File metadata and controls
139 lines (97 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function handleFormSubmit(event) {
event.preventDefault();
const data = new FormData(event.target);
const formJSON = Object.fromEntries(data.entries());
//const results = document.querySelector('.results pre');
//results.innerText = JSON.stringify(formJSON, null, 2);
//console.log(JSON.stringify(formJSON, null, 2));
//const newUserData = JSON.stringify(formJSON, null, 2);
// console.log(newUserData);
var myTextPath = formJSON.title;
myTextPath = myTextPath.replace(/ /g, "_");
console.log(formJSON.title + ", " + formJSON.username + ", " + formJSON.veri + ", " + myTextPath + ", " + formJSON.atype + ", " + formJSON.texts + ", " + formJSON.myFile);
//var dump = formJSON.artist + ", " + formJSON.albumName + ", " + formJSON.genre + ", " + formJSON.date + ", " + formJSON.condition1 + ", " + formJSON.condition2 + ", " + formJSON.number + ", " + formJSON.meeting;
const order = {"article_title": formJSON.title,
"author_username": formJSON.username,
"author_verification": formJSON.veri,
"article_text_path": myTextPath,
"article_type": formJSON.atype,
"article_texts": formJSON.texts,
"article_img": formJSON.myFile
}
console.log(order);
const sendData = JSON.stringify(order, null, 2);
console.log(sendData);
sendOrder(sendData);
}
const form = document.querySelector('.order-form');
form.addEventListener('submit', handleFormSubmit);
// function previewImage() {
// var file = document.getElementById("myfile").files
// if (file.length > 0) {
// var fileReader = new FileReader()
// fileReader.onload = function (event) {
// document.getElementById("preview").setAttribute("src", event.target.result)
// }
// fileReader.readAsDataURL(file[0])
// var fileName = document.getElementById('myfile').value;
// }
// var fu1 = document.getElementById("myfile");
// finalFileName = "/" + fu1.value.split(/(\\|\/)/g).pop();
//alert("You selected " + finalFileName );
// }
//var orderResponse = "";
//var pickup_address = "";
//var destination_address = "";
// var destCoord = "";
// var pickupCoord = "";
// var timeToDest = "";
// var timeToPickup = "";
// var vehicleCoord = "";
// var vehicleID = "";
function previewImage(){
document.getElementById("preview").src = document.getElementById("myFile").value;
}
function sendOrder(newUserData) {
const url = "http://165.22.183.12/createdArticle";
var info = newUserData;
const params = {
headers: {
"content-type": "application/json; charset=UTF-8",
},
body: info,
method: "POST",
};
fetch(url, params)
.then((data) => {
return data.json();
})
.then((result) => {
//console.log(result);
orderResponse = result.data;
console.log(orderResponse);
// test1 = result.data.destCoord;
window.location.href = "http://165.22.183.12/pagesPrev.html";
})
.catch((error) => console.log(error));
}
// function clearUser(){
// localStorage.clear();
// }
// function redirect(){
// if(localStorage.getItem("username") === null)
// {
// window.location.href = "http://146.190.113.162/homepage.html";
// }
// else
// {
// window.location.href = "http://146.190.113.162/welcomePage.html";
// }
// }
//function loginCheck()
//{
// if (localStorage.getItem("username") === null) {
// alert("You need to login!")
// window.location.href = "";
// }
//}