-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_maint.js
More file actions
177 lines (143 loc) · 5.29 KB
/
script_maint.js
File metadata and controls
177 lines (143 loc) · 5.29 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
// MAINTENANCE_PAGE
var isLoggedIn = localStorage.getItem("isLoggedIn");
// If user is not logged in, redirect to login page
if (!isLoggedIn) {
alert("You are not logged in. Redirecting to login page...");
window.location.href = "Login.html";
}
var isAccessLevel = localStorage.getItem("accessLevel");
if (isAccessLevel === 3) {
alert("You are not cleared to be here. Redirecting to initial menu...");
window.location.href = "index.html";
}
var deepLookupButton = document.getElementById("deepLookupButton");
var redirect_employees = document.getElementById("toEmployees");
var redirect_programs = document.getElementById("toPrograms");
var redirect_areas = document.getElementById("toAreas");
var backButton = document.getElementById("backButton");
if (deepLookupButton) {
deepLookupButton.addEventListener("click", function() {
window.location.href = "maintenanceLookup.html";
});
}
if (redirect_employees) {
redirect_employees.addEventListener("click", function() {
window.location.href = "maintenancePage/employees.html";
});
}
if (redirect_programs) {
redirect_programs.addEventListener("click", function() {
window.location.href = "maintenancePage/programs.html";
});
}
if (redirect_areas) {
redirect_areas.addEventListener("click", function() {
window.location.href = "maintenancePage/areas.html";
});
}
if (backButton) {
backButton.addEventListener("click", function() {
window.location.href = "index.html";
});
}
// EXPORT DB DATA
var exportEmployeeListButton = document.getElementById("exportEmployeeListButton");
var exportProgramAreasButton = document.getElementById("exportProgramAreasButton");
if (exportEmployeeListButton) {
exportEmployeeListButton.addEventListener("click", function() {
// get file type
let file_type = $('#file_type_e').val();
console.log("beginning export of employee_list as file type:", file_type);
// get list of employees
const file_content = ""; // TODO: insert file content
downloadFile(file_type, file_content, "employee_list");
});
}
if (exportProgramAreasButton) {
exportProgramAreasButton.addEventListener("click", function() {
// get file type
let file_type = $('#file_type_a').val();
console.log("beginning export of program_areas as file type:", file_type);
// get list of program areas
const file_content = ""; // TODO: insert file content
downloadFile(file_type, file_content, "program_areas");
});
}
function downloadFile(file_type, content, src) {
if (file_type === "TXT") {
const link = document.createElement("a");
const file = new Blob([content], {type: "text/plain"});
link.href = URL.createObjectURL(file);
link.download = src+".txt";
link.click();
URL.revokeObjectURL(link.href);
console.log("download of "+src+" complete");
return;
}
if (file_type === "XML") {
let parsedContent = (content) => {
// add parsed content, merging content where relevant
let xml_str = "<span></span>";
const parser = new DOMParser();
const doc = parser.parseFromString(xml_str, "application/xml");
// parse failed
if (doc.querySelector("parseerror")) {
console.log("xml parse failed. no download was made.");
return -1;
}
// serialize
const serializer = new XMLSerializer();
return serializer.serializeToString(doc);
};
// if parseerror happens, parsedContent will return -1
if (parsedContent === -1) {return;}
const link = document.createElement("a");
const file = new Blob([parsedContent], {type: "text/xml"});
link.href = URL.createObjectURL(file);
link.download = src+".xml";
link.click();
URL.revokeObjectURL(link.href);
console.log("download of "+src+" complete");
return;
}
if (file_type === "JSON") {
console.log("not yet ready; no download has occurred");
return;
}
}
// MAINTENANCE LOOKUP
var backButtonM = document.getElementById("backButtonM");
if (backButtonM) {
backButtonM.addEventListener("click", function() {
window.location.href = "maintenancePage.html";
});
}
var lookupButton = document.getElementById("lookupButton");
if (lookupButton) {
lookupButton.addEventListener("click", function() {
let searchInput = document.getElementById("lookupType").value;
// $.ajax({
// type: "GET",
// url: "db_connect.php",
// data: {
// f: "read_maint",
// q: searchInput,
// },
// success: function(obj) {
// console.log(obj);
// // for (var i = 0; i < obj.length; i++) {
// // let row = "";
// // // format row
// // $('#searchResults').append(row);
// // }
// },
// });
// query and post results
$('#searchResults').html("No results found");
});
document.addEventListener("keypress", function(e) {
if (e.key === "Enter") {
lookupButton.click();
}
});
}