diff --git a/src/api/printerjob.js b/src/api/printerjob.js
index a1d9059..899099b 100644
--- a/src/api/printerjob.js
+++ b/src/api/printerjob.js
@@ -89,12 +89,23 @@ export const printerjob = {
/**
* POST /api/printerjob/cancel-all
- * Cancels all pending/processing jobs, optionally scoped to an agentprinter.
- * Falls back to listing and cancelling individual jobs if needed.
+ * Sends ~JA to clear printer buffer and cancels all queued jobs.
* @param {{ agentprinterId?: number }} [payload]
* → { success: true, cancelledCount: number, jobs: PrinterJob[] }
*/
async cancelAll({ agentprinterId } = {}) {
+ if (agentprinterId != null) {
+ try {
+ await this.createZplJob({
+ agentprinterId: Number(agentprinterId),
+ data: '~JA',
+ copiescount: 1,
+ });
+ } catch (e) {
+ console.warn('Failed to send ~JA to printer:', e);
+ }
+ }
+
try {
return await http('/api/printerjob/cancel-all', {
method: 'POST',
diff --git a/src/components/OnlinePrinterIcons.jsx b/src/components/OnlinePrinterIcons.jsx
index 83ff379..77ee42b 100644
--- a/src/components/OnlinePrinterIcons.jsx
+++ b/src/components/OnlinePrinterIcons.jsx
@@ -27,8 +27,6 @@ export default class OnlinePrinterIcons extends PureComponent {
? companyAutomat.state.livePrinters
: [],
menuAnchor: null,
- testingId: null,
- cancellingId: null,
};
this.handleOpenMenu = this.handleOpenMenu.bind(this);
this.handleCloseMenu = this.handleCloseMenu.bind(this);
@@ -110,45 +108,33 @@ export default class OnlinePrinterIcons extends PureComponent {
this.setState({ menuAnchor: null });
}
- async handleTestPrint(printer) {
+ handleTestPrint(printer) {
if (!printer?.id) return;
- this.setState({ testingId: printer.id });
- try {
- await companyAutomat.actions.sendTestPrint(printer.id, {
+ this.handleCloseMenu();
+ companyAutomat.actions
+ .sendTestPrint(printer.id, {
model: printer.model || printer.type || 'Zebra',
- });
- enqueueSnackbar(
- `Testdruck für ${printer.model || 'Drucker'} (#${printer.id}) an Warteschlange gesendet.`,
- { variant: 'success' },
- );
- } catch (err) {
- notifyError(err);
- } finally {
- this.setState({ testingId: null, menuAnchor: null });
- }
+ })
+ .then(() => {
+ enqueueSnackbar(
+ `Testdruck für ${printer.model || 'Drucker'} (#${printer.id}) an Warteschlange gesendet.`,
+ { variant: 'success' },
+ );
+ })
+ .catch(notifyError);
}
- async handleCancelAllJobs(printer) {
+ handleCancelAllJobs(printer) {
if (!printer?.id) return;
- this.setState({ cancellingId: printer.id });
- try {
- const res = await companyAutomat.actions.cancelAllPrinterJobs(printer.id);
- const count = res?.cancelledCount ?? 0;
- if (count > 0) {
- enqueueSnackbar(
- `${count} Druckauftrag/Druckaufträge für ${printer.model || 'Drucker'} abgebrochen.`,
- { variant: 'info' },
- );
- } else {
- enqueueSnackbar(`Keine offenen Aufträge für ${printer.model || 'Drucker'}.`, {
+ this.handleCloseMenu();
+ companyAutomat.actions
+ .cancelAllPrinterJobs(printer.id)
+ .then(() => {
+ enqueueSnackbar(`Druckaufträge für ${printer.model || 'Drucker'} abgebrochen.`, {
variant: 'info',
});
- }
- } catch (err) {
- notifyError(err);
- } finally {
- this.setState({ cancellingId: null, menuAnchor: null });
- }
+ })
+ .catch(notifyError);
}
handleOpenPrinterSettings() {
@@ -159,7 +145,7 @@ export default class OnlinePrinterIcons extends PureComponent {
}
render() {
- const { menuAnchor, testingId, cancellingId } = this.state;
+ const { menuAnchor } = this.state;
const onlinePrinters = this.getOnlinePrinters();
if (onlinePrinters.length === 0) {
@@ -290,28 +276,22 @@ export default class OnlinePrinterIcons extends PureComponent {
-