-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2813inventory.html
More file actions
616 lines (545 loc) · 20.3 KB
/
Copy path2813inventory.html
File metadata and controls
616 lines (545 loc) · 20.3 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inventory Request — Team 2813</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #17181a;
--panel: #1f2123;
--panel-raised: #26282b;
--line: #383b3e;
--text: #e9e6df;
--text-dim: #8b8d8f;
--accent: #ff6a1a;
--accent-dim: #7a3712;
--good: #4caf6d;
--bad: #e5484d;
--warn: #e5b84c;
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--bg);
background-image:
repeating-linear-gradient(135deg, rgba(255,255,255,0.015) 0px, rgba(255,255,255,0.015) 1px, transparent 1px, transparent 14px);
color: var(--text);
font-family: 'IBM Plex Mono', monospace;
min-height: 100vh;
display: flex;
justify-content: center;
padding: 40px 16px 80px;
}
.sheet {
width: 100%;
max-width: 560px;
}
.eyebrow {
font-size: 12px;
letter-spacing: 0.18em;
color: var(--accent);
text-transform: uppercase;
margin-bottom: 6px;
display: flex;
align-items: center;
gap: 8px;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
background: var(--accent);
display: inline-block;
}
h1 {
font-family: 'Oswald', sans-serif;
font-weight: 700;
font-size: 32px;
letter-spacing: 0.01em;
text-transform: uppercase;
margin: 0 0 4px;
}
.subhead {
color: var(--text-dim);
font-size: 13px;
margin-bottom: 28px;
line-height: 1.5;
}
form {
background: var(--panel);
border: 1px solid var(--line);
padding: 24px;
}
fieldset {
border: none;
padding: 0;
margin: 0 0 22px;
}
legend {
font-family: 'Oswald', sans-serif;
font-size: 12px;
letter-spacing: 0.14em;
text-transform: uppercase;
color: var(--text-dim);
padding: 0 0 10px;
width: 100%;
border-bottom: 1px solid var(--line);
margin-bottom: 14px;
}
.field {
margin-bottom: 16px;
}
.field:last-child { margin-bottom: 0; }
label {
display: block;
font-size: 12px;
letter-spacing: 0.04em;
color: var(--text-dim);
margin-bottom: 6px;
text-transform: uppercase;
}
label .req { color: var(--accent); }
label .opt { color: var(--text-dim); text-transform: none; letter-spacing: 0; }
input[type="text"],
input[type="number"],
select,
textarea {
width: 100%;
background: var(--panel-raised);
border: 1px solid var(--line);
color: var(--text);
font-family: 'IBM Plex Mono', monospace;
font-size: 14px;
padding: 10px 12px;
outline: none;
transition: border-color 0.15s ease;
}
input::placeholder, textarea::placeholder { color: #56585b; }
input:focus, select:focus, textarea:focus {
border-color: var(--accent);
}
input:disabled, select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
textarea { resize: vertical; min-height: 60px; }
select {
appearance: none;
background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
background-position: calc(100% - 18px) center, calc(100% - 13px) center;
background-size: 5px 5px, 5px 5px;
background-repeat: no-repeat;
}
.row2 {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.row-unit {
display: grid;
grid-template-columns: 1fr 110px;
gap: 12px;
}
.type-tabs {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 8px;
margin-bottom: 6px;
}
.type-tab {
background: var(--panel-raised);
border: 1px solid var(--line);
color: var(--text-dim);
font-family: 'Oswald', sans-serif;
font-size: 11px;
letter-spacing: 0.06em;
text-transform: uppercase;
text-align: center;
padding: 10px 6px;
cursor: pointer;
user-select: none;
}
.type-tab.active {
border-color: var(--accent);
color: var(--text);
background: var(--accent-dim);
}
.error-text {
font-size: 12px;
color: var(--bad);
margin-top: 6px;
display: none;
}
.field.invalid input,
.field.invalid select,
.field.invalid textarea {
border-color: var(--bad);
}
.field.invalid .error-text { display: block; }
button {
width: 100%;
background: var(--accent);
color: #171215;
border: none;
font-family: 'Oswald', sans-serif;
font-weight: 600;
font-size: 15px;
letter-spacing: 0.06em;
text-transform: uppercase;
padding: 14px;
cursor: pointer;
transition: background 0.15s ease, transform 0.05s ease;
}
button:hover { background: #ff7f3d; }
button:active { transform: translateY(1px); }
button:disabled {
background: var(--panel-raised);
color: var(--text-dim);
cursor: not-allowed;
}
.status {
margin-top: 16px;
padding: 12px 14px;
font-size: 13px;
border: 1px solid var(--line);
display: none;
line-height: 1.5;
}
.status.show { display: block; }
.status.ok { border-color: var(--good); color: var(--good); }
.status.err { border-color: var(--bad); color: var(--bad); }
.status.pending { border-color: var(--text-dim); color: var(--text-dim); }
.hint {
font-size: 11px;
color: var(--text-dim);
margin-top: 6px;
line-height: 1.4;
}
.status-pill-row {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 8px;
}
.status-pill {
border: 1px solid var(--line);
background: var(--panel-raised);
color: var(--text-dim);
font-family: 'Oswald', sans-serif;
font-size: 12px;
letter-spacing: 0.05em;
text-transform: uppercase;
text-align: center;
padding: 12px 6px;
cursor: pointer;
user-select: none;
}
.status-pill[data-status="out"].active { border-color: var(--bad); color: var(--bad); background: rgba(229,72,77,0.12); }
.status-pill[data-status="low"].active { border-color: var(--warn); color: var(--warn); background: rgba(229,184,76,0.12); }
.status-pill[data-status="enough"].active { border-color: var(--good); color: var(--good); background: rgba(76,175,109,0.12); }
</style>
</head>
<body>
<div class="sheet">
<div class="eyebrow">Team 2813 · Gear Heads</div>
<h1>Inventory Request</h1>
<div class="subhead">Log a stock change. Every field marked <span style="color:var(--accent)">*</span> is required — the request won't send without it.</div>
<form id="invForm" novalidate>
<fieldset>
<legend>Item</legend>
<div class="field" data-field="itemName">
<label for="itemName">Item Name <span class="req">*</span></label>
<input type="text" id="itemName" placeholder="e.g. WAGO 221 Lever Nut">
<div class="hint">Keep naming consistent so the same item doesn't get logged twice under slightly different names.</div>
<div class="error-text">Enter an item name.</div>
</div>
<div class="field" data-field="itemType">
<label>Item Type <span class="req">*</span></label>
<div class="type-tabs" id="typeTabs">
<div class="type-tab active" data-type="countable">Countable</div>
<div class="type-tab" data-type="wire">Wire / Length</div>
<div class="type-tab" data-type="bulk">Bulk</div>
</div>
<div class="hint" id="typeHint">Discrete items you count one by one — gears, sensors, connectors, standoffs, motors.</div>
</div>
</fieldset>
<fieldset>
<legend>Action</legend>
<div class="field" data-field="action" id="actionField">
<label for="action">Type <span class="req">*</span></label>
<select id="action">
<option value="add">Add stock (+)</option>
<option value="checkout">Check out / use stock (−)</option>
<option value="set" selected>Set exact quantity</option>
</select>
<div class="error-text">Choose what this request does.</div>
</div>
<!-- Countable / Wire: numeric quantity fields -->
<div class="field" data-field="quantityDelta" id="deltaField" style="display:none;">
<label for="quantityDelta">Quantity <span class="req">*</span></label>
<div class="row-unit" id="deltaRow">
<input type="number" id="quantityDelta" min="0" step="1" placeholder="e.g. 3">
<select id="deltaUnit" style="display:none;">
<option value="ft">ft</option>
<option value="in">in</option>
<option value="m">m</option>
<option value="cm">cm</option>
</select>
</div>
<div class="error-text">Enter a quantity greater than 0.</div>
</div>
<div class="field" data-field="quantity" id="setField">
<label for="quantity">New Total Quantity <span class="req">*</span></label>
<div class="row-unit" id="setRow">
<input type="number" id="quantity" min="0" step="1" placeholder="e.g. 40">
<select id="setUnit" style="display:none;">
<option value="ft">ft</option>
<option value="in">in</option>
<option value="m">m</option>
<option value="cm">cm</option>
</select>
</div>
<div class="error-text">Enter a quantity of 0 or more.</div>
</div>
<!-- Bulk: qualitative stock level instead of a count -->
<div class="field" data-field="bulkStatus" id="bulkStatusField" style="display:none;">
<label>Stock Level <span class="req">*</span></label>
<div class="status-pill-row" id="bulkPills">
<div class="status-pill" data-status="out">Out of Stock</div>
<div class="status-pill" data-status="low">Low</div>
<div class="status-pill" data-status="enough">Enough</div>
</div>
<div class="hint">Bulk items (zip ties, heat shrink, tape, hardware bags) aren't counted exactly — just flag the current level.</div>
<div class="error-text">Pick a stock level.</div>
</div>
<div class="field" data-field="lowStockThreshold" id="thresholdField">
<label for="lowStockThreshold">Low Stock Threshold <span class="opt">(only used when creating a new item)</span></label>
<input type="number" id="lowStockThreshold" min="0" step="1" value="0">
</div>
</fieldset>
<fieldset>
<legend>Who / Where</legend>
<div class="row2">
<div class="field" data-field="subteam">
<label for="subteam">Subteam <span class="req">*</span></label>
<select id="subteam">
<option value="Fabrication">Fabrication</option>
<option value="Electrical">Electrical</option>
<option value="Software">Software</option>
<option value="Media">Media</option>
<option value="Outreach">Outreach</option>
</select>
<div class="error-text">Choose a subteam.</div>
</div>
<div class="field" data-field="submittedBy">
<label for="submittedBy">Your Name <span class="req">*</span></label>
<input type="text" id="submittedBy" placeholder="e.g. JJ">
<div class="error-text">Enter your name.</div>
</div>
</div>
<div class="field" data-field="notes">
<label for="notes">Notes <span class="opt">(optional)</span></label>
<textarea id="notes" placeholder="e.g. restocked from Amazon order"></textarea>
</div>
</fieldset>
<button type="submit" id="submitBtn">Send Request</button>
<div class="status" id="status"></div>
</form>
</div>
<script>
const ENDPOINT = 'https://script.google.com/macros/s/AKfycbysgInZV_0b3kLz4ABqKIXSRSFJzPn3LXlKXFPAG0glusSsQt4j0mOsnYDGXfwre_kd/exec';
const LAST_SUBTEAM_KEY = 'team2813_inventory_last_subteam';
const TYPE_HINTS = {
countable: 'Discrete items you count one by one — gears, sensors, connectors, standoffs, motors.',
wire: 'Spools or lengths measured in feet/inches/meters — wire, tubing, pneumatic line, belt stock.',
bulk: 'Loose consumables where an exact count isn\u2019t practical — zip ties, heat shrink, tape, hardware bags.'
};
const form = document.getElementById('invForm');
const itemNameInput = document.getElementById('itemName');
const typeTabs = document.getElementById('typeTabs');
const typeHint = document.getElementById('typeHint');
const actionField = document.getElementById('actionField');
const actionSelect = document.getElementById('action');
const deltaField = document.getElementById('deltaField');
const setField = document.getElementById('setField');
const quantityDeltaInput = document.getElementById('quantityDelta');
const quantityInput = document.getElementById('quantity');
const deltaUnit = document.getElementById('deltaUnit');
const setUnit = document.getElementById('setUnit');
const bulkStatusField = document.getElementById('bulkStatusField');
const bulkPills = document.getElementById('bulkPills');
const thresholdField = document.getElementById('thresholdField');
const subteamInput = document.getElementById('subteam');
function loadLastSubteam() {
try { return localStorage.getItem(LAST_SUBTEAM_KEY); } catch (e) { return null; }
}
function saveLastSubteam(value) {
try { localStorage.setItem(LAST_SUBTEAM_KEY, value); } catch (e) { /* storage unavailable, ignore */ }
}
// Restore the last subteam picked on this device, if any.
const savedSubteam = loadLastSubteam();
if (savedSubteam) subteamInput.value = savedSubteam;
subteamInput.addEventListener('change', () => saveLastSubteam(subteamInput.value));
const submittedByInput = document.getElementById('submittedBy');
const notesInput = document.getElementById('notes');
const statusEl = document.getElementById('status');
const submitBtn = document.getElementById('submitBtn');
let itemType = 'countable';
let bulkStatus = null;
function selectType(type) {
itemType = type;
[...typeTabs.children].forEach(tab => tab.classList.toggle('active', tab.dataset.type === type));
typeHint.textContent = TYPE_HINTS[type];
updateFormMode();
}
typeTabs.addEventListener('click', (e) => {
const tab = e.target.closest('.type-tab');
if (!tab) return;
selectType(tab.dataset.type);
});
bulkPills.addEventListener('click', (e) => {
const pill = e.target.closest('.status-pill');
if (!pill) return;
bulkStatus = pill.dataset.status;
[...bulkPills.children].forEach(p => p.classList.toggle('active', p === pill));
setInvalid('bulkStatus', false);
});
function updateFormMode() {
const isBulk = itemType === 'bulk';
const isWire = itemType === 'wire';
const action = actionSelect.value;
// Bulk items only ever get their status set directly — add/checkout amounts don't apply.
actionField.style.display = isBulk ? 'none' : '';
if (isBulk) actionSelect.value = 'set';
bulkStatusField.style.display = isBulk ? '' : 'none';
deltaField.style.display = (!isBulk && (action === 'add' || action === 'checkout')) ? '' : 'none';
setField.style.display = (!isBulk && action === 'set') ? '' : 'none';
thresholdField.style.display = isBulk ? 'none' : '';
deltaUnit.style.display = isWire ? '' : 'none';
setUnit.style.display = isWire ? '' : 'none';
quantityDeltaInput.step = isWire ? '0.1' : '1';
quantityInput.step = isWire ? '0.1' : '1';
const deltaLabel = deltaField.querySelector('label');
if (action === 'checkout') {
deltaLabel.innerHTML = (isWire ? 'Length to Remove' : 'Quantity to Remove') + ' <span class="req">*</span>';
} else {
deltaLabel.innerHTML = (isWire ? 'Length to Add' : 'Quantity to Add') + ' <span class="req">*</span>';
}
document.querySelector('label[for="quantity"]').innerHTML = (isWire ? 'New Total Length' : 'New Total Quantity') + ' <span class="req">*</span>';
}
actionSelect.addEventListener('change', updateFormMode);
// Keep the two unit dropdowns (add/checkout row vs. set-quantity row) in sync
// since only one is ever visible at a time but either could be the one submitted.
deltaUnit.addEventListener('change', () => { setUnit.value = deltaUnit.value; });
setUnit.addEventListener('change', () => { deltaUnit.value = setUnit.value; });
function setInvalid(fieldName, invalid) {
const el = form.querySelector('[data-field="' + fieldName + '"]');
if (!el) return;
el.classList.toggle('invalid', invalid);
}
function validate() {
let valid = true;
const nameVal = itemNameInput.value.trim();
setInvalid('itemName', !nameVal);
if (!nameVal) valid = false;
if (itemType === 'bulk') {
setInvalid('bulkStatus', !bulkStatus);
if (!bulkStatus) valid = false;
} else {
const actionVal = actionSelect.value;
setInvalid('action', !actionVal);
if (!actionVal) valid = false;
if (actionVal === 'add' || actionVal === 'checkout') {
const n = Number(quantityDeltaInput.value);
const bad = !quantityDeltaInput.value || !Number.isFinite(n) || n <= 0;
setInvalid('quantityDelta', bad);
if (bad) valid = false;
} else if (actionVal === 'set') {
const n = Number(quantityInput.value);
const bad = quantityInput.value === '' || !Number.isFinite(n) || n < 0;
setInvalid('quantity', bad);
if (bad) valid = false;
}
}
const subteamVal = subteamInput.value.trim();
setInvalid('subteam', !subteamVal);
if (!subteamVal) valid = false;
const submittedByVal = submittedByInput.value.trim();
setInvalid('submittedBy', !submittedByVal);
if (!submittedByVal) valid = false;
return valid;
}
function showStatus(kind, message) {
statusEl.className = 'status show ' + kind;
statusEl.textContent = message;
}
const BULK_CODE = { out: 0, low: 1, enough: 2 };
form.addEventListener('submit', async function (e) {
e.preventDefault();
if (!validate()) {
showStatus('err', 'Fix the highlighted fields — nothing was sent.');
return;
}
const payload = {
itemName: itemNameInput.value.trim(),
itemType: itemType,
subteam: subteamInput.value.trim(),
submittedBy: submittedByInput.value.trim()
};
if (itemType === 'bulk') {
payload.action = 'set';
payload.stockStatus = bulkStatus;
payload.quantity = BULK_CODE[bulkStatus];
} else {
const action = actionSelect.value;
payload.action = action;
if (itemType === 'wire') payload.unit = action === 'set' ? setUnit.value : deltaUnit.value;
if (action === 'add' || action === 'checkout') {
payload.quantityDelta = Number(quantityDeltaInput.value);
} else if (action === 'set') {
payload.quantity = Number(quantityInput.value);
}
const threshold = document.getElementById('lowStockThreshold').value;
if (threshold !== '') payload.lowStockThreshold = Number(threshold);
}
const notes = notesInput.value.trim();
if (notes) payload.notes = notes;
submitBtn.disabled = true;
submitBtn.textContent = 'Sending…';
showStatus('pending', 'Sending request…');
try {
const res = await fetch(ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'text/plain;charset=utf-8' }, // avoids a CORS preflight against Apps Script
body: JSON.stringify(payload)
});
const data = await res.json();
if (data.ok) {
const resultText = itemType === 'bulk'
? 'Done — ' + payload.itemName + ' is now marked ' + bulkStatus.toUpperCase() + '.'
: 'Done — ' + payload.itemName + ' is now at ' + data.result.newQuantity + (itemType === 'wire' ? (' ' + (payload.unit || '')) : '') + '.';
showStatus('ok', resultText);
form.reset();
selectType('countable');
actionSelect.value = 'set';
bulkStatus = null;
[...bulkPills.children].forEach(p => p.classList.remove('active'));
document.getElementById('lowStockThreshold').value = '0';
subteamInput.value = loadLastSubteam() || 'Fabrication';
updateFormMode();
} else {
showStatus('err', 'Server rejected the request: ' + (data.error || 'unknown error'));
}
} catch (err) {
showStatus('err', 'Request failed to send: ' + err.message + '. Check your connection and the endpoint URL.');
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Send Request';
}
});
updateFormMode();
</script>
</body>
</html>