From 660050d4c499a5627443c612d75621a74e27de6e Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Thu, 6 Oct 2016 16:00:29 +0000
Subject: [PATCH] [erp5_web_renderjs_ui] Allow to submit the form action from
 textarea

---
 .../rjs_gadget_erp5_textareafield_js.js       | 32 ++++++++++++-------
 .../rjs_gadget_erp5_textareafield_js.xml      |  2 +-
 .../rjs_gadget_html5_textarea_js.js           |  1 +
 .../rjs_gadget_html5_textarea_js.xml          |  4 +--
 4 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_textareafield_js.js b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_textareafield_js.js
index 8995321bfe..f12ebd476c 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_textareafield_js.js
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_textareafield_js.js
@@ -19,22 +19,32 @@
       return this.changeState(state_dict);
     })
 
-    .declareMethod('updateDOM', function () {
+    .declareMethod('updateDOM', function (modification_dict) {
       var element = this.element,
         gadget = this,
-        url;
-      if (gadget.state.editable) {
-        url = 'gadget_html5_textarea.html';
+        url,
+        result;
+
+      if (modification_dict.hasOwnProperty('editable')) {
+        if (gadget.state.editable) {
+          url = 'gadget_html5_textarea.html';
+        } else {
+          url = 'gadget_html5_element.html';
+        }
+        result = this.declareGadget(url, {scope: 'sub'})
+          .push(function (input) {
+            // Clear first to DOM, append after to reduce flickering/manip
+            while (element.firstChild) {
+              element.removeChild(element.firstChild);
+            }
+            element.appendChild(input.element);
+            return input;
+          });
       } else {
-        url = 'gadget_html5_element.html';
+        result = this.getDeclaredGadget('sub');
       }
-      return this.declareGadget(url, {scope: 'sub'})
+      return result
         .push(function (input) {
-          // Clear first to DOM, append after to reduce flickering/manip
-          while (element.firstChild) {
-            element.removeChild(element.firstChild);
-          }
-          element.appendChild(input.element);
           return input.render(gadget.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 8ddd5f526e..5c336598f3 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
@@ -254,7 +254,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1475163059.77</float>
+                        <float>1475764759.74</float>
                         <string>UTC</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_textarea_js.js b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_textarea_js.js
index 6f7dd86435..676dce5df4 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_textarea_js.js
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_textarea_js.js
@@ -33,6 +33,7 @@
 
     .declareMethod('updateDOM', function () {
       var textarea = this.element.querySelector('textarea');
+      // textarea.setAttribute('value', this.state.value);
       textarea.value = this.state.value;
       textarea.setAttribute('name', this.state.name);
       textarea.setAttribute('title', this.state.title);
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_textarea_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_textarea_js.xml
index 831306668d..36381923e7 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_textarea_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_textarea_js.xml
@@ -230,7 +230,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>954.22955.35469.52377</string> </value>
+                <value> <string>954.27370.32393.51592</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -248,7 +248,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1475499846.91</float>
+                        <float>1475769541.61</float>
                         <string>UTC</string>
                       </tuple>
                     </state>
-- 
2.30.9