Commit 62ffdb42 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: POST image cropped to backend

* change the `extra renderjs` parameters list to pass a Python script to call when a new image is cropped.
* change the gadget to use jio.util.ajax with the script full url (provided by the server)
parent f655ae26
/*jslint indent: 2, unparam: true */ /*jslint indent: 2, unparam: true */
/*global rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap*/ /*global rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData*/
(function (rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap) { (function (rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData) {
"use strict"; "use strict";
////////////////////////////////////////////////// //////////////////////////////////////////////////
...@@ -78,23 +78,19 @@ ...@@ -78,23 +78,19 @@
} }
function handleAsyncStore(gadget, blob_page) { function handleAsyncStore(gadget, blob_page) {
var data = new FormData();
data.append("input_value",
gadget.state['blob_url_' + blob_page].split(';')[1].split(',')[1]);
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
// XXX TODO: jio.util.ajax with return jIO.util.ajax({
/* "type": "POST",
JSON.stringify({ "url": gadget.state.store_new_image_cropped_method,
input_value: gadget.state.blob_url_XXX.split(';')[1].split(',')[1], "data": data,
// preferred_cropped_canvas_data: gadget.state.preferred_cropped_canvas_data "xhrFields": {
}) withCredentials: true
*/ }
function getRandomInt(max) { });
return Math.floor(Math.random() * Math.floor(max));
}
// XXX long or not, working or not, who knows?
return RSVP.any([
RSVP.delay(2000 + getRandomInt(3000)),
RSVP.timeout(2000 + getRandomInt(3000))
]);
}) })
.push(function () { .push(function () {
var state_dict = {}; var state_dict = {};
...@@ -481,6 +477,7 @@ ...@@ -481,6 +477,7 @@
.push(function (device_id) { .push(function (device_id) {
return gadget.changeState({ return gadget.changeState({
dialog_method: options.dialog_method, dialog_method: options.dialog_method,
store_new_image_cropped_method: options.store_new_image_cropped_method,
active_process: default_value.active_process, active_process: default_value.active_process,
image_list: default_value.image_list, image_list: default_value.image_list,
preferred_cropped_canvas_data: JSON.parse(options.preferred_cropped_canvas_data), preferred_cropped_canvas_data: JSON.parse(options.preferred_cropped_canvas_data),
...@@ -689,4 +686,4 @@ ...@@ -689,4 +686,4 @@
.declareAcquiredMethod("getTranslationList", "getTranslationList"); .declareAcquiredMethod("getTranslationList", "getTranslationList");
}(rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap)); }(rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData));
\ 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.29376.40278.19438</string> </value> <value> <string>981.29544.47237.55466</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>1580157393.77</float> <float>1580162507.4</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_storeNewImageCropped</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: [(\'dialog_method\', \'Base_storeDocumentFromCameraInActiveProcess\'), (\'preferred_cropped_canvas_data\', context.Base_getPreferredCropperSettingsFromSelection()),]</string> </value> <value> <string>python: [(\'dialog_method\', \'Base_storeDocumentFromCameraInActiveProcess\'), (\'preferred_cropped_canvas_data\', context.Base_getPreferredCropperSettingsFromSelection()), ("store_new_image_cropped_method", \'Base_storeNewImageCropped\')]</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
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