Commit 27931f00 authored by Vincent Bechu's avatar Vincent Bechu

erp5_officejs: make attachment synchro erp5 work with bad hack

parent 7cb1e09e
...@@ -6,10 +6,19 @@ ...@@ -6,10 +6,19 @@
function setjIOERP5Configuration(gadget) { function setjIOERP5Configuration(gadget) {
var erp5_url = gadget.props.element.querySelector("input[name='erp5_url']").value; var erp5_url = gadget.props.element.querySelector("input[name='erp5_url']").value;
return gadget.getSetting("portal_type") return new RSVP.Queue()
.push(function (portal_type) { .push(function () {
return RSVP.all([
gadget.getSetting("portal_type"),
gadget.getSetting("erp5_attachment_synchro", undefined)
]);
})
.push(function (result) {
var old_date = new Date(), var old_date = new Date(),
configuration = {}; configuration = {},
portal_type = result[0],
attachment_synchro = result[1] !== undefined,
extended_attachment_url = result[1];
// We are looking for documents modified in the past 3 month // We are looking for documents modified in the past 3 month
old_date = new Date(old_date.getFullYear(), old_date.getMonth(), old_date.getDate() - 15); old_date = new Date(old_date.getFullYear(), old_date.getMonth(), old_date.getDate() - 15);
configuration = { configuration = {
...@@ -25,6 +34,11 @@ ...@@ -25,6 +34,11 @@
}, },
use_remote_post: true, use_remote_post: true,
conflict_handling: 1, conflict_handling: 1,
check_local_attachment_modification: attachment_synchro,
check_local_attachment_creation: attachment_synchro,
check_remote_attachment_modification: attachment_synchro,
check_remote_attachment_creation: attachment_synchro,
check_remote_attachment_deletion: attachment_synchro,
check_local_modification: true, check_local_modification: true,
check_local_creation: true, check_local_creation: true,
check_local_deletion: false, check_local_deletion: false,
...@@ -42,11 +56,28 @@ ...@@ -42,11 +56,28 @@
} }
}, },
remote_sub_storage: { remote_sub_storage: {
type: "erp5", type: "mapping",
url: (new URI("hateoas")) attachment_list: ["data"],
.absoluteTo(erp5_url) attachment: {
.toString(), "data": {
default_view_reference: "jio_view" "get": {
"uri_template": (new URI("hateoas"))
.absoluteTo(erp5_url)
.toString() + extended_attachment_url
},
"put": {
"erp5_put_template": (new URI("hateoas")).absoluteTo(erp5_url)
.toString() + "/{+id}/Base_edit"
}
}
},
sub_storage: {
type: "erp5",
url: (new URI("hateoas"))
.absoluteTo(erp5_url)
.toString(),
default_view_reference: "jio_view"
}
} }
}; };
return gadget.setSetting('jio_storage_description', configuration); return gadget.setSetting('jio_storage_description', configuration);
......
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>956.4077.57694.30242</string> </value> <value> <string>957.13706.29150.15172</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1482145123.94</float> <float>1486654781.05</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*jslint indent:2, maxlen: 80, nomen: true */ /*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, /*global jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
Query*/ Query, FormData*/
(function (jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, (function (jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
Query) { Query, FormData) {
"use strict"; "use strict";
function getSubIdEqualSubProperty(storage, value, key) { function getSubIdEqualSubProperty(storage, value, key) {
...@@ -188,6 +188,7 @@ ...@@ -188,6 +188,7 @@
this._query = spec.query || {}; this._query = spec.query || {};
this._map_id = spec.id || ["equalSubId"]; this._map_id = spec.id || ["equalSubId"];
this._id_mapped = (spec.id !== undefined) ? spec.id[1] : false; this._id_mapped = (spec.id !== undefined) ? spec.id[1] : false;
this._attachment_list = spec.attachment_list || [];
if (this._query.query !== undefined) { if (this._query.query !== undefined) {
this._query.query = QueryFactory.create(this._query.query); this._query.query = QueryFactory.create(this._query.query);
...@@ -201,11 +202,12 @@ ...@@ -201,11 +202,12 @@
var mapping_dict = storage._attachment_mapping_dict; var mapping_dict = storage._attachment_mapping_dict;
if (mapping_dict !== undefined if (mapping_dict !== undefined
&& mapping_dict[attachment_id] !== undefined && mapping_dict[attachment_id] !== undefined
&& mapping_dict[attachment_id][method] !== undefined && mapping_dict[attachment_id][method] !== undefined) {
&& mapping_dict[attachment_id][method].uri_template !== undefined) { if (mapping_dict[attachment_id][method].uri_template !== undefined) {
return UriTemplate.parse( return UriTemplate.parse(
mapping_dict[attachment_id][method].uri_template mapping_dict[attachment_id][method].uri_template
).expand({id: sub_id}); ).expand({id: sub_id});
}
} }
return attachment_id; return attachment_id;
} }
...@@ -302,12 +304,20 @@ ...@@ -302,12 +304,20 @@
return getSubStorageId(storage, argument_list[0]) return getSubStorageId(storage, argument_list[0])
.push(function (sub_id) { .push(function (sub_id) {
argument_list[0] = sub_id; argument_list[0] = sub_id;
var old_id = argument_list[1];
argument_list[1] = getAttachmentId( argument_list[1] = getAttachmentId(
storage, storage,
sub_id, argument_list[0],
argument_list[1], argument_list[1],
method method
); );
if (storage._attachment_list.length > 0
&& storage._attachment_list.indexOf(old_id) < 0) {
if (method === "get") {
throw new jIO.util.jIOError("unhautorized attachment", 404);
}
return;
}
return storage._sub_storage[method + "Attachment"].apply( return storage._sub_storage[method + "Attachment"].apply(
storage._sub_storage, storage._sub_storage,
argument_list argument_list
...@@ -373,7 +383,32 @@ ...@@ -373,7 +383,32 @@
}); });
}; };
MappingStorage.prototype.putAttachment = function (id, attachment_id) { MappingStorage.prototype.putAttachment = function (id, attachment_id, blob) {
var storage = this,
mapping_dict = storage._attachment_mapping_dict;
// THIS IS REALLY BAD, FIND AN OTHER WAY IN FUTURE
if (mapping_dict !== undefined
&& mapping_dict[attachment_id] !== undefined
&& mapping_dict[attachment_id].put !== undefined
&& mapping_dict[attachment_id].put.erp5_put_template !== undefined) {
return getSubStorageId(storage, id)
.push(function (sub_id) {
var url = UriTemplate.parse(
mapping_dict[attachment_id].put.erp5_put_template
).expand({id: sub_id}),
data = new FormData();
data.append("field_my_file", blob);
data.append("form_id", "File_view");
return jIO.util.ajax({
"type": "POST",
"url": url,
"data": data,
"xhrFields": {
withCredentials: true
}
});
});
}
return handleAttachment(this, arguments, "put", id) return handleAttachment(this, arguments, "put", id)
.push(function () { .push(function () {
return attachment_id; return attachment_id;
...@@ -401,7 +436,8 @@ ...@@ -401,7 +436,8 @@
.push(function (result) { .push(function (result) {
var attachment_id, var attachment_id,
attachments = {}, attachments = {},
mapping_dict = {}; mapping_dict = {},
i;
for (attachment_id in storage._attachment_mapping_dict) { for (attachment_id in storage._attachment_mapping_dict) {
if (storage._attachment_mapping_dict.hasOwnProperty(attachment_id)) { if (storage._attachment_mapping_dict.hasOwnProperty(attachment_id)) {
mapping_dict[getAttachmentId(storage, sub_id, attachment_id, "get")] mapping_dict[getAttachmentId(storage, sub_id, attachment_id, "get")]
...@@ -410,13 +446,21 @@ ...@@ -410,13 +446,21 @@
} }
for (attachment_id in result) { for (attachment_id in result) {
if (result.hasOwnProperty(attachment_id)) { if (result.hasOwnProperty(attachment_id)) {
if (mapping_dict.hasOwnProperty(attachment_id)) { if (!(storage._attachment_list.length > 0
attachments[mapping_dict[attachment_id]] = {}; && storage._attachment_list.indexOf(attachment_id) < 0)) {
} else { if (mapping_dict.hasOwnProperty(attachment_id)) {
attachments[attachment_id] = {}; attachments[mapping_dict[attachment_id]] = {};
} else {
attachments[attachment_id] = {};
}
} }
} }
} }
for (i = 0; i < storage._attachment_list.length; i += 1) {
if (!attachments.hasOwnProperty(storage._attachment_list[i])) {
attachments[storage._attachment_list[i]] = {};
}
}
return attachments; return attachments;
}); });
}; };
...@@ -571,4 +615,5 @@ ...@@ -571,4 +615,5 @@
}; };
jIO.addStorage('mapping', MappingStorage); jIO.addStorage('mapping', MappingStorage);
}(jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, Query)); }(jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, Query,
\ No newline at end of file FormData));
\ No newline at end of file
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>957.11845.19520.59426</string> </value> <value> <string>957.13731.19555.59477</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1486546931.43</float> <float>1486656236.28</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment