From 1fc0d30f62b401128ff164e7701a1df91d0b6c44 Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Fri, 3 Oct 2014 16:24:45 +0200
Subject: [PATCH] Directly edit newly created document.

---
 .../web_page_module/rjs_gadget_erp5_js.xml    | 11 +++++++++-
 .../rjs_gadget_erp5_pt_form_dialog_js.xml     | 20 ++++++++++++++-----
 .../rjs_gadget_erp5_pt_form_list_js.xml       |  6 +++---
 ...s_gadget_erp5_pt_form_view_editable_js.xml |  2 +-
 .../rjs_gadget_erp5_pt_formpage_js.xml        |  7 ++++---
 5 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_js.xml
index 2a8e8c906c..b20fc81603 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_js.xml
@@ -257,7 +257,16 @@
 \n
     .allowPublicAcquisition("whoWantToDisplayThis", function (param_list) {\n
       // Hey, I want to display some URL\n
-      return this.aq_pleasePublishMyState({jio_key: param_list[0], view: this.props.default_view_reference});\n
+      var options = {\n
+        jio_key: param_list[0],\n
+        view: this.props.default_view_reference\n
+      };\n
+      if (param_list[1] !== undefined) {\n
+        if (param_list[1].editable !== undefined) {\n
+          options.editable = param_list[1].editable;\n
+        }\n
+      }\n
+      return this.aq_pleasePublishMyState(options);\n
     })\n
     .allowPublicAcquisition("whoWantToDisplayThisPage", function (param_list) {\n
       // Hey, I want to display some URL\n
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 b285bebcb1..372ca5a94b 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
@@ -137,6 +137,9 @@
     .declareAcquiredMethod("whoWantToDisplayThisPage", "whoWantToDisplayThisPage")\n
     .declareAcquiredMethod("whoWantToDisplayThis", "whoWantToDisplayThis")\n
     .declareAcquiredMethod("renderPageHeader", "renderPageHeader")\n
+    .declareAcquiredMethod("notifySubmitting", "notifySubmitting")\n
+    .declareAcquiredMethod("notifySubmitted", "notifySubmitted")\n
+\n
 \n
     /////////////////////////////////////////////////////////////////\n
     // declared methods\n
@@ -151,6 +154,7 @@
 \n
       form_gadget.props.id = erp5_document._id;\n
       form_gadget.props.view = options.view;\n
+      form_gadget.props.editable = options.editable;\n
       form_gadget.props.action = erp5_document._embedded._view._actions.put;\n
       form_gadget.props.form_id = erp5_document._embedded._view.form_id;\n
 \n
@@ -194,7 +198,10 @@
       var form_gadget = this;\n
 \n
       function formSubmit() {\n
-        return form_gadget.getDeclaredGadget("erp5_form")\n
+        return form_gadget.notifySubmitting()\n
+          .push(function () {\n
+            return form_gadget.getDeclaredGadget("erp5_form");\n
+          })\n
           .push(function (erp5_form) {\n
             return erp5_form.getContent();\n
           })\n
@@ -228,10 +235,13 @@
               // No redirection, stay on the same document\n
               return form_gadget.whoWantToDisplayThisPage({name: "view"});\n
             }\n
-            return form_gadget.whoWantToDisplayThis(new URI(location).segment(2));\n
+            return form_gadget.whoWantToDisplayThis(new URI(location).segment(2), {editable: form_gadget.props.editable});\n
           })\n
           .push(function (url) {\n
-            return form_gadget.pleaseRedirectMyHash(url);\n
+            return RSVP.all([\n
+              form_gadget.notifySubmitted(),\n
+              form_gadget.pleaseRedirectMyHash(url)\n
+            ]);\n
           });\n
       }\n
 \n
@@ -381,7 +391,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>937.64201.40983.3993</string> </value>
+                <value> <string>937.65475.63762.40123</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -399,7 +409,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1412251248.98</float>
+                        <float>1412328524.22</float>
                         <string>GMT</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_list_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_list_js.xml
index 25fa6521ca..3d5dbdbc4d 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_list_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_list_js.xml
@@ -133,7 +133,7 @@
         .push(function () {\n
           var new_content_action = options.erp5_document._links.action_object_new_content_action;\n
           if (new_content_action !== undefined) {\n
-            new_content_action = gadget.whoWantToDisplayThisPage({name: new_content_action.name});\n
+            new_content_action = gadget.whoWantToDisplayThisPage({name: new_content_action.name, editable: true});\n
           } else {\n
             new_content_action = "";\n
           }\n
@@ -300,7 +300,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>937.64086.34377.7560</string> </value>
+                <value> <string>937.64343.1806.54016</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -318,7 +318,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1412257173.84</float>
+                        <float>1412327028.09</float>
                         <string>GMT</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_view_editable_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_view_editable_js.xml
index 80b03d8e70..bf7d59ae20 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_view_editable_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_form_view_editable_js.xml
@@ -159,7 +159,7 @@
 \n
           new_content_action = options.erp5_document._links.action_object_new_content_action;\n
           if (new_content_action !== undefined) {\n
-            new_content_action = form_gadget.whoWantToDisplayThisPage({name: new_content_action.name});\n
+            new_content_action = form_gadget.whoWantToDisplayThisPage({name: new_content_action.name, editable: true});\n
           } else {\n
             new_content_action = "";\n
           }\n
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_formpage_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_formpage_js.xml
index 7023567b72..3dca015dfb 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_formpage_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_pt_formpage_js.xml
@@ -136,7 +136,7 @@
       return this.getDeclaredGadget(\'fg\')\n
         .push(function (g) {\n
           return g.triggerSubmit();\n
-        })\n
+        });\n
     })\n
     .declareMethod("render", function (options) {\n
       var gadget = this,\n
@@ -172,6 +172,7 @@
           sub_options.view = options.view;\n
           sub_options.action_view = options.action_view;\n
           sub_options.jio_key = options.jio_key;\n
+          sub_options.editable = options.editable;\n
 \n
           form_gadget = result;\n
           return form_gadget.render(sub_options);\n
@@ -325,7 +326,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>937.58335.7310.17476</string> </value>
+                <value> <string>937.65478.52910.50056</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -343,7 +344,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1412239088.85</float>
+                        <float>1412344031.82</float>
                         <string>GMT</string>
                       </tuple>
                     </state>
-- 
2.30.9