Commit 4552df7e authored by Romain Courteaud's avatar Romain Courteaud

erp5_document_scanner: fix display of the page title

parent 64b7ff09
...@@ -326,6 +326,31 @@ ...@@ -326,6 +326,31 @@
}); });
} }
function buildPageTitle(gadget, page_translation) {
var i,
len,
// By default,
displayed_title = 0;
if (gadget.state.display_index === null) {
len = gadget.state.page_count;
} else {
len = gadget.state.display_index;
}
for (i = 0; i < len; i += 1) {
if ((gadget.state.hasOwnProperty('blob_state_' + i)) &&
(gadget.state['blob_state_' + i] !== 'deleted')) {
displayed_title += 1;
}
}
return domsugar('div', {'class': 'camera-header'}, [
domsugar('h4', [
page_translation + ' ',
domsugar('label', {'class': 'page-number', text: displayed_title + 1})
])
]);
}
function buildPreviousThumbnailDom(gadget) { function buildPreviousThumbnailDom(gadget) {
var img_class, var img_class,
btn_class = "", btn_class = "",
...@@ -355,7 +380,7 @@ ...@@ -355,7 +380,7 @@
"class": btn_class, "class": btn_class,
// Do not allow to show again the current image // Do not allow to show again the current image
// or do not allow to show saving image (to simplify button management) // or do not allow to show saving image (to simplify button management)
disabled: (key === gadget.state.page) || (gadget.state['blob_state_' + key] === 'saving') disabled: (key === gadget.state.display_index) || (gadget.state['blob_state_' + key] === 'saving')
}, [domsugar("img", {"class": img_class, }, [domsugar("img", {"class": img_class,
'data-page': key, 'data-page': key,
src: gadget.state['blob_url_' + key]})])); src: gadget.state['blob_url_' + key]})]));
...@@ -365,7 +390,7 @@ ...@@ -365,7 +390,7 @@
thumbnail_dom_list.push(domsugar('button', {type: 'button', thumbnail_dom_list.push(domsugar('button', {type: 'button',
text: result_list[0], text: result_list[0],
// Do not allow to show again the current image // Do not allow to show again the current image
disabled: (len === gadget.state.page - 1), disabled: (gadget.state.display_index === null) || (len === gadget.state.display_index - 1),
"class": 'new-btn ui-btn-icon-left ui-icon-plus' "class": 'new-btn ui-btn-icon-left ui-icon-plus'
})); }));
return domsugar('ol', {"class": "thumbnail-list"}, thumbnail_dom_list); return domsugar('ol', {"class": "thumbnail-list"}, thumbnail_dom_list);
...@@ -429,15 +454,11 @@ ...@@ -429,15 +454,11 @@
domsugar('button', {type: 'button', domsugar('button', {type: 'button',
'class': 'auto-crop-btn ui-icon-fast-forward ui-btn-icon-left', 'class': 'auto-crop-btn ui-icon-fast-forward ui-btn-icon-left',
text: result_list[1][3] text: result_list[1][3]
})); })
);
div = domsugar('div', {'class': 'camera'}, [ div = domsugar('div', {'class': 'camera'}, [
domsugar('div', {'class': 'camera-header'}, [ buildPageTitle(gadget, result_list[1][2]),
domsugar('h4', [
result_list[1][2] + ' ',
domsugar('label', {'class': 'page-number', text: gadget.state.page})
])
]),
domsugar('div', {'class': 'camera-input'}, [video]), domsugar('div', {'class': 'camera-input'}, [video]),
domsugar('div', {'class': 'edit-picture'}, button_list), domsugar('div', {'class': 'edit-picture'}, button_list),
result_list[2] result_list[2]
...@@ -649,12 +670,7 @@ ...@@ -649,12 +670,7 @@
// Prepare the cropper canvas // Prepare the cropper canvas
div = domsugar('div', {'class': 'camera'}, [ div = domsugar('div', {'class': 'camera'}, [
domsugar('div', {'class': 'camera-header'}, [ buildPageTitle(gadget, result_list[0][2]),
domsugar('h4', [
result_list[0][2] + ' ',
domsugar('label', {'class': 'page-number', text: gadget.state.page})
])
]),
// If you don't know what you are doing: // If you don't know what you are doing:
// DON'T remove img from a div img-container. // DON'T remove img from a div img-container.
// DON'T replace img by canvas. // DON'T replace img by canvas.
...@@ -698,7 +714,7 @@ ...@@ -698,7 +714,7 @@
], ],
div; div;
if (gadget.state['blob_state_' + gadget.state.page] === 'error') { if (gadget.state['blob_state_' + gadget.state.display_index] === 'error') {
button_list.push( button_list.push(
// XXX TODO improve icon // XXX TODO improve icon
domsugar('button', {type: 'button', domsugar('button', {type: 'button',
...@@ -709,14 +725,9 @@ ...@@ -709,14 +725,9 @@
} }
div = domsugar('div', {'class': 'camera'}, [ div = domsugar('div', {'class': 'camera'}, [
domsugar('div', {'class': 'camera-header'}, [ buildPageTitle(gadget, result_list[0][2]),
domsugar('h4', [
result_list[0][2] + ' ',
domsugar('label', {'class': 'page-number', text: gadget.state.page + 1})
])
]),
domsugar('div', {'class': 'img-container'}, [ domsugar('div', {'class': 'img-container'}, [
domsugar('img', {src: gadget.state['blob_url_' + gadget.state.page]}) domsugar('img', {src: gadget.state['blob_url_' + gadget.state.display_index]})
]), ]),
// XXX TODO: why is the button rendering different from the other pages? // XXX TODO: why is the button rendering different from the other pages?
domsugar('div', {'class': 'edit-picture'}, button_list), domsugar('div', {'class': 'edit-picture'}, button_list),
...@@ -736,7 +747,7 @@ ...@@ -736,7 +747,7 @@
state_dict = { state_dict = {
preferred_cropped_canvas_data: gadget.cropper.getData(), preferred_cropped_canvas_data: gadget.cropper.getData(),
display_step: 'display_video', display_step: 'display_video',
page: gadget.state.page + 1, display_index: null,
page_count: gadget.state.page_count + 1 page_count: gadget.state.page_count + 1
}; };
// Keep image date, as user may need to display it again // Keep image date, as user may need to display it again
...@@ -781,7 +792,7 @@ ...@@ -781,7 +792,7 @@
.setState({ .setState({
display_step: 'display_video', display_step: 'display_video',
page: 1, display_index: null,
page_count: 0, page_count: 0,
camera_list: [] camera_list: []
}) })
...@@ -822,7 +833,7 @@ ...@@ -822,7 +833,7 @@
// Only refresh the full gadget content after the first render call // Only refresh the full gadget content after the first render call
// or if the display_step is modified // or if the display_step is modified
// or if displaying another image // or if displaying another image
if (modification_dict.first_render || modification_dict.hasOwnProperty('page')) { if (modification_dict.first_render || modification_dict.hasOwnProperty('display_index')) {
display_step = gadget.state.display_step; display_step = gadget.state.display_step;
} else { } else {
display_step = modification_dict.display_step; display_step = modification_dict.display_step;
...@@ -859,9 +870,7 @@ ...@@ -859,9 +870,7 @@
.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 el, var gadget = this,
key,
gadget = this,
tag_name = evt.target.tagName, tag_name = evt.target.tagName,
state_dict; state_dict;
...@@ -889,26 +898,17 @@ ...@@ -889,26 +898,17 @@
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 + 1 display_index: null
}); });
} }
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: 0 display_index: null
}; };
for (el in gadget.state) { state_dict['blob_state_' + gadget.state.display_index] = 'deleted';
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';
return gadget.changeState(state_dict); return gadget.changeState(state_dict);
} }
...@@ -933,13 +933,13 @@ ...@@ -933,13 +933,13 @@
if (evt.target.className.indexOf("retry-btn") !== -1) { if (evt.target.className.indexOf("retry-btn") !== -1) {
// XXX Ensure that you have the active process relative url // XXX Ensure that you have the active process relative url
addDetachedPromise(gadget, 'ajax_' + (gadget.state.page), addDetachedPromise(gadget, 'ajax_' + (gadget.state.display_index),
handleAsyncStore(gadget, gadget.state.page)); handleAsyncStore(gadget, gadget.state.display_index));
state_dict = { state_dict = {
display_step: 'display_video', display_step: 'display_video',
page: gadget.state.page_count + 1 display_index: null
}; };
state_dict['blob_state_' + gadget.state.page] = 'saving'; state_dict['blob_state_' + gadget.state.display_index] = 'saving';
return gadget.changeState(state_dict); return gadget.changeState(state_dict);
} }
...@@ -971,7 +971,7 @@ ...@@ -971,7 +971,7 @@
return gadget.changeState({ return gadget.changeState({
display_step: 'show_picture', display_step: 'show_picture',
page: parseInt(evt.target.getAttribute('data-page'), 10) display_index: parseInt(evt.target.getAttribute('data-page'), 10)
}); });
} }
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>982.61614.28913.46660</string> </value> <value> <string>982.62865.31516.35805</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>1585846471.58</float> <float>1585921095.31</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