Commit dba33a10 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Clean up code and make jslint happy

parent 4e60b3bd
/*jslint indent: 2, unparam: true */ /*jslint indent: 2, unparam: true */
/*global rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData, Caman, URL, File*/ /*global rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData, Caman*/
(function (rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData, Caman, URL, File) { (function (rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData, caman) {
"use strict"; "use strict";
////////////////////////////////////////////////// //////////////////////////////////////////////////
...@@ -51,10 +51,7 @@ ...@@ -51,10 +51,7 @@
} }
function handleCropper(element, data, callback) { function handleCropper(element, data, callback) {
var cropper, var cropper;
queue = new RSVP.Queue(),
img = domsugar("img"),
canvas = domsugar('canvas', {'class': 'canvas'});
function canceller() { function canceller() {
cropper.destroy(); cropper.destroy();
...@@ -97,7 +94,7 @@ ...@@ -97,7 +94,7 @@
}); });
}) })
.push(function (evt) { .push(function (evt) {
var state_dict = {}, var state_dict = {};
data = JSON.parse(evt.target.responseText); data = JSON.parse(evt.target.responseText);
state_dict['blob_state_' + blob_page] = 'OK'; state_dict['blob_state_' + blob_page] = 'OK';
state_dict['blob_uuid_' + blob_page] = data.uuid; state_dict['blob_uuid_' + blob_page] = data.uuid;
...@@ -188,12 +185,6 @@ ...@@ -188,12 +185,6 @@
return gadget.getTranslationList(["Page", "New Page"]) return gadget.getTranslationList(["Page", "New Page"])
.push(function (result_list) { .push(function (result_list) {
thumbnail_dom_list.push(domsugar('button', {type: 'button',
// Do not allow to show again the current image
disabled: (len === gadget.state.page - 1),
'class': 'new-btn ui-btn-icon-left ui-icon-plus'
}));
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
// XXX TODO display a loader when saving // XXX TODO display a loader when saving
if (gadget.state['blob_state_' + i] !== 'deleted') { if (gadget.state['blob_state_' + i] !== 'deleted') {
...@@ -217,7 +208,13 @@ ...@@ -217,7 +208,13 @@
src: gadget.state['blob_url_' + i]})])); src: gadget.state['blob_url_' + i]})]));
} }
} }
return domsugar('ol', {"class": "thumbnail-list"}, thumbnail_dom_list); return domsugar("div", {"class": "thumbnail-area"}, [
domsugar('button', {type: 'button',
// Do not allow to show again the current image
disabled: (len === gadget.state.page - 1),
'class': 'new-btn ui-btn-icon-left ui-icon-plus'}),
domsugar('ol', {"class": "thumbnail-list"}, thumbnail_dom_list)
]);
}); });
} }
...@@ -293,9 +290,7 @@ ...@@ -293,9 +290,7 @@
// Capture the media stream // Capture the media stream
function captureAndRenderPicture(gadget) { function captureAndRenderPicture(gadget) {
var file, var settings = gadget.state.preferred_image_settings_data,
settings = gadget.state.preferred_image_settings_data,
data = gadget.state.preferred_cropped_canvas_data,
image_capture = new window.ImageCapture( image_capture = new window.ImageCapture(
gadget.element.querySelector('video').srcObject.getVideoTracks()[0] gadget.element.querySelector('video').srcObject.getVideoTracks()[0]
), ),
...@@ -319,7 +314,7 @@ ...@@ -319,7 +314,7 @@
var canvas = domsugar('canvas', {'class': 'canvas'}); var canvas = domsugar('canvas', {'class': 'canvas'});
return new Promise(function (resolve) { return new Promise(function (resolve) {
// XXX the correct usage is `new Caman()` but the library does not support it // XXX the correct usage is `new Caman()` but the library does not support it
Caman(canvas, result.target.result, function () { caman(canvas, result.target.result, function () {
if (settings.brightness && settings.brightness !== 0) { if (settings.brightness && settings.brightness !== 0) {
this.brightness(settings.brightness); this.brightness(settings.brightness);
} }
...@@ -337,9 +332,8 @@ ...@@ -337,9 +332,8 @@
}); });
}); });
}); });
} else {
return blob;
} }
return blob;
}) })
.push(function (blob) { .push(function (blob) {
return RSVP.all([ return RSVP.all([
...@@ -524,7 +518,7 @@ ...@@ -524,7 +518,7 @@
// if display_step is not modified // if display_step is not modified
return buildPreviousThumbnailDom(gadget) return buildPreviousThumbnailDom(gadget)
.push(function (result) { .push(function (result) {
thumbnail_container = gadget.element.querySelector('.thumbnail-list'); thumbnail_container = gadget.element.querySelector('.thumbnail-area');
thumbnail_container.parentElement.replaceChild( thumbnail_container.parentElement.replaceChild(
result, result,
thumbnail_container thumbnail_container
...@@ -659,7 +653,7 @@ ...@@ -659,7 +653,7 @@
for (key in gadget.state) { for (key in gadget.state) {
if (gadget.state.hasOwnProperty(key)) { if (gadget.state.hasOwnProperty(key)) {
if (key.indexOf("blob_state_") !== -1 && if (key.indexOf("blob_state_") !== -1 &&
gadget.state[key] == "OK") { gadget.state[key] === "OK") {
uuid_key = "blob_uuid_" + key.replace("blob_state_", ""); uuid_key = "blob_uuid_" + key.replace("blob_state_", "");
image_list.push(gadget.state[uuid_key]); image_list.push(gadget.state[uuid_key]);
} }
...@@ -700,4 +694,4 @@ ...@@ -700,4 +694,4 @@
.declareAcquiredMethod("getTranslationList", "getTranslationList"); .declareAcquiredMethod("getTranslationList", "getTranslationList");
}(rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData, Caman, URL, File)); }(rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData, Caman));
\ No newline at end of file \ No newline at end of file
...@@ -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.52410.59293.63010</string> </value> <value> <string>981.53435.24231.47104</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>1581534665.68</float> <float>1581596045.41</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