Commit 057e5808 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Extend code to disable button properly and display a...

erp5_document_scanner: Extend code to disable button properly and display a preview before open Cropper
parent 466868f0
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
this.greyscale(); this.greyscale();
} }
this.render(function () { this.render(function () {
// XXX canceller should be called automatically // XXX canceller should be called automatically ?
canceller(); canceller();
resolve([this.context.canvas, settings.compression]); resolve([this.context.canvas, settings.compression]);
}); });
...@@ -338,6 +338,7 @@ ...@@ -338,6 +338,7 @@
// Capture the media stream // Capture the media stream
function captureAndRenderPicture(gadget) { function captureAndRenderPicture(gadget) {
var settings = gadget.state.preferred_image_settings_data, var settings = gadget.state.preferred_image_settings_data,
btn = gadget.element.querySelector(".take-picture-btn"),
image_capture = new window.ImageCapture( image_capture = new window.ImageCapture(
gadget.element.querySelector('video').srcObject.getVideoTracks()[0] gadget.element.querySelector('video').srcObject.getVideoTracks()[0]
), ),
...@@ -345,18 +346,27 @@ ...@@ -345,18 +346,27 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
btn.classList.remove("ui-icon-circle");
btn.classList.add("ui-icon-spinner");
return image_capture.getPhotoCapabilities(); return image_capture.getPhotoCapabilities();
}) })
.push(function (capabilities) { .push(function (capabilities) {
return image_capture.takePhoto({imageWidth: capabilities.imageWidth.max}); return image_capture.takePhoto({imageWidth: capabilities.imageWidth.max});
}) })
.push(function (blob) { .push(function (blob) {
return createImageBitmap(blob); return RSVP.all([
createImageBitmap(blob),
jIO.util.readBlobAsDataURL(blob)
]);
}) })
.push(function (bitmap) { .push(function (result_list) {
var canvas = domsugar('canvas', {'class': 'canvas'}); var bitmap = result_list[0],
gadget.detached_promise_dict.media_stream.cancel('Not needed anymore, as captured'); img = domsugar("img", {"src": result_list[1].target.result}),
div = gadget.element.querySelector(".camera-input"),
canvas = domsugar('canvas', {'class': 'canvas'});
gadget.detached_promise_dict.media_stream.cancel('Not needed anymore, as captured');
div.replaceChild(img, div.firstElementChild);
canvas.width = bitmap.width; canvas.width = bitmap.width;
canvas.height = bitmap.height; canvas.height = bitmap.height;
canvas.getContext('2d').drawImage(bitmap, 0, 0); canvas.getContext('2d').drawImage(bitmap, 0, 0);
...@@ -409,6 +419,8 @@ ...@@ -409,6 +419,8 @@
// XXX How to change the dom only when cropper is ready? // XXX How to change the dom only when cropper is ready?
// For now, it needs to access dom element size // For now, it needs to access dom element size
gadget.element.replaceChild(div, gadget.element.firstElementChild); gadget.element.replaceChild(div, gadget.element.firstElementChild);
btn.classList.add("ui-icon-circle");
btn.classList.remove("ui-icon-spinner");
addDetachedPromise(gadget, 'cropper', addDetachedPromise(gadget, 'cropper',
handleCropper(img, handleCropper(img,
gadget.state.preferred_cropped_canvas_data, gadget.state.preferred_cropped_canvas_data,
...@@ -571,7 +583,8 @@ ...@@ -571,7 +583,8 @@
evt.preventDefault(); evt.preventDefault();
// If user clicks on same image twice, // If user clicks on same image twice,
// we don't need to disable everything again if parent is already disabled // we don't need to disable everything again if parent is already disabled
if (evt.target.tagName === 'IMG' && !evt.target.parentElement.disabled) { if (evt.target.tagName === 'BUTTON' || (
evt.target.tagName === 'IMG' && !evt.target.parentElement.disabled)) {
gadget.element.querySelectorAll('button').forEach(function (elt) { gadget.element.querySelectorAll('button').forEach(function (elt) {
elt.disabled = true; elt.disabled = true;
}); });
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>981.61472.39170.22050</string> </value> <value> <string>981.61542.11546.10973</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>1582078293.94</float> <float>1582082340.93</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