-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarcodeScanner.html
More file actions
175 lines (154 loc) · 6.53 KB
/
Copy pathBarcodeScanner.html
File metadata and controls
175 lines (154 loc) · 6.53 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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
h2 { text-align: center; color: #2E5339; margin-bottom: 15px; }
.subtitle { text-align: center; color: #666; font-size: 12px; margin-bottom: 20px; }
.scan-area {
background: #fff; border-radius: 10px; padding: 20px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-bottom: 15px;
}
.input-row { display: flex; gap: 8px; margin-bottom: 15px; }
.input-row input {
flex: 1; padding: 16px; font-size: 22px; text-align: center;
border: 3px solid #2E5339; border-radius: 10px;
font-weight: bold; letter-spacing: 1px;
}
.input-row input:focus {
outline: none; border-color: #28a745;
box-shadow: 0 0 0 3px rgba(40,167,69,0.3);
}
.scan-btn {
padding: 16px 24px; font-size: 18px; font-weight: bold;
background: #2E5339; color: #fff; border: none; border-radius: 10px;
cursor: pointer; min-width: 80px;
}
.scan-btn:hover { background: #3a6249; }
.scan-btn:disabled { background: #ccc; cursor: not-allowed; }
#status {
padding: 12px; border-radius: 8px; text-align: center;
font-size: 15px; font-weight: bold; min-height: 42px;
margin-bottom: 15px; transition: all 0.3s;
}
.ready { background: #e8f5e9; color: #2E5339; }
.scanning { background: #fff3cd; color: #856404; }
.success { background: #d4edda; color: #155724; }
.error { background: #f8d7da; color: #721c24; }
#counter {
text-align: center; padding: 10px; background: #2E5339;
color: #fff; border-radius: 8px; font-size: 14px; margin-bottom: 15px;
}
#counter span { font-size: 22px; font-weight: bold; }
.history { background: #fff; border-radius: 10px; padding: 15px; max-height: 250px; overflow-y: auto; }
.history h3 { color: #2E5339; margin-bottom: 10px; font-size: 14px; }
.history-item {
display: flex; justify-content: space-between; align-items: center;
padding: 8px 12px; margin-bottom: 4px; border-radius: 6px; font-size: 13px;
}
.history-item.ok { background: #e8f5e9; }
.history-item.fail { background: #f8d7da; }
.history-item .sample-id { font-weight: bold; font-family: monospace; font-size: 14px; }
.history-item .time { color: #888; font-size: 11px; }
.actions { text-align: center; margin-top: 15px; }
.clear-btn {
padding: 8px 20px; background: #dc3545; color: #fff;
border: none; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.close-btn {
padding: 8px 20px; background: #6c757d; color: #fff;
border: none; border-radius: 6px; cursor: pointer; font-size: 13px; margin-left: 10px;
}
</style>
</head>
<body>
<h2>📷 Receiving Scanner (Scan In)</h2>
<div class="subtitle">Scan or type a CS Sample # to mark as SCANNED</div>
<div id="counter">Scanned this session: <span id="count">0</span></div>
<div id="status" class="ready">Ready — scan a barcode or type a sample number</div>
<div class="scan-area">
<div class="input-row">
<input type="text" id="barcodeInput" placeholder="Scan barcode here..."
autofocus autocomplete="off" onkeypress="if(event.key==='Enter') doScan();">
<button class="scan-btn" id="scanBtn" onclick="doScan()">SCAN</button>
</div>
</div>
<div class="history" id="historySection" style="display:none;">
<h3>📋 Scan History</h3>
<div id="historyList"></div>
</div>
<div class="actions">
<button class="clear-btn" onclick="clearHistory()">Clear History</button>
<button class="close-btn" onclick="google.script.host.close()">Close</button>
</div>
<script>
var scanCount = 0;
var scanning = false;
function doScan() {
var input = document.getElementById('barcodeInput');
var barcode = input.value.trim();
if (!barcode || scanning) return;
scanning = true;
document.getElementById('scanBtn').disabled = true;
setStatus('scanning', '⏳ Looking up ' + barcode + '...');
google.script.run
.withSuccessHandler(function(result) {
scanning = false;
document.getElementById('scanBtn').disabled = false;
if (result.success) {
scanCount++;
document.getElementById('count').textContent = scanCount;
setStatus('success', result.message);
addHistory(barcode, true, result.message);
} else {
setStatus('error', result.message);
addHistory(barcode, false, result.message);
}
input.value = '';
input.focus();
})
.withFailureHandler(function(err) {
scanning = false;
document.getElementById('scanBtn').disabled = false;
setStatus('error', '❌ Error: ' + err.message);
addHistory(barcode, false, err.message);
input.value = '';
input.focus();
})
.scanSampleBarcode(barcode);
}
function setStatus(cls, msg) {
var el = document.getElementById('status');
el.className = cls;
el.textContent = msg;
}
function addHistory(id, ok, msg) {
var section = document.getElementById('historySection');
section.style.display = 'block';
var list = document.getElementById('historyList');
var now = new Date();
var time = now.getHours().toString().padStart(2,'0') + ':' +
now.getMinutes().toString().padStart(2,'0') + ':' +
now.getSeconds().toString().padStart(2,'0');
var div = document.createElement('div');
div.className = 'history-item ' + (ok ? 'ok' : 'fail');
var idSpan = document.createElement('span'); idSpan.className = 'sample-id'; idSpan.textContent = id;
var statusSpan = document.createElement('span'); statusSpan.textContent = ok ? '✅' : '❌';
var timeSpan = document.createElement('span'); timeSpan.className = 'time'; timeSpan.textContent = time;
div.appendChild(idSpan); div.appendChild(statusSpan); div.appendChild(timeSpan);
list.insertBefore(div, list.firstChild);
}
function clearHistory() {
document.getElementById('historyList').innerHTML = '';
document.getElementById('historySection').style.display = 'none';
scanCount = 0;
document.getElementById('count').textContent = '0';
setStatus('ready', 'Ready — scan a barcode or type a sample number');
}
// Auto-focus on load
document.getElementById('barcodeInput').focus();
</script>
</body>
</html>