Commit b34fd545 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Add a tales expression as default field value

The default value is a JSON containing 2 keys:
- the relative_url of an active process
- the list of active process image content to aggregate
By default, when the field is rendered for the first time, this tales expression is evaluated and a new active process is created at that point.
So, default json is like: {active_process: 'portal_activities/1234', image_list: []}
* store the active_process relative_url in the gadget state in the render method
* store the image_list in the gadget state in the render_method
* change getContent method to send a json build from the active_process and image_list state
parent d99d6dc3
...@@ -475,11 +475,14 @@ ...@@ -475,11 +475,14 @@
// This method is called during the ERP5 form rendering // This method is called during the ERP5 form rendering
// changeState is used to ensure not resetting the gadget current display // changeState is used to ensure not resetting the gadget current display
// if not needed // if not needed
var gadget = this; var gadget = this,
default_value = JSON.parse(options.value);
return selectMediaDevice(gadget.state.device_id, false) return selectMediaDevice(gadget.state.device_id, false)
.push(function (device_id) { .push(function (device_id) {
return gadget.changeState({ return gadget.changeState({
dialog_method: options.dialog_method, dialog_method: options.dialog_method,
active_process: default_value.active_process,
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),
device_id: device_id, device_id: device_id,
key: options.key, key: options.key,
...@@ -651,6 +654,10 @@ ...@@ -651,6 +654,10 @@
var gadget = this, var gadget = this,
result = {}; result = {};
// XXX TODO: check all blob, and only return the UUID for the one in stored state // XXX TODO: check all blob, and only return the UUID for the one in stored state
result.data_json = JSON.stringify({
active_process: gadget.state.active_process,
image_list: gadget.state.image_list
});
result[gadget.state.key] = JSON.stringify({ result[gadget.state.key] = JSON.stringify({
input_value: 'XXX', input_value: 'XXX',
preferred_cropped_canvas_data: gadget.state.preferred_cropped_canvas_data preferred_cropped_canvas_data: gadget.state.preferred_cropped_canvas_data
......
...@@ -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.29206.2173.6297</string> </value> <value> <string>981.29376.40278.19438</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>1580142156.11</float> <float>1580157393.77</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
import json
context.log("Called")
active_process = context.getPortalObject().portal_activities.newActiveProcess()
return json.dumps({
"active_process": active_process.getRelativeUrl(),
"image_list": []
})
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getDefaultBackendDataAsJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<key> <string>delegated_list</string> </key> <key> <string>delegated_list</string> </key>
<value> <value>
<list> <list>
<string>default</string>
<string>gadget_url</string> <string>gadget_url</string>
<string>renderjs_extra</string> <string>renderjs_extra</string>
<string>title</string> <string>title</string>
...@@ -51,6 +52,12 @@ ...@@ -51,6 +52,12 @@
<key> <string>tales</string> </key> <key> <string>tales</string> </key>
<value> <value>
<dictionary> <dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>field_id</string> </key> <key> <string>field_id</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -62,19 +69,19 @@ ...@@ -62,19 +69,19 @@
<item> <item>
<key> <string>gadget_url</string> </key> <key> <string>gadget_url</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
<item> <item>
<key> <string>renderjs_extra</string> </key> <key> <string>renderjs_extra</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value> </value>
</item> </item>
<item> <item>
...@@ -88,6 +95,10 @@ ...@@ -88,6 +95,10 @@
<key> <string>values</string> </key> <key> <string>values</string> </key>
<value> <value>
<dictionary> <dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>field_id</string> </key> <key> <string>field_id</string> </key>
<value> <string>my_gadget_field</string> </value> <value> <string>my_gadget_field</string> </value>
...@@ -128,7 +139,7 @@ ...@@ -128,7 +139,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>string: gadget_document_scanner.html</string> </value> <value> <string>python: here.Base_getDefaultBackendDataAsJSON()</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
...@@ -141,12 +152,25 @@ ...@@ -141,12 +152,25 @@
<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>string: gadget_document_scanner.html</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [(\'dialog_method\', \'Base_storeDocumentFromCameraInActiveProcess\'), (\'preferred_cropped_canvas_data\', context.Base_getPreferredCropperSettingsFromSelection()),]</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/> <global name="TALESMethod" module="Products.Formulator.TALESField"/>
</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