Commit 9821abea authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Improve gadget to store images captured in Active Process

parent ecb90eb6
from base64 import decodestring
from Products.CMFActivity.ActiveResult import ActiveResult
portal = context.getPortalObject()
active_result = ActiveResult(
detail=decodestring(document_scanner_gadget)
)
if not active_process_url:
active_process = portal.portal_activities.newActiveProcess()
context.REQUEST.form["your_active_process_url"] = active_process.getRelativeUrl()
else:
active_process = portal.restrictedTraverse(active_process_url)
active_process.postResult(active_result)
return context.Base_renderForm('Base_viewUploadDocumentFromCameraDialog',
message='Captured')
<?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>portal_type=None, classification=None, synchronous_metadata_discovery=None, cancel_url=None, batch_mode=False, editable_mode=1, group=None, publication_section=None, document_scanner_gadget=None, active_process_url=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_storeDocumentFromCameraInActiveProcess</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -103,6 +103,7 @@ ...@@ -103,6 +103,7 @@
<string>your_language</string> <string>your_language</string>
<string>your_version</string> <string>your_version</string>
<string>stringfield_validator</string> <string>stringfield_validator</string>
<string>your_active_process_url</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -145,7 +146,7 @@ ...@@ -145,7 +146,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Attach Document</string> </value> <value> <string>Finish</string> </value>
</item> </item>
<item> <item>
<key> <string>unicode_mode</string> </key> <key> <string>unicode_mode</string> </key>
...@@ -153,11 +154,11 @@ ...@@ -153,11 +154,11 @@
</item> </item>
<item> <item>
<key> <string>update_action</string> </key> <key> <string>update_action</string> </key>
<value> <string></string> </value> <value> <string>Base_storeDocumentFromCameraInActiveProcess</string> </value>
</item> </item>
<item> <item>
<key> <string>update_action_title</string> </key> <key> <string>update_action_title</string> </key>
<value> <string></string> </value> <value> <string>Attach Image</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_active_process_url</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
} }
.video, .photo, .camera-output { .video, .photo, .camera-output {
width: auto !important; width: 100%;
height: 360px; height: 360px;
filter: brightness(1); filter: brightness(1);
text-align:center;
} }
.canvas { .canvas {
...@@ -24,10 +25,9 @@ ...@@ -24,10 +25,9 @@
.camera { .camera {
display: inline-block; display: inline-block;
padding-top: 2em;
} }
.startbutton, .crop-button { .startbutton, .capture-button {
display: block; display: block;
position: relative; position: relative;
margin: 0 auto; margin: 0 auto;
...@@ -45,3 +45,10 @@ ...@@ -45,3 +45,10 @@
font-family: "Lucida Grande", "Arial", sans-serif; font-family: "Lucida Grande", "Arial", sans-serif;
width: 760px; width: 760px;
} }
@media screen
and (min-device-width: 600px) {
.camera {
margin-top: 1em;
}
}
\ No newline at end of file
...@@ -17,15 +17,15 @@ ...@@ -17,15 +17,15 @@
</select> </select>
</div> </div>
<div class="camera"> <div class="camera">
<div class="camera-input"> <div class="camera-input" style="display:none">
<video class="video">Webcam is not available</video> <video class="video">Webcam is not available</video>
<button type="button" class="startbutton">Take a picture!</button> <button type="button" class="startbutton">Take a picture!</button>
</div> </div>
<canvas class="canvas"></canvas> <canvas class="canvas"></canvas>
<div class="camera-output" style="display:none"> <div class="camera-output" style="display:none">
<img class="photo" alt="Photo"> <img class="photo" alt="Photo">
<input class="photoInput" type="hidden"> <input class="photoInput" type="hidden">
<button class="crop-button">Crop</button> <button class="capture-button">Capture</button>
</div> </div>
</div> </div>
</body> </body>
......
...@@ -188,6 +188,7 @@ ...@@ -188,6 +188,7 @@
if (video) { if (video) {
video.pause(); video.pause();
} }
root.querySelector(".camera-input").style.display = "";
if (evt.target.value) { if (evt.target.value) {
return startup(root, evt.target.value); return startup(root, evt.target.value);
} }
...@@ -196,18 +197,20 @@ ...@@ -196,18 +197,20 @@
}, false, true) }, false, true)
.onEvent("click", function (evt) { .onEvent("click", function (evt) {
var canvasData; var gadget, canvasData;
if (evt.target.className == "startbutton") { if (evt.target.className == "startbutton") {
return this.getElement() return this.getElement()
.push(function (gadget) { .push(function (el) {
return takePicture(gadget); el.querySelector(".camera-input").style.display = "none";
return takePicture(el);
}); });
} }
if (evt.target.className == "capture-button") { if (evt.target.className == "capture-button") {
canvasData = cropper.getCanvasData(); canvasData = cropper.getCanvasData();
storage.put("settings", cropper.getData()); storage.put("settings", cropper.getData());
return RSVP.Queue() return this.getElement()
.push(function () { .push(function (el) {
gadget = el;
return cropper.getCroppedCanvas(); return cropper.getCroppedCanvas();
}) })
.push(function (canvas) { .push(function (canvas) {
...@@ -230,6 +233,7 @@ ...@@ -230,6 +233,7 @@
photo.src = base64data; photo.src = base64data;
photoInput.value = realData; photoInput.value = realData;
gadget.querySelector(".capture-button").style.display = "none";
cropper.destroy(); cropper.destroy();
}); });
} }
......
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