Commit afac180a authored by Romain Courteaud's avatar Romain Courteaud

erp5_document_scanner: store the preferred device in session storage

parent 071d2901
......@@ -7,7 +7,8 @@
FileReader, DataView, URL, fx) {
"use strict";
var CROPPER_DATA_JIO_KEY = 'cropperjs_data_';
var CROPPER_DATA_JIO_KEY = 'cropperjs_data_',
DEVICE_JIO_KEY = 'preferred_device';
function getDevicePreferredCropperData(gadget) {
return gadget.session_storage_jio.get(CROPPER_DATA_JIO_KEY + gadget.state.device_id)
......@@ -27,6 +28,27 @@
);
}
function getPreferredDevice(gadget) {
return gadget.session_storage_jio.get(DEVICE_JIO_KEY)
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
return {};
}
throw error;
})
.push(function (jio_document) {
return jio_document.device_id;
});
}
function putPreferredDevice(gadget, device_id) {
return gadget.session_storage_jio.put(
DEVICE_JIO_KEY,
{device_id: device_id}
);
}
//////////////////////////////////////////////////
// Browser API to promise
//////////////////////////////////////////////////
......@@ -848,7 +870,10 @@
camera_list = gadget.state.camera_list,
default_value = JSON.parse(options.value);
return selectMediaDevice(camera_list, gadget.state.device_id, false)
return getPreferredDevice(gadget)
.push(function (preferred_device_id) {
return selectMediaDevice(camera_list, preferred_device_id, false);
})
.push(function (device_id) {
if (camera_list.indexOf(device_id) === -1) {
camera_list.push(device_id);
......@@ -995,12 +1020,15 @@
} else {
camera_list = [device_id];
}
return putPreferredDevice(gadget, device_id)
.push(function () {
return gadget.changeState({
display_step: 'display_video',
camera_list: camera_list,
device_id: device_id
});
});
});
}
if (evt.target.className.indexOf("show-img") !== -1) {
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>983.1729.31351.955</string> </value>
<value> <string>983.2714.63510.3754</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1586185444.24</float>
<float>1586244257.05</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment