-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreturn.html
More file actions
168 lines (154 loc) · 7.82 KB
/
return.html
File metadata and controls
168 lines (154 loc) · 7.82 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Return Books</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<style>
body {
background-color: rgb(37, 150, 190);
}
</style>
<link rel="icon" href="stab-logo.png">
</head>
<body onload="isDataHere()">
<div id="global-navbar">
<ul id="nav-bar">
<li><a href="index.html"><img id="nav-bar-home-img" src="navBarHomePageImg.png" alt="Home Page Image Button" width="30px" height="30px"></a></li>
<li class="nav-bar-item nav-bar-highlight" id="nav-bar-search-books"><a href="books.html">Search Availible Books</a></li>
<li class="nav-bar-item nav-bar-highlight" id="nav-bar-return-books"><a href="return.html">Return Books</a></li>
<li class="nav-bar-item nav-bar-highlight" id="nav-bar-see-checked-out"><a href="checkedOutBooks.html">Books Currently Checked Out</a></li>
<li class="nav-bar-item nav-bar-highlight"><a href="contact.html">Contact Us</a></li>
<li id="nav-bar-instagram" class="nav-bar-item"> <a href="https://www.instagram.com/st.annesbelfield/?hl=en" target="_blank" rel="noopener noreferrer"><img src="instagramImage.png" alt="Instagram Logo Image" width="50px" height="50px"></a></li>
</ul>
</div>
<div id="return-all">
<div id="return-body">
<div id="return-body-center">
<h2 id="return-title">Return Book</h2><br>
<div id="return-form-container">
<form id="return-form">
<label for="return-form-book-title">Book Title (Select From Dropdown)</label><br>
<input id="return-form-book-title" class="return-inputs i-pointer" name="Book_Title" autocomplete="off" /><br>
<select id="return-drop-down" size="4">
</select>
<label id="return-form-name-label" for="return-form-name-book">School Email</label><br>
<input id="return-form-name-book" class="return-inputs i-pointer" name="School_Email" /><br>
<input type="radio" id="return-radio" name="Last_Action" value="Returned" checked="checked" />
<br />
</form>
<input id="returning-book-button" class="pointer" type="button" value="Return Book">
<div id="return-tick-mark-holder"><div id="return-tick-mark"></div></div>
<div id="return-cross-mark-holder"><div id="return-cross-mark"></div></div>
<!-- end of form div --></div>
<!-- end of return-body-center div --></div>
<!-- end of return-body div --></div>
<script>
// displays the drop down when an input is inputed
document.getElementById("return-form-book-title").addEventListener("input", ()=>{
displayDropDown();
document.getElementById("return-drop-down").style.display = "grid"
document.getElementById("return-form-book-title").style.marginBottom = "0px"
});
// checks if we have the json data from the spreadsheet so we dont call it over and over again
function isDataHere () {
if (typeof(localStorage.getItem("spread-sheet"))!='undefined') {
console.log(1)
getData();
} else {
console.log(2)
spreadSheet = JSON.parse(localStorage.getItem("spread-sheet"));
}
}
// displays the drop down and changes the items in the drop down
function displayDropDown () {
document.getElementById("return-drop-down").innerHTML = ""
let s = document.getElementById("return-form-book-title").value;
for (let i = 0; i < spreadSheet.data.length; i++) {
if (spreadSheet.data[i].Book_Title.toLowerCase().includes(s.toLowerCase())) {
console.log(1)
document.getElementById("return-drop-down").innerHTML = document.getElementById("return-drop-down").innerHTML + "<option>Room Number: "+ spreadSheet.data[i].Room + ": " +spreadSheet.data[i].Book_Title + "</option>"
}
}
}
// changes the value of the input to the book title clicked on
$('body').on('change', 'select', function() {
let fired_button = $(this).val();
document.getElementById("return-form-book-title").value = fired_button;
document.getElementById("return-drop-down").style.display = "none";
document.getElementById("return-form-book-title").style.marginBottom = "5px"
});
// hides the select drop down when it is clicked off of
// $('body').on('blur', 'select', function() {
// document.getElementById("return-drop-down").style.display = "none"
// document.getElementById("return-form-book-title").style.marginBottom = "0px"
// });
// hides the drop down when it is clicked off of
document.getElementById("return-drop-down").addEventListener("blur", ()=> {
document.getElementById("return-drop-down").style.display = "none";
document.getElementById("return-form-book-title").style.marginBottom = "5px"
})
// checks if the data is already in local storage
function isDataHere () {
if (typeof(localStorage.getItem("spread-sheet"))!='undefined') {
console.log(1)
getData();
} else {
spreadSheet = JSON.parse(localStorage.getItem("spread-sheet"));
}
}
var spreadSheet;
var books = [];
// gets the data from the spreadsheet
function getData() {
fetch("https://api.apispreadsheets.com/data/eksihvfg6DJsWlvl/").then(res => {
if (res.status === 200) {
//SUCCESS
// https://plainenglish.io/blog/how-to-store-json-data-in-local-storage-js-react-angular
res.json().then(data => {
localStorage.setItem("spread-sheet", JSON.stringify(data));
spreadSheet = JSON.parse(localStorage.getItem("spread-sheet"));
}).catch(err => console.log(err))
}
else {
// ERROR
console.log("errorrrrrrr")
}
})
}
// sends the data from the html form to the spreadsheet
function SubForm() {
$.ajax({
url: 'https://api.apispreadsheets.com/data/eksihvfg6DJsWlvl/',
type: 'post',
data: $("#return-form").serializeArray(),
// if we were able to connect to the api
success: function () {
resetForm()
document.getElementById("return-body-center").innerHTML = document.getElementById("return-body-center").innerHTML + "Book has been successfully returned"
},
// if we didnt connect to the api to input the data
error: function () {
document.getElementById("return-body-center").innerHTML = document.getElementById("return-body-center").innerHTML + "Book has failed to be returned"
}
});
}
// initializes the form submission
document.getElementById("returning-book-button").addEventListener("click", () => {
SubForm();
//returnedOrNot();
})
// resets the values in the input boxes for after the form is submitted
function resetForm() {
document.getElementById("return-form-book-title").value = "";
document.getElementById("return-form-name-book").value = "";
}
</script>
</body>
</html>
<!--room number they got it from
check that the name and the student id match
return the book to where you got it -->