From 125a048197a326cdc5e6d9a90f126337321c1e8b Mon Sep 17 00:00:00 2001
From: Xiaowu Zhang <xiaowu.zhang@tiolive.com>
Date: Tue, 23 Feb 2016 18:41:53 +0000
Subject: [PATCH] erp5_web_renderjs_ui: display all texts in view mode

---
 .../web_page_module/rjs_gadget_erp5_css.xml   | 11 +++-
 .../rjs_gadget_erp5_stringfield_html.xml      |  9 ++-
 .../rjs_gadget_erp5_stringfield_js.xml        | 64 ++++++++++++-------
 .../rjs_gadget_erp5_textareafield_js.xml      |  8 +--
 .../testSortWithPreviousNext.xml              | 12 ++--
 .../testFormViewField.xml                     |  9 ++-
 .../renderjs_ui_zuite/testCloneDocument.xml   | 10 +--
 .../testRenderjsBasicNavigation.xml           |  2 +-
 8 files changed, 76 insertions(+), 49 deletions(-)

diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_css.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_css.xml
index 7dd938d7aa..ba89ddf327 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_css.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_css.xml
@@ -1125,6 +1125,13 @@ html .ui-listbox-error {\n
   text-align: center;\n
 }\n
 \n
+\n
+\n
+html .ui-content-non-editable {\n
+  word-wrap: break-word;\n
+  white-space: pre-line;\n
+}\n
+\n
 /* cell background */\n
 html table thead tr,\n
 html table tfoot tr,\n
