mirror of
https://codeberg.org/icewind/ptouch-api.git
synced 2026-06-03 19:04:08 +02:00
working web ui
This commit is contained in:
parent
71cf4dbcb2
commit
88e6fa3244
2 changed files with 21 additions and 1 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<td>
|
<td>
|
||||||
<input type="button" value="Add" id="add"/>
|
<input type="button" value="Add Text" id="add"/>
|
||||||
</td>
|
</td>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
@ -29,6 +29,10 @@
|
||||||
</p>
|
</p>
|
||||||
<canvas id="preview" height="32" width="300"></canvas>
|
<canvas id="preview" height="32" width="300"></canvas>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<input type="button" value="Print" id="print"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
<script src="label.js"></script>
|
<script src="label.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
16
web/label.js
16
web/label.js
|
|
@ -4,6 +4,8 @@ const preview = document.getElementById('preview');
|
||||||
const renderCtx = preview.getContext("2d");
|
const renderCtx = preview.getContext("2d");
|
||||||
const elementsTableBody = elementsTable.getElementsByTagName('tbody')[0];
|
const elementsTableBody = elementsTable.getElementsByTagName('tbody')[0];
|
||||||
const addButton = document.getElementById('add');
|
const addButton = document.getElementById('add');
|
||||||
|
/** @type HTMLInputElement printButton */
|
||||||
|
const printButton = document.getElementById('print');
|
||||||
const widthInput = document.getElementById('canvas-width');
|
const widthInput = document.getElementById('canvas-width');
|
||||||
const widthUnit = document.getElementById('canvas-width-unit');
|
const widthUnit = document.getElementById('canvas-width-unit');
|
||||||
|
|
||||||
|
|
@ -128,7 +130,21 @@ const resize = () => {
|
||||||
render()
|
render()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const print = () => {
|
||||||
|
printButton.disabled = true;
|
||||||
|
preview.toBlob(blob => {
|
||||||
|
blob.arrayBuffer().then(png => fetch(apiRoot + '/print', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: png,
|
||||||
|
}))
|
||||||
|
.then(() => {
|
||||||
|
printButton.disabled = false;
|
||||||
|
});
|
||||||
|
}, 'image/png');
|
||||||
|
};
|
||||||
|
|
||||||
addButton.addEventListener('click', addElement);
|
addButton.addEventListener('click', addElement);
|
||||||
|
printButton.addEventListener('click', print);
|
||||||
widthInput.addEventListener('input', resize);
|
widthInput.addEventListener('input', resize);
|
||||||
|
|
||||||
widthUnit.addEventListener('change', () => {
|
widthUnit.addEventListener('change', () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue