Commit 110d9931 authored by Romain Courteaud's avatar Romain Courteaud

erp5_document_scanner: handle more asynchronous methods from cropper

parent aa2c92ce
...@@ -22,8 +22,12 @@ ...@@ -22,8 +22,12 @@
if (gadget.props.cropper) { if (gadget.props.cropper) {
gadget.props.cropper.destroy(); gadget.props.cropper.destroy();
} }
gadget.props.cropper = new Cropper(root.querySelector('.photo'), { // creating Cropper is asynchronous
data: gadget.props.preferred_cropped_canvas_data return new RSVP.Promise(function (resolve) {
gadget.props.cropper = new Cropper(root.querySelector('.photo'), {
data: gadget.props.preferred_cropped_canvas_data,
ready: resolve
});
}); });
} }
...@@ -299,7 +303,7 @@ ...@@ -299,7 +303,7 @@
} }
} }
} }
gadget.startStream(); return gadget.startStream();
} }
if (evt.target.className.indexOf("take-picture-btn") !== -1) { if (evt.target.className.indexOf("take-picture-btn") !== -1) {
evt.preventDefault(); evt.preventDefault();
...@@ -312,7 +316,7 @@ ...@@ -312,7 +316,7 @@
.push(function () { .push(function () {
root.querySelector(".camera-input").style.display = "none"; root.querySelector(".camera-input").style.display = "none";
setPageTwo(root); setPageTwo(root);
enableButton(root); return enableButton(root);
}); });
} }
if (evt.target.className.indexOf("reset-btn") !== -1) { if (evt.target.className.indexOf("reset-btn") !== -1) {
...@@ -336,9 +340,7 @@ ...@@ -336,9 +340,7 @@
var canvas = gadget.props.cropper.getCroppedCanvas(); var canvas = gadget.props.cropper.getCroppedCanvas();
disableButton(gadget.element); disableButton(gadget.element);
return new Promise(function (resolve) { return new Promise(function (resolve) {
canvas.toBlob(function (blob) { canvas.toBlob(resolve, 'image/jpeg', 0.85);
resolve(blob);
}, 'image/jpeg', 0.85);
}); });
}) })
.push(function (blob) { .push(function (blob) {
......
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