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 @@ ...@@ -7,7 +7,8 @@
FileReader, DataView, URL, fx) { FileReader, DataView, URL, fx) {
"use strict"; "use strict";
var CROPPER_DATA_JIO_KEY = 'cropperjs_data_'; var CROPPER_DATA_JIO_KEY = 'cropperjs_data_',
DEVICE_JIO_KEY = 'preferred_device';
function getDevicePreferredCropperData(gadget) { function getDevicePreferredCropperData(gadget) {
return gadget.session_storage_jio.get(CROPPER_DATA_JIO_KEY + gadget.state.device_id) return gadget.session_storage_jio.get(CROPPER_DATA_JIO_KEY + gadget.state.device_id)
...@@ -27,6 +28,27 @@ ...@@ -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 // Browser API to promise
////////////////////////////////////////////////// //////////////////////////////////////////////////
...@@ -848,7 +870,10 @@ ...@@ -848,7 +870,10 @@
camera_list = gadget.state.camera_list, camera_list = gadget.state.camera_list,
default_value = JSON.parse(options.value); 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) { .push(function (device_id) {
if (camera_list.indexOf(device_id) === -1) { if (camera_list.indexOf(device_id) === -1) {
camera_list.push(device_id); camera_list.push(device_id);
...@@ -995,11 +1020,14 @@ ...@@ -995,11 +1020,14 @@
} else { } else {
camera_list = [device_id]; camera_list = [device_id];
} }
return gadget.changeState({ return putPreferredDevice(gadget, device_id)
display_step: 'display_video', .push(function () {
camera_list: camera_list, return gadget.changeState({
device_id: device_id display_step: 'display_video',
}); camera_list: camera_list,
device_id: device_id
});
});
}); });
} }
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>983.1729.31351.955</string> </value> <value> <string>983.2714.63510.3754</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1586185444.24</float> <float>1586244257.05</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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