-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
184 lines (166 loc) · 5.96 KB
/
script.js
File metadata and controls
184 lines (166 loc) · 5.96 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// 072623
// for changing car color in new paint job page
const currentSelectedColor = document.getElementById('current-select');
const targetSelectedColor = document.getElementById('target-select');
const currentSelectedImage = document.getElementById('current-car');
const targetSelectedImage = document.getElementById('target-car');
// to load data in the shop performance part
document.addEventListener("DOMContentLoaded", function() {
updateTotal();
});
function submitData(plateNum, currColor, targColor) {
$(document).ready(function() {
var data = {
action: "delete",
plateNum: plateNum,
currColor: currColor,
targColor: targColor
};
$.ajax({
url: '/includes/function.php',
type: 'POST',
data: data,
success: function(response) {
//alert(response);
if (response === "Job removed from the queue.") {
//document.getElementById(plateNum).style.display = "none";
$(".job-row").each(function() {
if ($(this).find("td:first").text() === plateNum) {
$(this).hide();
return false; // Exit the loop
}
});
$(".job-row2").each(function() {
if ($(this).find("td:first").text() === plateNum) {
$(this).hide();
return false; // Exit the loop
}
});
updateTotal();
}
else {
alert("Cannot be removed yet.");
}
}
});
})
}
function updateTotal() {
const total = document.querySelector('.perf-num');
const red = document.querySelector('.perf-red');
const blue = document.querySelector('.perf-blue');
const green = document.querySelector('.perf-green');
let r = g = b = t = 0;
$(document).ready(function() {
$.ajax({
url: '/includes/function.php',
type: 'POST',
data: { action: "update" },
dataType: 'json',
success: function(response) {
console.log(response); // yung json with count and target color
for (let i = 0; i < response.length; i++) {
const count = parseInt(response[i].count);
const targColor = response[i].targColor;
if (targColor === "Red") {
r = count;
} else if (targColor === "Green") {
g = count;
} else if (targColor === "Blue"){
b = count;
}
console.log("Count: " + count + ", targColor: " + targColor);
t = r+g+b;
// Update the HTML elements only if they exist to prevent null error
if (total) total.innerHTML = t;
if (red) red.innerHTML = r;
if (green) green.innerHTML = g;
if (blue) blue.innerHTML = b;
}
}
});
})
}
// const form = document.querySelector('.form');
// const jobsTable = document.querySelector('.table-body');
// form.addEventListener('submit', event => {
// event.preventDefault(); // prevent the page to refresh after submitting
// const formData = new FormData(form);
// //console.log(formData.get('platenum'));
// const data = Object.fromEntries(formData);
// fetch('https://reqres.in/api/users', { // adds the data to this server
// method: 'POST',
// headers: {
// "Content-Type": "application/json"
// },
// body: JSON.stringify(data)
// })
// .then(res => {
// console.log(res);
// return res.json();
// })
// .then(data => {
// // const tableData = "";
// // data.map(item =>{
// // tableData += `
// // <tr>
// // <td>${item.plateNum}</td>
// // <td>${item.currColor}</td>
// // <td>${item.targColor}</td>
// // <td>Mark as Completed</td>
// // </tr>
// // `;
// // });
// // document.getElementById("table-body").innerHTML = tableData;
// console.log("ADDED?");
// })
// .catch(error => console.log(error));
// });
// changing car color for current color option
currentSelectedColor.addEventListener('change', function() {
let selectedValue = currentSelectedColor.value;
let imageUrl;
switch(selectedValue){
case 'red':
imageUrl = '/images/Red.png';
console.log("Red Car");
break;
case 'green':
imageUrl = '/images/Green.png';
console.log("Green Car");
break;
case 'blue':
imageUrl = '/images/Blue.png';
console.log("Blue Car");
break;
default:
imageUrl = '/images/Default.png';
console.log("Default Car");
break;
}
currentSelectedImage.src = imageUrl;
});
// changing car color for target color option
targetSelectedColor.addEventListener('change', function() {
let selectedValue = targetSelectedColor.value;
let imageUrl;
switch(selectedValue){
case 'red':
imageUrl = '/images/Red.png';
console.log("Red Car");
break;
case 'green':
imageUrl = '/images/Green.png';
console.log("Green Car");
break;
case 'blue':
imageUrl = '/images/Blue.png';
console.log("Blue Car");
break;
default:
imageUrl = '/images/Default.png';
console.log("Default Car");
break;
}
targetSelectedImage.src = imageUrl;
});