mirror of
https://github.com/grocy/grocy.git
synced 2026-04-07 05:16:15 +02:00
Remove button and nested dialog - make it a select
- Also make Cancel button gray again
This commit is contained in:
parent
d5ecc0c9c5
commit
0e8cc11366
|
|
@ -8,11 +8,11 @@ Grocy.Components.BarcodeScanner.CheckCapabilities = async function()
|
||||||
capabilities = track.getCapabilities();
|
capabilities = track.getCapabilities();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is only 1 camera, hide the camera select button
|
// If there is more than 1 camera, show the camera selection
|
||||||
var cameras = await Quagga.CameraAccess.enumerateVideoDevices();
|
var cameras = await Quagga.CameraAccess.enumerateVideoDevices();
|
||||||
var cameraPickerButton = document.querySelector('.cameraPicker');
|
var cameraSelect = document.querySelector('.cameraSelect');
|
||||||
if (cameraPickerButton) {
|
if (cameraSelect) {
|
||||||
cameraPickerButton.style.display = cameras.length > 1 ? 'inline-block' : 'none';
|
cameraSelect.style.display = cameras.length > 1 ? 'inline-block' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the camera is capable to turn on a torch.
|
// Check if the camera is capable to turn on a torch.
|
||||||
|
|
@ -206,9 +206,7 @@ $(document).on("click", "#barcodescanner-start-button", async function(e)
|
||||||
|
|
||||||
Grocy.Components.BarcodeScanner.CurrentTarget = inputElement.attr("data-target");
|
Grocy.Components.BarcodeScanner.CurrentTarget = inputElement.attr("data-target");
|
||||||
|
|
||||||
var cameras = await Quagga.CameraAccess.enumerateVideoDevices();
|
var dialog = bootbox.dialog({
|
||||||
|
|
||||||
bootbox.dialog({
|
|
||||||
message: '<div id="barcodescanner-container" class="col"><div id="barcodescanner-livestream"></div></div>',
|
message: '<div id="barcodescanner-container" class="col"><div id="barcodescanner-livestream"></div></div>',
|
||||||
title: __t('Scan a barcode'),
|
title: __t('Scan a barcode'),
|
||||||
onEscape: function()
|
onEscape: function()
|
||||||
|
|
@ -219,34 +217,6 @@ $(document).on("click", "#barcodescanner-start-button", async function(e)
|
||||||
backdrop: true,
|
backdrop: true,
|
||||||
closeButton: true,
|
closeButton: true,
|
||||||
buttons: {
|
buttons: {
|
||||||
cameraPicker: {
|
|
||||||
label: 'Camera Picker',
|
|
||||||
className: 'btn-secondary responsive-button cameraPicker',
|
|
||||||
// When clicking the camera picker button, open a second prompt and populate it with a list of cameras to choose from
|
|
||||||
callback: function()
|
|
||||||
{
|
|
||||||
bootbox.prompt({
|
|
||||||
title: "Pick a camera",
|
|
||||||
inputType: 'select',
|
|
||||||
value: window.localStorage.getItem('cameraId'),
|
|
||||||
inputOptions: cameras.map(camera => {
|
|
||||||
const cameraSelect = {};
|
|
||||||
cameraSelect.text = camera.label ? camera.label : camera.deviceId; // Use camera label if it exists, else show device id
|
|
||||||
cameraSelect.value = camera.deviceId;
|
|
||||||
return cameraSelect;
|
|
||||||
}),
|
|
||||||
// When new camera is picked, re-initialise scanning so it picks up the new camera choice
|
|
||||||
callback: function (result) {
|
|
||||||
if ( result ) {
|
|
||||||
window.localStorage.setItem('cameraId', result);
|
|
||||||
Quagga.stop();
|
|
||||||
Grocy.Components.BarcodeScanner.StartScanning();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
torch: {
|
torch: {
|
||||||
label: '<i class="far fa-lightbulb"></i>',
|
label: '<i class="far fa-lightbulb"></i>',
|
||||||
className: 'btn-warning responsive-button torch',
|
className: 'btn-warning responsive-button torch',
|
||||||
|
|
@ -258,7 +228,7 @@ $(document).on("click", "#barcodescanner-start-button", async function(e)
|
||||||
},
|
},
|
||||||
cancel: {
|
cancel: {
|
||||||
label: __t('Cancel'),
|
label: __t('Cancel'),
|
||||||
className: 'btn-danger responsive-button',
|
className: 'btn-secondary responsive-button',
|
||||||
callback: function()
|
callback: function()
|
||||||
{
|
{
|
||||||
Grocy.Components.BarcodeScanner.StopScanning();
|
Grocy.Components.BarcodeScanner.StopScanning();
|
||||||
|
|
@ -266,6 +236,28 @@ $(document).on("click", "#barcodescanner-start-button", async function(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add camera select to existing dialog
|
||||||
|
dialog.find('.bootbox-body').append('<select class="form-control cameraSelect" style="display: none"> </select>');
|
||||||
|
var cameraSelect = document.querySelector('.cameraSelect');
|
||||||
|
|
||||||
|
var cameras = await Quagga.CameraAccess.enumerateVideoDevices();
|
||||||
|
cameras.forEach(camera => {
|
||||||
|
var option = document.createElement("option");
|
||||||
|
option.text = camera.label ? camera.label : camera.deviceId; // Use camera label if it exists, else show device id
|
||||||
|
option.value = camera.deviceId;
|
||||||
|
cameraSelect.appendChild(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set initial value to preferred camera if one exists - and if not, start out empty
|
||||||
|
cameraSelect.value = window.localStorage.getItem('cameraId');
|
||||||
|
|
||||||
|
cameraSelect.onchange = function(){
|
||||||
|
window.localStorage.setItem('cameraId', cameraSelect.value);
|
||||||
|
Quagga.stop();
|
||||||
|
Grocy.Components.BarcodeScanner.StartScanning();
|
||||||
|
};
|
||||||
|
|
||||||
Grocy.Components.BarcodeScanner.StartScanning();
|
Grocy.Components.BarcodeScanner.StartScanning();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user