Commit 071d2901 authored by Romain Courteaud's avatar Romain Courteaud

erp5_document_scanner: store the cropper data in session storage

Allow user to reuse the same cropper area in a session.
parent ef13c749
...@@ -7,6 +7,26 @@ ...@@ -7,6 +7,26 @@
FileReader, DataView, URL, fx) { FileReader, DataView, URL, fx) {
"use strict"; "use strict";
var CROPPER_DATA_JIO_KEY = 'cropperjs_data_';
function getDevicePreferredCropperData(gadget) {
return gadget.session_storage_jio.get(CROPPER_DATA_JIO_KEY + gadget.state.device_id)
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
return null;
}
throw error;
});
}
function putDevicePreferredCropperData(gadget, data) {
return gadget.session_storage_jio.put(
CROPPER_DATA_JIO_KEY + gadget.state.device_id,
data
);
}
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Browser API to promise // Browser API to promise
////////////////////////////////////////////////// //////////////////////////////////////////////////
...@@ -201,7 +221,7 @@ ...@@ -201,7 +221,7 @@
checkOrientation: false, checkOrientation: false,
zoomable: false, zoomable: false,
movable: false, movable: false,
data: data, data: data || {},
ready: function () { ready: function () {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -434,7 +454,8 @@ ...@@ -434,7 +454,8 @@
return RSVP.all([ return RSVP.all([
getVideoDeviceList(), getVideoDeviceList(),
gadget.getTranslationList(["Capture", "Change Camera", "Page", "1-click Capture"]), gadget.getTranslationList(["Capture", "Change Camera", "Page", "1-click Capture"]),
buildPreviousThumbnailDom(gadget) buildPreviousThumbnailDom(gadget),
getDevicePreferredCropperData(gadget)
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
...@@ -455,12 +476,14 @@ ...@@ -455,12 +476,14 @@
text: result_list[1][0] text: result_list[1][0]
})); }));
button_list.push( if (result_list[3] !== null) {
domsugar('button', {type: 'button', button_list.push(
'class': 'auto-crop-btn ui-icon-fast-forward ui-btn-icon-left', domsugar('button', {type: 'button',
text: result_list[1][3] 'class': 'auto-crop-btn ui-icon-fast-forward ui-btn-icon-left',
}) text: result_list[1][3]
); })
);
}
div = domsugar('div', {'class': 'camera'}, [ div = domsugar('div', {'class': 'camera'}, [
buildPageTitle(gadget, result_list[1][2]), buildPageTitle(gadget, result_list[1][2]),
...@@ -646,7 +669,8 @@ ...@@ -646,7 +669,8 @@
return RSVP.all([ return RSVP.all([
gadget.getTranslationList(["Delete", "Save", "Page"]), gadget.getTranslationList(["Delete", "Save", "Page"]),
createLoadedImgElement(blob_url), createLoadedImgElement(blob_url),
buildPreviousThumbnailDom(gadget) buildPreviousThumbnailDom(gadget),
getDevicePreferredCropperData(gadget)
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
...@@ -691,7 +715,7 @@ ...@@ -691,7 +715,7 @@
btn.classList.remove("ui-icon-spinner"); btn.classList.remove("ui-icon-spinner");
addDetachedPromise(gadget, 'cropper', addDetachedPromise(gadget, 'cropper',
handleCropper(img, handleCropper(img,
gadget.state.preferred_cropped_canvas_data, result_list[3],
defer.resolve)); defer.resolve));
return defer.promise; return defer.promise;
}) })
...@@ -750,7 +774,6 @@ ...@@ -750,7 +774,6 @@
var canvas = gadget.cropper.getCroppedCanvas(), var canvas = gadget.cropper.getCroppedCanvas(),
state_dict; state_dict;
state_dict = { state_dict = {
preferred_cropped_canvas_data: gadget.cropper.getData(),
display_step: 'display_video', display_step: 'display_video',
display_index: null, display_index: null,
page_count: gadget.state.page_count + 1 page_count: gadget.state.page_count + 1
...@@ -761,7 +784,11 @@ ...@@ -761,7 +784,11 @@
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; state_dict['blob_uuid_' + gadget.state.page_count] = null;
return gadget.changeState(state_dict) // Store the cropper data area
return putDevicePreferredCropperData(gadget, gadget.cropper.getData())
.push(function () {
return gadget.changeState(state_dict);
})
.push(function () { .push(function () {
// 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_count - 1), addDetachedPromise(gadget, 'ajax_' + (gadget.state.page_count - 1),
...@@ -777,6 +804,18 @@ ...@@ -777,6 +804,18 @@
rJS(window) rJS(window)
.ready(function () { .ready(function () {
this.detached_promise_dict = {}; this.detached_promise_dict = {};
// use to store temporary cropper data area
this.session_storage_jio = jIO.createJIO({
type: "document",
document_id: "/",
sub_storage: {
type: "zip",
sub_storage: {
type: "local",
sessiononly: true
}
}
});
}) })
.declareJob('raise', function (error) { .declareJob('raise', function (error) {
throw error; throw error;
...@@ -819,7 +858,6 @@ ...@@ -819,7 +858,6 @@
active_process: default_value.active_process, active_process: default_value.active_process,
image_list: default_value.image_list, image_list: default_value.image_list,
camera_list: camera_list, camera_list: camera_list,
preferred_cropped_canvas_data: {},
preferred_image_settings_data: JSON.parse(options.preferred_image_settings_data), preferred_image_settings_data: JSON.parse(options.preferred_image_settings_data),
device_id: device_id, device_id: device_id,
key: options.key, key: options.key,
...@@ -959,7 +997,6 @@ ...@@ -959,7 +997,6 @@
} }
return gadget.changeState({ return gadget.changeState({
display_step: 'display_video', display_step: 'display_video',
preferred_cropped_canvas_data: {},
camera_list: camera_list, camera_list: camera_list,
device_id: device_id device_id: device_id
}); });
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>983.1655.22186.31027</string> </value> <value> <string>983.1729.31351.955</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>1586181306.42</float> <float>1586185444.24</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