Commit 17b1d6d8 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 9635c1f6
/*jslint indent: 2, unparam: true */
/*global 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) {
/*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, FormData) {
"use strict";
//////////////////////////////////////////////////
......@@ -78,23 +78,19 @@
}
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()
.push(function () {
// XXX TODO: jio.util.ajax with
/*
JSON.stringify({
input_value: gadget.state.blob_url_XXX.split(';')[1].split(',')[1],
// preferred_cropped_canvas_data: gadget.state.preferred_cropped_canvas_data
})
*/
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))
]);
return jIO.util.ajax({
"type": "POST",
"url": gadget.state.store_new_image_cropped_method,
"data": data,
"xhrFields": {
withCredentials: true
}
});
})
.push(function () {
var state_dict = {};
......@@ -481,6 +477,7 @@
.push(function (device_id) {
return gadget.changeState({
dialog_method: options.dialog_method,
store_new_image_cropped_method: options.store_new_image_cropped_method,
active_process: default_value.active_process,
image_list: default_value.image_list,
preferred_cropped_canvas_data: JSON.parse(options.preferred_cropped_canvas_data),
......@@ -689,4 +686,4 @@
.declareAcquiredMethod("getTranslationList", "getTranslationList");
}(rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap));
\ No newline at end of file
}(rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData));
\ No newline at end of file
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>981.29376.40278.19438</string> </value>
<value> <string>981.29544.47237.55466</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1580157393.77</float>
<float>1580162507.4</float>
<string>UTC</string>
</tuple>
</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 @@
<dictionary>
<item>
<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>
</dictionary>
</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