From 921476c113c99c0788d336e3f120727a9466b998 Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Fri, 26 Oct 2018 13:53:14 +0000
Subject: [PATCH] [erp5_web_renderjs_ui] Load the notification gadget only when
 it is needed to display a message

---
 .../rjs_gadget_erp5_launcher_js.js            | 38 ++++++++++++++++---
 .../rjs_gadget_erp5_launcher_js.xml           |  4 +-
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_launcher_js.js b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_launcher_js.js
index 410f70b706..df5772b4bc 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_launcher_js.js
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_launcher_js.js
@@ -360,7 +360,11 @@
     ) {
       return RSVP.all([
         route(this, "header", 'notifySubmitting'),
-        route(this, "notification", 'notify', argument_list)
+        this.deferChangeState({
+          // Force calling notify
+          notification_timestamp: new Date().getTime(),
+          notification_options: argument_list[0]
+        })
       ]);
     })
     .allowPublicAcquisition('notifySubmitted', function notifySubmitted(
@@ -368,7 +372,11 @@
     ) {
       return RSVP.all([
         route(this, "header", 'notifySubmitted'),
-        route(this, "notification", 'notify', argument_list),
+        this.deferChangeState({
+          // Force calling notify
+          notification_timestamp: new Date().getTime(),
+          notification_options: argument_list[0]
+        }),
         route(this, "router", 'notify', argument_list)
       ]);
     })
@@ -377,7 +385,11 @@
     ) {
       return RSVP.all([
         route(this, "header", 'notifyChange'),
-        route(this, "notification", 'notify', argument_list),
+        this.deferChangeState({
+          // Force calling notify
+          notification_timestamp: new Date().getTime(),
+          notification_options: argument_list[0]
+        }),
         route(this, "router", 'notify', argument_list)
       ]);
     })
@@ -613,6 +625,21 @@
         );
       }
 
+      // Update the notification
+      if (modification_dict.hasOwnProperty('notification_options') ||
+          modification_dict.hasOwnProperty('notification_timestamp')) {
+        if (gadget.state.notification_options === undefined) {
+          promise_list.push(
+            route(gadget, "notification", 'close')
+          );
+        } else {
+          promise_list.push(
+            route(this, "notification", 'notify',
+                  [gadget.state.notification_options])
+          );
+        }
+      }
+
       return RSVP.all(promise_list);
     })
     // Render the page
@@ -631,9 +658,6 @@
             route(gadget, 'panel', 'close'),
             route(gadget, 'router', 'notify', [{modified : false}])
           ];
-          if (keep_message !== true) {
-            promise_list.push(route(gadget, 'notification', 'close'));
-          }
           return RSVP.all(promise_list);
         })
         .push(function () {
@@ -641,6 +665,8 @@
             url: route_result.url,
             options: route_result.options,
             editor_panel_url: undefined,
+            notification_options: (keep_message === true) ?
+                                  gadget.state.notification_options : undefined,
             // Force calling main gadget render
             render_timestamp: new Date().getTime()
           });
diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_launcher_js.xml b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_launcher_js.xml
index 242e01696c..e8e7210ad5 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_launcher_js.xml
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_launcher_js.xml
@@ -230,7 +230,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>971.13351.46212.20787</string> </value>
+                <value> <string>971.13370.40868.64819</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -248,7 +248,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1540560524.97</float>
+                        <float>1540561732.08</float>
                         <string>UTC</string>
                       </tuple>
                     </state>
-- 
2.30.9