From c12ac82c1578af9204450fb2c2766d70fa2665af Mon Sep 17 00:00:00 2001
From: Tomas Peterka <tomas.peterka@nexedi.com>
Date: Fri, 8 Sep 2017 12:31:10 +0000
Subject: [PATCH] [renderjs_ui] Workflow (Form Dialog) is always in editable
 state

/reviewed-on https://lab.nexedi.com/nexedi/erp5/merge_requests/381
---
 .../rjs_gadget_erp5_pt_form_dialog_js.js      | 14 ++--
 .../rjs_gadget_erp5_pt_form_dialog_js.xml     |  4 +-
 .../testFormDialogWorkflowAlwaysEditable.xml  | 58 +++++++++++++++
 .../testFormDialogWorkflowAlwaysEditable.zpt  | 72 +++++++++++++++++++
 4 files changed, 139 insertions(+), 9 deletions(-)
 create mode 100644 bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormDialogWorkflowAlwaysEditable.xml
 create mode 100644 bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormDialogWorkflowAlwaysEditable.zpt

diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_dialog_js.js b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_dialog_js.js
index e6f1bd56d5..75940eed71 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_dialog_js.js
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_dialog_js.js
@@ -62,7 +62,8 @@
 
   rJS(window)
     .setState({
-      title: ""
+      title: "",
+      editable: true // dialogs are always in editable mode
     })
     /////////////////////////////////////////////////////////////////
     // acquisition
@@ -101,16 +102,15 @@
     })
 
     .declareMethod('render', function (options) {
-      var state_dict = {
+      // copy out wanted items from options and pass it to `changeState`
+      return this.changeState({
         jio_key: options.jio_key,
         view: options.view,
-        editable: options.editable,
+        // ignore options.editable because dialog is always editable
         erp5_document: options.erp5_document,
         form_definition: options.form_definition,
         erp5_form: options.erp5_form || {}
-      };
-
-      return this.changeState(state_dict);
+      });
     })
 
     .onStateChange(function () {
@@ -168,7 +168,7 @@
         .push(function (erp5_form) {
           var form_options = form_gadget.state.erp5_form;
 
-          // <span class="ui-icon ui-icon-custom ui-icon-random">&nbsp;</span>
+          // pass own form options to the embedded form
           form_options.erp5_document = form_gadget.state.erp5_document;
           form_options.form_definition = form_gadget.state.form_definition;
           form_options.view = form_gadget.state.view;
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_dialog_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_dialog_js.xml
index 45f850ed9d..c20e538a59 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_dialog_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_dialog_js.xml
@@ -230,7 +230,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>961.59533.60499.59221</string> </value>
+                <value> <string>961.62321.34764.37614</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -248,7 +248,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1504701037.67</float>
+                        <float>1504874104.04</float>
                         <string>UTC</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormDialogWorkflowAlwaysEditable.xml b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormDialogWorkflowAlwaysEditable.xml
new file mode 100644
index 0000000000..c777f3048b
--- /dev/null
+++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormDialogWorkflowAlwaysEditable.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <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_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>content_type</string> </key>
+            <value> <string>text/html</string> </value>
+        </item>
+        <item>
+            <key> <string>expand</string> </key>
+            <value> <int>0</int> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>testFormDialogWorkflowAlwaysEditable</string> </value>
+        </item>
+        <item>
+            <key> <string>output_encoding</string> </key>
+            <value> <string>utf-8</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <unicode></unicode> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormDialogWorkflowAlwaysEditable.zpt b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormDialogWorkflowAlwaysEditable.zpt
new file mode 100644
index 0000000000..9b36197881
--- /dev/null
+++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormDialogWorkflowAlwaysEditable.zpt
@@ -0,0 +1,72 @@
+<html xmlns:tal="http://xml.zope.org/namespaces/tal"
+      xmlns:metal="http://xml.zope.org/namespaces/metal">
+<head>
+<!-- Workflow action always shows editable form dialog.
+
+-  access a document in NONeditable mode
+-  any workflow action must be editable
+-->
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Test Form View Editable Save Action</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">Test Default Module View</td></tr>
+</thead><tbody>
+<tal:block metal:use-macro="here/PTZuite_CommonTemplate/macros/init" />
+<tr>
+  <td>store</td>
+  <td>${base_url}/web_site_module/renderjs_runner</td>
+  <td>renderjs_url</td>
+</tr>
+<tr>
+  <td>open</td>
+  <td>${renderjs_url}/#/foo_module/1</td>
+  <td></td>
+</tr>
+<tr>
+  <td>waitForElementPresent</td>
+  <td>//a[text()='Actions']</td>
+  <td></td>
+</tr>
+<tr>
+  <td>click</td>
+  <td>//a[text()='Actions']</td>
+  <td></td>
+</tr>
+<tr>
+  <td>waitForElementPresent</td>
+  <td>//a[@data-i18n='Dummy Workflow Action']</td>
+  <td></td>
+</tr>
+<tr>
+  <td>click</td>
+  <td>//a[@data-i18n='Dummy Workflow Action']</td>
+  <td></td>
+</tr>
+<!-- Wait for gadget to be loaded -->
+<tr>
+  <td>waitForElementPresent</td>
+  <td>//div[@data-gadget-url='${renderjs_url}/gadget_erp5_pt_form_dialog.html']//textarea</td>
+  <td></td>
+</tr>
+<!-- Textarea must be editable -->
+<tr>
+  <td>type</td>
+  <td>//div[@data-gadget-url='${renderjs_url}/gadget_erp5_pt_form_dialog.html']//textarea</td>
+  <td>QWERTY</td>
+</tr>
+<tr>
+  <td>click</td>
+  <td>//div[@data-gadget-url='${renderjs_url}/gadget_erp5_pt_form_dialog.html']//input[@type='submit']</td>
+  <td></td>
+</tr>
+<tr>
+  <td>waitForTextPresent</td>
+  <td>Status changed.</td>
+  <td></td>
+</tr>
+</tbody></table>
+</body>
+</html>
\ No newline at end of file
-- 
2.30.9