-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
209 lines (204 loc) · 7.26 KB
/
index.html
File metadata and controls
209 lines (204 loc) · 7.26 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html lang="en">
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Food Inventory</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
<div class="h3 text-center">
<label class="form-label">Food Inventory</label>
</div>
<hr>
<form id="itemForm">
<div id="actionDiv" class="row">
<div class="col-2">
<label class="form-label">Action to take:</label>
</div>
<div class="col-2">
<select id='actionToTake' name='action' class="form-control">
<option value="">Select Action</option>
<option value="Add">Add</option>
<option value="Remove">Remove</option>
<option value="List">List</option>
</select>
</div>
</div>
<div id="itemDiv" class="d-none">
<div class='row'>
<div class="col-2">
<label class="form-label">Location:</label>
</div>
<div class="col-4">
<select id='location' name='location' class="form-control">
<option value="Refrigerator">Refrigerator</option>
<option value="Freezer">Freezer</option>
<option value="Cabenit">Cabenit</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<div class='row'>
<div class="col-2">
<label class="form-label label">Description</label>
</div>
<div class="col-8">
<input id="desc" name='desc' type="text" class="form-control" value="">
</div>
</div>
<div class='row'>
<div class="col-2">
<label class="form-label label">Quantity</label>
</div>
<div class="col-2">
<input id="qty" name="qty" type="number" class="form-control" value="1" step="1" min="1">
</div>
</div>
<div class='row'>
<div class="col-2">
<label class="form-label label">Expiration Date</label>
</div>
<div class="col-2">
<input id="expireDate" name="expireDate" type="date" class="form-control" value="" >
</div>
</div>
<div class='row'>
<div class="col-2">
<label class="form-label label">Date Added</label>
</div>
<div class="col-2">
<input id="addedDate" name="addedDate" type="date" class="form-control" value="" >
</div>
</div>
<div class="row-col">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</form>
<div id="resultDiv" class="container-fluid d-none">
<div class="row-col">
<div id="resultMessage" class="h5">
</div>
<div class="row-col">
<button id="messageCloseButton" class="btn btn-success">Start Over</button>
</div>
</div>
</div>
<form id="removeForm" class="container-fluid d-none">
<div class='row'>
<div class="col-2">
<label class="form-label">Location:</label>
</div>
<div class="col-4">
<select id='removeLocation' name='removeLocation' class="form-control">
<option value="Refrigerator">Refrigerator</option>
<option value="Freezer">Freezer</option>
<option value="Cabenit">Cabenit</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="form-label">Item # to remove: </label>
</div>
</div>
<div class="row">
<div class="col-2">
<input id="removeItemNo" name="removeItemNo" type="number" min="1" step="1">
</div>
</div>
<div class="row">
<div class="col-2">
<button id="removeItemNo" class="btn btn-danger">Remove</button>
</div>
</div>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous">
</script>
<script>
const itemForm = document.getElementById('itemForm')
const itemDiv = document.getElementById('itemDiv')
const actionToTake = document.getElementById('actionToTake');
const resultDiv = document.getElementById('resultDiv')
const resultMessage = document.getElementById('resultMessage')
const messageCloseButton = document.getElementById('messageCloseButton')
const removeForm = document.getElementById('removeForm')
itemForm.addEventListener('submit', addItem)
messageCloseButton.addEventListener('click', startOver)
actionToTake.addEventListener('change', actionSelected);
removeForm.addEventListener('submit', removeItem)
function actionSelected(){
const actionText = [...actionToTake.options].find((option) => option.selected).text;
if(actionText=='Add'){
if(itemDiv.classList.contains('d-none')){
itemDiv.classList.remove('d-none');
}
if(removeForm.classList.contains('d-none')== false){
removeForm.classList.add('d-none');
}
if(resultDiv.classList.contains('d-none')== false){
removeForm.classList.add('d-none');
}
}else if(actionText=='Remove'){
if(itemDiv.classList.contains('d-none') == false){
itemDiv.classList.add('d-none');
}
if(removeForm.classList.contains('d-none')){
removeForm.classList.remove('d-none');
}
if(resultDiv.classList.contains('d-none')){
removeForm.classList.remove('d-none');
}
}
}
function addItem(event){
event.preventDefault();
google.script.run
.withSuccessHandler(response=> {
console.log(response)
itemForm.reset()
itemForm.classList.add('d-none')
itemDiv.classList.add('d-none');
resultDiv.classList.remove('d-none')
resultMessage.innerHTML = response;
})
// .withFailureHandler(()=> )
.addItem(this)
}
function startOver(){
itemForm.reset();
removeForm.reset();
itemForm.classList.remove('d-none');
removeForm.classList.add('d-none');
itemDiv.classList.add('d-none');
resultDiv.classList.add('d-none');
}
function removeItem(){
event.preventDefault();
//confirmRemoval
google.script.run
.withSuccessHandler(response=> {
if (confirm(response) == true){
google.script.run
.withSuccessHandler(response=> {
console.log(response)
removeForm.reset()
removeForm.classList.add('d-none')
resultDiv.classList.remove('d-none')
resultMessage.innerHTML = response;
})
//.withFailureHandler(()=> )
.removeItem(this)
}
})
.confirmRemoval(this)
}
</script>
</body>
</html>