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 @@
function setjIOERP5Configuration(gadget) {
var erp5_url = gadget.props.element.querySelector("input[name='erp5_url']").value;
return gadget.getSetting("portal_type")
.push(function (portal_type) {
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting("portal_type"),
gadget.getSetting("erp5_attachment_synchro", undefined)
]);
})
.push(function (result) {
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
old_date = new Date(old_date.getFullYear(), old_date.getMonth(), old_date.getDate() - 15);
configuration = {
......@@ -25,6 +34,11 @@
},
use_remote_post: true,
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_creation: true,
check_local_deletion: false,
......@@ -42,12 +56,29 @@
}
},
remote_sub_storage: {
type: "mapping",
attachment_list: ["data"],
attachment: {
"data": {
"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);
})
......
......@@ -273,7 +273,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.4077.57694.30242</string> </value>
<value> <string>957.13706.29150.15172</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -291,7 +291,7 @@
</tuple>
<state>
<tuple>
<float>1482145123.94</float>
<float>1486654781.05</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
Query*/
Query, FormData*/
(function (jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
Query) {
Query, FormData) {
"use strict";
function getSubIdEqualSubProperty(storage, value, key) {
......@@ -188,6 +188,7 @@
this._query = spec.query || {};
this._map_id = spec.id || ["equalSubId"];
this._id_mapped = (spec.id !== undefined) ? spec.id[1] : false;
this._attachment_list = spec.attachment_list || [];
if (this._query.query !== undefined) {
this._query.query = QueryFactory.create(this._query.query);
......@@ -201,12 +202,13 @@
var mapping_dict = storage._attachment_mapping_dict;
if (mapping_dict !== undefined
&& mapping_dict[attachment_id] !== undefined
&& mapping_dict[attachment_id][method] !== undefined
&& mapping_dict[attachment_id][method].uri_template !== undefined) {
&& mapping_dict[attachment_id][method] !== undefined) {
if (mapping_dict[attachment_id][method].uri_template !== undefined) {
return UriTemplate.parse(
mapping_dict[attachment_id][method].uri_template
).expand({id: sub_id});
}
}
return attachment_id;
}
......@@ -302,12 +304,20 @@
return getSubStorageId(storage, argument_list[0])
.push(function (sub_id) {
argument_list[0] = sub_id;
var old_id = argument_list[1];
argument_list[1] = getAttachmentId(
storage,
sub_id,
argument_list[0],
argument_list[1],
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(
storage._sub_storage,
argument_list
......@@ -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)
.push(function () {
return attachment_id;
......@@ -401,7 +436,8 @@
.push(function (result) {
var attachment_id,
attachments = {},
mapping_dict = {};
mapping_dict = {},
i;
for (attachment_id in storage._attachment_mapping_dict) {
if (storage._attachment_mapping_dict.hasOwnProperty(attachment_id)) {
mapping_dict[getAttachmentId(storage, sub_id, attachment_id, "get")]
......@@ -410,6 +446,8 @@
}
for (attachment_id in result) {
if (result.hasOwnProperty(attachment_id)) {
if (!(storage._attachment_list.length > 0
&& storage._attachment_list.indexOf(attachment_id) < 0)) {
if (mapping_dict.hasOwnProperty(attachment_id)) {
attachments[mapping_dict[attachment_id]] = {};
} else {
......@@ -417,6 +455,12 @@
}
}
}
}
for (i = 0; i < storage._attachment_list.length; i += 1) {
if (!attachments.hasOwnProperty(storage._attachment_list[i])) {
attachments[storage._attachment_list[i]] = {};
}
}
return attachments;
});
};
......@@ -571,4 +615,5 @@
};
jIO.addStorage('mapping', MappingStorage);
}(jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, Query));
\ No newline at end of file
}(jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, Query,
FormData));
\ No newline at end of file
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>957.11845.19520.59426</string> </value>
<value> <string>957.13731.19555.59477</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1486546931.43</float>
<float>1486656236.28</float>
<string>UTC</string>
</tuple>
</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