Skip to content

Commit

Permalink
Issue #86
Browse files Browse the repository at this point in the history
Issue #86, Add an option to print multiple copies. New beta version.
  • Loading branch information
mgobat committed Jun 24, 2024
1 parent e5d0e6a commit 9a738ef
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 15 deletions.
7 changes: 7 additions & 0 deletions configWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@
</div>
</div>
<div class="row"><br><br></div>
<div classe="row">
<div class="column">
<label for="numCopies">Copies:</label>
<input type="text" id="numCopies" name="numCopies" size="5">
</div>
</div>
<div class="row"><br><br></div>
<div class="row" id="customFormat" style="display:none">
<div class="column">
<label for="pageWidth">Page Width:</label>
Expand Down
18 changes: 15 additions & 3 deletions configWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,21 +379,24 @@ function savePrinterProfile () {
const left = document.querySelector('#borderLeft').value;
const customHeight = document.querySelector('#pageHeight').value;
const customWidth = document.querySelector('#pageWidth').value;
let copies = document.querySelector('#numCopies').value;
if (copies == 0 || isNaN(copies))
copies = 1

//if in edit mode, remove the existing entry and build new one
if (editMode) {
var checkedBoxes = document.querySelectorAll('input[id=printerProfile]:checked');
for (var i = checkedBoxes.length - 1; i >= 0; i--) {
almaPrinterProfiles.splice(checkedBoxes[i].value, 1);
}
jsonObj = {almaPrinter: document.querySelector('#almaPrinterId').value, localPrinter: localPrinterSelected, orientation: orientationValue, color: colorValue, letterFormat: format, borderUnits: units, borderTop: top, borderRight: right, borderBottom: bottom, borderLeft: left, pageHeight: customHeight, pageWidth: customWidth};
jsonObj = {almaPrinter: document.querySelector('#almaPrinterId').value, localPrinter: localPrinterSelected, orientation: orientationValue, color: colorValue, letterFormat: format, borderUnits: units, borderTop: top, borderRight: right, borderBottom: bottom, borderLeft: left, pageHeight: customHeight, pageWidth: customWidth, numCopies: copies};
} else {
//we are adding; build new entries
var x = document.getElementById("almaPrinter");
for (var i = 0; i < x.options.length; i++) {
console.log ("in the addloop");
if (x.options[i].selected) {
jsonObj = {almaPrinter: x.options[i].value, localPrinter: localPrinterSelected, orientation: orientationValue, color: colorValue, letterFormat: format, borderUnits: units, borderTop: top, borderRight: right, borderBottom: bottom, borderLeft: left, pageHeight: customHeight, pageWidth: customWidth};
jsonObj = {almaPrinter: x.options[i].value, localPrinter: localPrinterSelected, orientation: orientationValue, color: colorValue, letterFormat: format, borderUnits: units, borderTop: top, borderRight: right, borderBottom: bottom, borderLeft: left, pageHeight: customHeight, pageWidth: customWidth, numCopies: copies};
}
}
}
Expand Down Expand Up @@ -439,6 +442,10 @@ function editPrinterProfile () {
document.getElementById('borderRight').value = setBorderValue(editProfile.borderRight);
document.getElementById('pageHeight').value = editProfile.pageHeight;
document.getElementById('pageWidth').value = editProfile.pageWidth;
if (editProfile.numCopies == undefined)
document.getElementById('numCopies').value = 1;
else
document.getElementById('numCopies').value = editProfile.numCopies;
console.log ('local printer looking for ' + decodeURIComponent(editProfile.localPrinter));
for (var i = 0; i < document.getElementById('localPrinter').length; i++) {
console.log ('local printer match? ' + document.getElementById('localPrinter').options[i].value);
Expand Down Expand Up @@ -506,7 +513,7 @@ function appendPrinterProfiles(almaPrinters, data) {
myObj.remove();
var mainContainer = document.getElementById("printerProfiles");
var div = document.createElement('div');
var letterFormat, borderUnits, borderTop, borderRight, borderBottom, borderLeft;
var letterFormat, borderUnits, borderTop, borderRight, borderBottom, borderLeft, copies;
div.id = 'profiles'
mainContainer.appendChild(div);
var secondContainer = document.getElementById('profiles');
Expand Down Expand Up @@ -540,6 +547,11 @@ function appendPrinterProfiles(almaPrinters, data) {
div.innerHTML = div.innerHTML + ' Page Width/Height ' + data[i].pageWidth + '/' + data[i].pageHeight + borderUnits;
div.innerHTML = div.innerHTML + ', ' + data[i].orientation + '<br>';
div.innerHTML = div.innerHTML + '&emsp; Border (' + borderUnits + '): top ' + borderTop + ', right ' + borderRight + ', bottom ' + borderBottom + ', left ' + borderLeft + '<br>';
if (data[i].numCopies == undefined)
copies = 1
else
copies = data[i].numCopies;
div.innerHTML = div.innerHTML + '&emsp; Copies: ' + copies + '<br>';
secondContainer.appendChild(div);
}
}
Expand Down
2 changes: 1 addition & 1 deletion docsPrintIntervalPaused.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.2.0</title>
<title>Alma Print Daemon 2.2.1-beta-01</title>
</head>
<style>
#notification {
Expand Down
2 changes: 1 addition & 1 deletion docsPrintSleeping.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.2.0</title>
<title>Alma Print Daemon 2.2.1-beta-01</title>
</head>
<style>
#notification {
Expand Down
2 changes: 1 addition & 1 deletion docsPrintedInterval.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.2.0</title>
<title>Alma Print Daemon 2.2.1-beta-01</title>
</head>
<style>
#notification {
Expand Down
2 changes: 1 addition & 1 deletion docsPrintedManual.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.2.0</title>
<title>Alma Print Daemon 2.2.1-beta-01</title>
</head>
<style>
#notification {
Expand Down
2 changes: 1 addition & 1 deletion docsRetrievalErrorInterval.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.2.0-beta-03</title>
<title>Alma Print Daemon 2.2.1-beta-01</title>
</head>
<style>
#notification {
Expand Down
2 changes: 1 addition & 1 deletion docsRetrievalErrorManual.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.2.0</title>
<title>Alma Print Daemon 2.2.1-beta-01</title>
</head>
<style>
#notification {
Expand Down
15 changes: 11 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ let mode;
let lastAlmaPrinter = 0;
let useLandscape = false;
let useColor = false;
let numCopies = 1;
let useLocalPrinter;
let menuOffset = 0;
let printouts;
Expand Down Expand Up @@ -290,7 +291,7 @@ function createWindow () {
width: 600,
height: 625,
show: true,
title: "Alma Print Daemon 2.2.0",
title: "Alma Print Daemon 2.2.1-beta-01",
webPreferences: {
//preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true
Expand All @@ -310,7 +311,7 @@ function createWindow () {
getLocalPrinter(printDocs.printout[docIndex].printer.value);
}

mainWindow.webContents.print({silent: true, landscape: useLandscape, color: useColor, deviceName: useLocalPrinter}, (success, errorType) => {
mainWindow.webContents.print({silent: true, landscape: useLandscape, color: useColor, deviceName: useLocalPrinter, copies: Math.floor(numCopies)}, (success, errorType) => {
if (!success) {
//Checking success here should work, according to Electron doc...but doesn't...at least not for "invalid deviceName" error.
console.log ('Printing document failed on ' + useLocalPrinter + ' with error ' + errorType + '. Skipping to next document.');
Expand Down Expand Up @@ -761,7 +762,12 @@ function getLocalPrinter(almaPrinter) {
borderLeft = setBorderValue(configSettings.almaPrinterProfiles[i].borderLeft) + borderUnits;
customHeight = configSettings.almaPrinterProfiles[i].pageHeight + borderUnits;
customWidth = configSettings.almaPrinterProfiles[i].pageWidth + borderUnits;


if (configSettings.almaPrinterProfiles[i].numCopies == undefined)
numCopies = 1;
else
numCopies = configSettings.almaPrinterProfiles[i].numCopies;

if (letterFormat == 'Custom')
pdfOptions = {
height: customHeight,
Expand Down Expand Up @@ -792,7 +798,8 @@ function getLocalPrinter(almaPrinter) {

printOptions = {
"landscape": useLandscape,
"color": useColor
"color": useColor,
"copies": Math.floor(numCopies)
}
printer.setPrinter (useLocalPrinter);
console.log ("Local printer settings: useLandscape = " + useLandscape + " useColor = " + useColor + " useLocalPrinter = " + useLocalPrinter);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alma-print-daemon",
"version": "2.2.0",
"version": "2.2.1-beta-01",
"description": "Alma Print Daemon",
"main": "main.js",
"dependencies": {
Expand Down

0 comments on commit 9a738ef

Please sign in to comment.