@@ -5219,7 +5226,7 @@ html .ui-panel .ui-content .ui-btn[class*="ui-icon-"]:after {\n
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>949.1052.3508.62634</string> </value>
+                <value> <string>949.22640.50771.7816</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -5237,7 +5244,7 @@ html .ui-panel .ui-content .ui-btn[class*="ui-icon-"]:after {\n
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1454957135.51</float>
+                        <float>1456317267.11</float>
                         <string>UTC</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_stringfield_html.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_stringfield_html.xml
index 034a1b953f..4bc3e83140 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_stringfield_html.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_stringfield_html.xml
@@ -122,7 +122,6 @@
 \n
   </head>\n
   <body>\n
-    <input type=\'text\' />\n
   </body>\n
 </html>
 
@@ -247,7 +246,7 @@
             </item>
             <item>
                 <key> <string>actor</string> </key>
-                <value> <string>romain</string> </value>
+                <value> <string>zope</string> </value>
             </item>
             <item>
                 <key> <string>comment</string> </key>
@@ -261,7 +260,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>937.51526.35217.14489</string> </value>
+                <value> <string>949.22501.55314.65245</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -279,8 +278,8 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1412257603.97</float>
-                        <string>GMT</string>
+                        <float>1456252782.83</float>
+                        <string>UTC</string>
                       </tuple>
                     </state>
                   </object>
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_stringfield_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_stringfield_js.xml
index 67e4456c2a..d74434129d 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_stringfield_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_stringfield_js.xml
@@ -99,15 +99,16 @@
         </item>
         <item>
             <key> <string>text_content</string> </key>
-            <value> <string>/*global window, rJS, RSVP, loopEventListener */\n
+            <value> <string>/*global window, rJS, RSVP, loopEventListener, document */\n
 /*jslint indent: 2, maxerr: 3 */\n
-(function (window, rJS, RSVP, loopEventListener) {\n
+(function (window, rJS, RSVP, loopEventListener, document) {\n
   "use strict";\n
 \n
   rJS(window)\n
     .ready(function (gadget) {\n
       return gadget.getElement()\n
         .push(function (element) {\n
+          gadget.props = {};\n
           gadget.element = element;\n
         });\n
     })\n
@@ -116,37 +117,47 @@
     .declareAcquiredMethod("notifyInvalid", "notifyInvalid")\n
     .declareAcquiredMethod("notifyChange", "notifyChange")\n
     .declareMethod(\'getTextContent\', function () {\n
-      return this.element.querySelector(\'input\').getAttribute(\'value\');\n
+      return this.props.value;\n
     })\n
     .declareMethod(\'render\', function (options) {\n
-      var input = this.element.querySelector(\'input\'),\n
+      var element,\n
+        text,\n
         field_json = options.field_json || {};\n
-      input.setAttribute(\n
-        \'value\',\n
-        field_json.value || field_json.default || ""\n
-      );\n
-      input.setAttribute(\'name\', field_json.key);\n
-      input.setAttribute(\'title\', field_json.title);\n
-      if (field_json.required === 1) {\n
-        input.setAttribute(\'required\', \'required\');\n
-      }\n
-      if (field_json.editable !== 1) {\n
-        input.setAttribute(\'readonly\', \'readonly\');\n
-        input.setAttribute(\'data-wrapper-class\', \'ui-state-readonly\');\n
-        // input.setAttribute(\'disabled\', \'disabled\');\n
-\n
+      this.props.value = field_json.value || field_json.default || "";\n
+      this.props.editable = field_json.editable;\n
+      if (field_json.editable) {\n
+        element = document.createElement(\'input\');\n
+        element.setAttribute("type", "text");\n
+        element.setAttribute(\'value\', this.props.value);\n
+        element.setAttribute(\'name\', field_json.key);\n
+        element.setAttribute(\'title\', field_json.title);\n
+        if (field_json.required === 1) {\n
+          element.setAttribute(\'required\', \'required\');\n
+        }\n
+      } else {\n
+        element = document.createElement("p");\n
+        element.setAttribute("class", "ui-content-non-editable");\n
+        text = document.createTextNode(this.props.value);\n
+        element.appendChild(text);\n
       }\n
+      this.element.appendChild(element);\n
     })\n
 \n
     .declareMethod(\'getContent\', function () {\n
-      var input = this.element.querySelector(\'input\'),\n
+      var input,\n
         result = {};\n
-      result[input.getAttribute(\'name\')] = input.value;\n
+      if (this.props.editable) {\n
+        input = this.element.querySelector(\'input\');\n
+        result[input.getAttribute(\'name\')] = input.value;\n
+      }\n
       return result;\n
     })\n
 \n
     .declareMethod(\'checkValidity\', function () {\n
       var result;\n
+      if (!this.props.editable) {\n
+        return true;\n
+      }\n
       result = this.element.querySelector(\'input\').checkValidity();\n
       if (result) {\n
         return this.notifyValid()\n
@@ -162,6 +173,9 @@
       // Check field validity when the value changes\n
       ////////////////////////////////////\n
       var field_gadget = this;\n
+      if (!field_gadget.props.editable) {\n
+        return;\n
+      }\n
 \n
       function notifyChange() {\n
         return RSVP.all([\n
@@ -184,7 +198,9 @@
       // Inform when the field input is invalid\n
       ////////////////////////////////////\n
       var field_gadget = this;\n
-\n
+      if (!field_gadget.props.editable) {\n
+        return;\n
+      }\n
       function notifyInvalid(evt) {\n
         return field_gadget.notifyInvalid(evt.target.validationMessage);\n
       }\n
@@ -198,7 +214,7 @@
       );\n
     });\n
 \n
-}(window, rJS, RSVP, loopEventListener));</string> </value>
+}(window, rJS, RSVP, loopEventListener, document));</string> </value>
         </item>
         <item>
             <key> <string>title</string> </key>
@@ -333,7 +349,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>949.15479.27859.47018</string> </value>
+                <value> <string>949.22535.16679.23876</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -351,7 +367,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1455899182.71</float>
+                        <float>1456317346.39</float>
                         <string>UTC</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_textareafield_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_textareafield_js.xml
index 0dd7c56ab1..d526594965 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_textareafield_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_textareafield_js.xml
@@ -140,6 +140,7 @@
         this.property_dict.textarea_deferred.resolve(new_element);\n
       } else {\n
         new_element = document.createElement(\'pre\');\n
+        new_element.setAttribute("class",  "ui-content-non-editable");\n
         new_element.textContent = value;\n
       }\n
       this.property_dict.element.appendChild(new_element);\n
@@ -157,9 +158,6 @@
         value = field.textContent;\n
       }\n
       result[this.property_dict.name] = value;\n
-      console.log(result);\n
-      console.log(field);\n
-      console.log(this.property_dict.element);\n
       return result;\n
     })\n
 \n
@@ -316,7 +314,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>948.41930.30032.34201</string> </value>
+                <value> <string>949.24043.58938.21367</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -334,7 +332,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1453477730.87</float>
+                        <float>1456336348.49</float>
                         <string>UTC</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_listbox_zuite/testSortWithPreviousNext.xml b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_listbox_zuite/testSortWithPreviousNext.xml
index 64b0fd3490..b9805c1b97 100644
--- a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_listbox_zuite/testSortWithPreviousNext.xml
+++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_listbox_zuite/testSortWithPreviousNext.xml
@@ -190,8 +190,8 @@
 </tr>\n
 \n
 <tr>\n
-  <td>verifyValue</td>\n
-  <td>//input[@title="Title"]</td>\n
+  <td>verifyText</td>\n
+  <td>//div[@data-gadget-scope="field_my_title"]</td>\n
   <td>Title 3</td>\n
 </tr>\n
 \n
@@ -217,8 +217,8 @@
 </tr>\n
 \n
 <tr>\n
-  <td>verifyValue</td>\n
-  <td>//input[@title="Title"]</td>\n
+  <td>verifyText</td>\n
+  <td>//div[@data-gadget-scope="field_my_title"]</td>\n
   <td>Title 4</td>\n
 </tr>\n
 \n
@@ -244,8 +244,8 @@
 </tr>\n
 \n
 <tr>\n
-  <td>verifyValue</td>\n
-  <td>//input[@title="Title"]</td>\n
+  <td>verifyText</td>\n
+  <td>//div[@data-gadget-scope="field_my_title"]</td>\n
   <td>Title 3</td>\n
 </tr>\n
 \n
diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormViewField.xml b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormViewField.xml
index 4429024db1..c3a616700a 100644
--- a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormViewField.xml
+++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_page_templates_zuite/testFormViewField.xml
@@ -92,10 +92,17 @@
 </tr>\n
 <tr>\n
   <td>assertElementPresent</td>\n
-  <td>//input[@value=\'1\' and @name=\'field_my_id\' and @readonly=\'readonly\']</td>\n
+  <td>//div[@data-gadget-scope=\'field_my_id\']</td>\n
   <td></td>\n
 </tr>\n
 \n
+<tr>\n
+  <td>verifyText</td>\n
+  <td>//div[@data-gadget-scope=\'field_my_id\']</td>\n
+  <td>1</td>\n
+</tr>\n
+\n
+\n
 <!-- Listbox are always displayed without label -->\n
 <tr>\n
   <td>assertElementNotPresent</td>\n
diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_zuite/testCloneDocument.xml b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_zuite/testCloneDocument.xml
index cdc23cd5e7..2e22f425db 100644
--- a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_zuite/testCloneDocument.xml
+++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_zuite/testCloneDocument.xml
@@ -232,14 +232,14 @@
 \n
 <tr>\n
   <td>waitForElementPresent</td>\n
-  <td>//input[@title="Short Title"]</td>\n
+  <td>//div[@data-gadget-scope="field_my_short_title"]</td>\n
   <td></td>\n
 </tr>\n
 \n
 \n
 <tr>\n
-  <td>verifyValue</td>\n
-  <td>//input[@title="Short Title"]</td>\n
+  <td>verifyText</td>\n
+  <td>//div[@data-gadget-scope="field_my_short_title"]</td>\n
   <td>test_clone</td>\n
 </tr>\n
 \n
@@ -262,8 +262,8 @@
 </tr>\n
 \n
 <tr>\n
-  <td>storeValue</td>\n
-  <td>//input[@name=\'field_my_id\']</td>\n
+  <td>storeText</td>\n
+  <td>//div[@data-gadget-scope=\'field_my_id\']</td>\n
   <td>original_id</td>\n
 </tr>\n
 \n
diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_zuite/testRenderjsBasicNavigation.xml b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_zuite/testRenderjsBasicNavigation.xml
index 1601833248..949019f499 100644
--- a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_zuite/testRenderjsBasicNavigation.xml
+++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_zuite/testRenderjsBasicNavigation.xml
@@ -188,7 +188,7 @@
 </tr>\n
 <tr>\n
   <td>waitForElementPresent</td>\n
-  <td>//input[@title=\'ID\']</td>\n
+  <td>//div[@data-gadget-scope=\'field_my_id\']</td>\n
   <td></td>\n
 </tr>\n
 <tr>\n
-- 
2.30.9