Commit f337eb74 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Fix pagination

parent 4570c90d
...@@ -192,10 +192,10 @@ ...@@ -192,10 +192,10 @@
for (j = 0; j < len; j += 1) { for (j = 0; j < len; j += 1) {
device = info_list[j]; device = info_list[j];
if (device.kind === 'videoinput') { if (device.kind === 'videoinput') {
if ((!current_device_id) || if (!current_device_id ||
(camera_list.indexOf(device.deviceId) === -1 && (camera_list.indexOf(device.deviceId) === -1 &&
(force_new_device && (device.deviceId !== current_device_id)) || ((force_new_device && (device.deviceId !== current_device_id)) ||
(!force_new_device && (device.deviceId === current_device_id)))) { (!force_new_device && (device.deviceId === current_device_id))))) {
return device.deviceId; return device.deviceId;
} }
} }
...@@ -227,38 +227,39 @@ ...@@ -227,38 +227,39 @@
} }
function buildPreviousThumbnailDom(gadget) { function buildPreviousThumbnailDom(gadget) {
var i, var img_class,
img_class,
btn_class = "", btn_class = "",
len = gadget.state.page_count, len = gadget.state.page_count,
thumbnail_dom_list = []; thumbnail_dom_list = [];
return gadget.getTranslationList(["New Page"]) return gadget.getTranslationList(["New Page"])
.push(function (result_list) { .push(function (result_list) {
for (i = 0; i < len; i += 1) { var key, el;
// XXX TODO display a loader when saving for (el in gadget.state) {
if (gadget.state['blob_state_' + i] !== 'deleted') { if (gadget.state.hasOwnProperty(el) && el.indexOf("blob_state_") !== -1) {
if (gadget.state['blob_state_' + i] === "error") { key = parseInt(el.replace("blob_state_", ""), 10);
img_class = "show-img upload-error"; if (gadget.state['blob_state_' + key] !== 'deleted') {
} else { if (gadget.state['blob_state_' + key] === "error") {
img_class = "show-img"; img_class = "show-img upload-error";
} } else {
img_class = "show-img";
}
if (gadget.state['blob_state_' + i] === "saving") { if (gadget.state['blob_state_' + key] === "saving") {
btn_class = "btn-thumbnail ui-btn-icon-top ui-icon-spinner"; btn_class = "btn-thumbnail ui-btn-icon-top ui-icon-spinner";
} else { } else {
btn_class = "btn-thumbnail"; btn_class = "btn-thumbnail";
}
thumbnail_dom_list.push(domsugar('button', {
type: "button",
"class": btn_class,
// Do not allow to show again the current image
// or do not allow to show saving image (to simplify button management)
disabled: (key === gadget.state.page) || (gadget.state['blob_state_' + key] === 'saving')
}, [domsugar("img", {"class": img_class,
'data-page': key,
src: gadget.state['blob_url_' + key]})]));
} }
thumbnail_dom_list.push(domsugar('button', {
type: "button",
"class": btn_class,
// Do not allow to show again the current image
// or do not allow to show saving image (to simplify button management)
disabled: (i === gadget.state.page) || (gadget.state['blob_state_' + i] === 'saving')
}, [domsugar("img", {"class": img_class,
'data-page': i,
src: gadget.state['blob_url_' + i]})]));
} }
} }
thumbnail_dom_list.push(domsugar('button', {type: 'button', thumbnail_dom_list.push(domsugar('button', {type: 'button',
...@@ -368,9 +369,9 @@ ...@@ -368,9 +369,9 @@
.push(function (result_list) { .push(function (result_list) {
var bitmap = result_list[0], var bitmap = result_list[0],
img = domsugar("img", {"src": result_list[1].target.result}), img = domsugar("img", {"src": result_list[1].target.result}),
div = gadget.element.querySelector(".camera-input"),
canvas = domsugar('canvas', {'class': 'canvas'}); canvas = domsugar('canvas', {'class': 'canvas'});
div = gadget.element.querySelector(".camera-input");
gadget.detached_promise_dict.media_stream.cancel('Not needed anymore, as captured'); gadget.detached_promise_dict.media_stream.cancel('Not needed anymore, as captured');
div.replaceChild(img, div.firstElementChild); div.replaceChild(img, div.firstElementChild);
canvas.width = bitmap.width; canvas.width = bitmap.width;
...@@ -587,7 +588,9 @@ ...@@ -587,7 +588,9 @@
.onEvent("click", function (evt) { .onEvent("click", function (evt) {
// Only handle click on BUTTON and IMG element // Only handle click on BUTTON and IMG element
var gadget = this, var el,
key,
gadget = this,
tag_name = evt.target.tagName, tag_name = evt.target.tagName,
state_dict; state_dict;
...@@ -600,8 +603,7 @@ ...@@ -600,8 +603,7 @@
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 (tag_name === 'BUTTON' || ( if (tag_name === 'BUTTON' || (tag_name === 'IMG' && !evt.target.parentElement.disabled)) {
tag_name === '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;
}); });
...@@ -622,15 +624,25 @@ ...@@ -622,15 +624,25 @@
if (evt.target.className.indexOf("new-btn") !== -1) { if (evt.target.className.indexOf("new-btn") !== -1) {
return gadget.changeState({ return gadget.changeState({
display_step: 'display_video', display_step: 'display_video',
page: gadget.state.page_count + 1 page: gadget.state.page + 1
}); });
} }
if (evt.target.className.indexOf("delete-btn") !== -1) { if (evt.target.className.indexOf("delete-btn") !== -1) {
state_dict = { state_dict = {
display_step: 'display_video', display_step: 'display_video',
page: gadget.state.page_count + 1 page: 0
}; };
for (el in gadget.state) {
if (gadget.state.hasOwnProperty(el) && el.indexOf("blob_state_") !== -1) {
key = el.replace("blob_state_", "");
if (gadget.state['blob_state_' + key] !== 'deleted') {
state_dict.page = state_dict.page + 1;
}
}
}
state_dict['blob_state_' + gadget.state.page] = 'deleted'; state_dict['blob_state_' + gadget.state.page] = 'deleted';
return gadget.changeState(state_dict); return gadget.changeState(state_dict);
} }
...@@ -657,6 +669,8 @@ ...@@ -657,6 +669,8 @@
// Keep image date, as user may need to display it again // Keep image date, as user may need to display it again
state_dict['blob_url_' + gadget.state.page_count] = evt.target.result; state_dict['blob_url_' + gadget.state.page_count] = evt.target.result;
state_dict['blob_state_' + gadget.state.page_count] = 'saving'; state_dict['blob_state_' + gadget.state.page_count] = 'saving';
state_dict['blob_uuid_' + gadget.state.page_count] = null;
return gadget.changeState(state_dict); return gadget.changeState(state_dict);
}) })
.push(function () { .push(function () {
......
...@@ -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.65265.9437.56217</string> </value> <value> <string>982.7372.6060.34525</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>1582308884.59</float> <float>1582764289.53</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