-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-printer-qr-code.html
More file actions
176 lines (158 loc) · 6.16 KB
/
generate-printer-qr-code.html
File metadata and controls
176 lines (158 loc) · 6.16 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Printer QR code generator for Digitevent Checkin2 app</title>
</head>
<body>
<h1>
Printer QR code generator
<small> for Digitevent Checkin2 app</small>
</h1>
<div class="row">
<section class="column">
<h2>Enter name and MAC</h2>
<form>
<p>
<label for="printer_family">Model family </label>
<select name="printer_family" id="printer_family">
<option value="">Select printer model...</option>
<option value="zebra_zd421">Zebra ZD421</option>
<option value="zebra_zd230">Zebra ZD230</option>
<option value="zebra_zd420">Zebra ZD420</option>
</select>
(<b>Double check</b>)
</p>
<p>
<label for="printer_name">Printer name</label>
<input type="text" name="printer_name" id="printer_name" placeholder="Printer name" />
</p>
<p>
<label for="printer_mac">Printer MAC</label>
<input type="text" name="printer_mac" id="printer_mac" placeholder="Printer MAC" />
</p>
<p>
<label for="printer_friendly_name">Friendly name</label>
<input type="text" name="printer_friendly_name" id="printer_friendly_name"
placeholder="What user will see" />
</p>
<p>
<button type="button" id="generatebutton">Generate QR code</button>
</p>
<p>
<span id="errors" style="color: red;"></span>
</p>
</form>
<p>
<img id="qrcode" src="" alt="QR code" style="display: none;" />
<textarea id="payload"></textarea>
</p>
<p> <a id="downloadbutton" download="printer-qr.png" href="" target="_blank" style="display: none;">Download
QR code</a></p>
</section>
<section class="column">
<h2>How to find MAC and name of the Printer?</h2>
<img src="img/printer_how_to_find_mac_name.jpg" alt="How to find MAC and name of the Printer?" />
</section>
</div>
<script type="module">
console.log('QR code generator for Digitevent Checkin2 app')
import qrcode from 'https://cdn.jsdelivr.net/npm/qrcode@1.5.3/+esm'
console.log('Lib loaded')
const form = document.querySelector('form')
document.querySelector('#generatebutton').addEventListener('click', generateQRCode);
function generateQRCode() {
const name = document.querySelector('#printer_name').value.trim()
const macWithOrWithoutColons = document.querySelector('#printer_mac').value.trim()
const friendlyName = document.querySelector('#printer_friendly_name').value.trim()
const family = document.querySelector('#printer_family').value
const validFamilies = ['zebra_zd421', 'zebra_zd420', 'zebra_zd230']
if (!family) {
putError('Please select printer model');
return
}
if (!validFamilies.includes(family)) {
putError('Invalid printer model');
return
}
if (!name) {
putError('Please fill name field');
return
}
if (!macWithOrWithoutColons) {
putError('Please fill mac field');
return
}
if (!friendlyName) {
putError('Please fill friendly name field');
return
}
const mac = macWithOrWithoutColons.replace(/:/g, '')
if (mac.length !== 12) {
putError('MAC should be 12 characters long');
return
}
if (friendlyName.length > 20) {
putError('Friendly name should be less than 20 characters');
return
}
const macWithColons = mac.match(/.{1,2}/g).join(':')
const payload = generatePrinterQRCodePayload({ name, mac: macWithColons, friendlyName, family })
document.querySelector('#payload').innerHTML = payload
qrcode.toDataURL(payload, function (err, url) {
if (err) {
console.error(err)
putError(err)
return
}
console.log('QR code generated', url)
document.querySelector('#qrcode').style.display = 'block'
document.querySelector('#downloadbutton').style.display = 'block'
document.querySelector('#qrcode').src = url
document.querySelector('#downloadbutton').href = url
clearError()
})
}
function putError(message) {
document.querySelector('#errors').innerHTML = message
}
function clearError() {
document.querySelector('#errors').innerHTML = ""
}
function generatePrinterQRCodePayload({ friendlyName, name, mac, family }) {
const payload = {
type: "digitevent_checkin2_printer",
mac,
localName: name,
friendlyName,
family
}
return JSON.stringify(payload)
}
</script>
<style>
body {
max-width: 1000px;
margin: 1rem auto;
padding: 2rem;
font-family: sans-serif;
}
.row {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 1rem;
}
.column {
grid-row: 1;
}
img {
max-width: 100%;
}
#payload {
word-wrap: break-word;
}
</style>
</body>
</html>