Public
Snippet $185 authored by Boris Kocherov

jio_replicate_storage_cederic.patch

jio_replicate_storage_cederic.patch
diff --git a/src/jio.storage/erp5storage.js b/src/jio.storage/erp5storage.js
index e821357..57eac76 100644
--- a/src/jio.storage/erp5storage.js
+++ b/src/jio.storage/erp5storage.js
@@ -399,6 +399,34 @@
 
   ERP5Storage.prototype.putAttachment = function (id, name, blob) {
     // Assert we use a callable on a document from the ERP5 site
+    if (name === "data") {
+      return getDocumentAndHateoas(this, id,
+        {"_view": "jio_data"})
+        .push(function (response) {
+          var result = JSON.parse(response.target.responseText);
+          // Remove all ERP5 hateoas links / convert them into jIO ID
+
+          // XXX Change default action to an jio urn with attachment name inside
+          // if Base_edit, do put URN
+          // if others, do post URN (ie, unique new attachment name)
+          // XXX Except this attachment name should be generated when
+          return extractPropertyFromFormJSON(result);
+        })
+        .push(function (result) {
+          var form_data = result.form_data,
+            data = new FormData();
+          data.append("field_my_file", blob, form_data.filename["default"]);
+          data.append("form_id", form_data.form_id["default"]);
+          return jIO.util.ajax({
+            "type": "POST",
+            "url": result.action_href,
+            "data": data,
+            "xhrFields": {
+              withCredentials: true
+            }
+          });
+        });
+    }
     if (name.indexOf(this._url) !== 0) {
       throw new jIO.util.jIOError("Can not store outside ERP5: " +
                                   name, 400);
diff --git a/src/jio.storage/replicatestorage.js b/src/jio.storage/replicatestorage.js
index 39ee429..26af586 100644
--- a/src/jio.storage/replicatestorage.js
+++ b/src/jio.storage/replicatestorage.js
@@ -63,6 +63,7 @@
     });
 
     this._use_remote_post = spec.use_remote_post || false;
+    this._use_bulk_get = spec.use_bulk !== undefined ? spec.use_bulk : true;
 
     this._conflict_handling = spec.conflict_handling || 0;
     // 0: no resolution (ie, throw an Error)
@@ -1047,7 +1048,8 @@
         // Keep it like this until the bulk API is stabilized
         var use_bulk_get = false;
         try {
-          use_bulk_get = context._remote_sub_storage.hasCapacity("bulk");
+          use_bulk_get = context._remote_sub_storage.hasCapacity("bulk")
+            && context._use_bulk_get;
         } catch (error) {
           if (!((error instanceof jIO.util.jIOError) &&
                (error.status_code === 501))) {