From 37afe87ecaf3c419e561f8632074363a481bdbaa Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Mon, 7 Sep 2015 14:17:51 +0000
Subject: [PATCH] [erp5_officejs] Add setSetting/getSetting methods.

This allow to configure local properties (like language) in the browser database through jIO.
---
 .../officejs_launcher_html.xml                |  8 +++-
 .../web_page_module/officejs_launcher_js.xml  | 47 +++++++++++++++++--
 2 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/bt5/erp5_officejs/PathTemplateItem/web_page_module/officejs_launcher_html.xml b/bt5/erp5_officejs/PathTemplateItem/web_page_module/officejs_launcher_html.xml
index e43ba03906..f907f38811 100644
--- a/bt5/erp5_officejs/PathTemplateItem/web_page_module/officejs_launcher_html.xml
+++ b/bt5/erp5_officejs/PathTemplateItem/web_page_module/officejs_launcher_html.xml
@@ -155,6 +155,10 @@
         <a href="#mypanel" class="ui-btn-left ui-btn ui-btn-inline ui-mini ui-corner-all"></a>\n
         <div><h1 class="ui-title"></h1></div>\n
       </div-->\n
+\n
+      <div data-gadget-url="gadget_jio.html"\n
+          data-gadget-scope="setting_gadget"\n
+          data-gadget-sandbox="public"></div>\n
 \n
       <div data-gadget-url="${router_gadget}"\n
           data-gadget-scope="router"\n
@@ -322,7 +326,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>945.31049.20388.20360</string> </value>
+                <value> <string>945.38184.6119.32017</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -340,7 +344,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1441200593.5</float>
+                        <float>1441628774.12</float>
                         <string>GMT</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_officejs/PathTemplateItem/web_page_module/officejs_launcher_js.xml b/bt5/erp5_officejs/PathTemplateItem/web_page_module/officejs_launcher_js.xml
index 8bc352e10f..ecf0472d01 100644
--- a/bt5/erp5_officejs/PathTemplateItem/web_page_module/officejs_launcher_js.xml
+++ b/bt5/erp5_officejs/PathTemplateItem/web_page_module/officejs_launcher_js.xml
@@ -314,7 +314,16 @@
         }\n
       }\n
     })\n
-\n
+    // Configure setting storage\n
+    .ready(function (g) {\n
+      return g.getDeclaredGadget("setting_gadget")\n
+        .push(function (jio_gadget) {\n
+          return jio_gadget.createJio({\n
+            type: "indexeddb",\n
+            database: "setting"\n
+          });\n
+        });\n
+    })\n
     // Configure jIO storage\n
     .ready(function (g) {\n
       return g.getDeclaredGadget("jio_gadget")\n
@@ -341,6 +350,38 @@
     //////////////////////////////////////////\n
     // Allow Acquisition\n
     //////////////////////////////////////////\n
+    .allowPublicAcquisition("getSetting", function (argument_list) {\n
+      return this.getDeclaredGadget("setting_gadget")\n
+        .push(function (jio_gadget) {\n
+          return jio_gadget.get("setting");\n
+        })\n
+        .push(function (doc) {\n
+          return doc[argument_list[0]] || argument_list[1];\n
+        }, function (error) {\n
+          if (error.status_code === 404) {\n
+            return argument_list[1];\n
+          }\n
+          throw error;\n
+        });\n
+    })\n
+    .allowPublicAcquisition("setSetting", function (argument_list) {\n
+      var jio_gadget;\n
+      return this.getDeclaredGadget("setting_gadget")\n
+        .push(function (result) {\n
+          jio_gadget = result;\n
+          return jio_gadget.get("setting");\n
+        })\n
+        .push(undefined, function (error) {\n
+          if (error.status_code === 404) {\n
+            return {};\n
+          }\n
+          throw error;\n
+        })\n
+        .push(function (doc) {\n
+          doc[argument_list[0]] = argument_list[1];\n
+          return jio_gadget.put(\'setting\', doc);\n
+        });\n
+    })\n
     .allowPublicAcquisition("translateHtml", function (argument_list) {\n
       return this.getDeclaredGadget("translation_gadget")\n
         .push(function (translation_gadget) {\n
@@ -672,7 +713,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>945.33659.5064.30310</string> </value>
+                <value> <string>945.38261.35515.4386</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -690,7 +731,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1441377487.05</float>
+                        <float>1441634809.55</float>
                         <string>GMT</string>
                       </tuple>
                     </state>
-- 
2.30.9