Commit 1c85dec3 authored by Boris Kocherov's avatar Boris Kocherov

Revert "erp5_officejs: change jio_getAttachment and jio_putAttachment for...

Revert "erp5_officejs: change jio_getAttachment and jio_putAttachment for compatability with ooffice"

This reverts commit 883ee9089b16cef26db973bcbd8f5a514661b4e5.
parent f65eb7db
/*global window, rJS, jIO, FormData, UriTemplate, Rusha */
/*global window, rJS, jIO, FormData, UriTemplate */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, jIO) {
"use strict";
var rusha = new Rusha();
// jIO call wrapper for redirection to authentication page if needed
function wrapJioCall(gadget, method_name, argument_list) {
var storage = gadget.state_parameter_dict.jio_storage;
......@@ -88,80 +86,11 @@
.declareMethod('remove', function () {
return wrapJioCall(this, 'remove', arguments);
})
.declareMethod('getAttachment', function (docId, atId, opt) {
return wrapJioCall(this, 'getAttachment', [docId, atId])
.push(function (blob) {
var data;
if (opt === "asBlobURL") {
data = URL.createObjectURL(blob);
} else if (opt === "asDataURL") {
data = new RSVP.Promise(function (resolve, reject) {
var reader = new FileReader();
reader.addEventListener('load', function () {
resolve(reader.result);
});
reader.readAsDataURL(blob);
});
} else {
data = blob;
}
return data;
});
.declareMethod('getAttachment', function () {
return wrapJioCall(this, 'gettAttachment', arguments);
})
.declareMethod('putAttachment', function (docId, atId, data) {
var start = data.slice(0, 5),
gadget = this,
queue = new RSVP.Queue();
if (start === "data:") {
queue.push(function () {
var byteString = atob(data.split(',')[1]);
// separate out the mime component
var mimeString = data.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return [ab, mimeString];
});
} else if (start === "blob:") {
queue.push(function () {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', data, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function (e) {
if (this.status == 200) {
resolve([this.response, this.getResponseHeader("Content-Type")]);
}
};
xhr.send();
});
});
}
return queue.push(function (result) {
var ab = result[0],
mimeString = result[1];
if (!atId) {
atId = mimeString + ',' + rusha.digestFromArrayBuffer(ab);
}
return wrapJioCall(gadget, 'allAttachments', [docId])
.push(function (list) {
var blob;
if (list.hasOwnProperty(atId)) {
return {};
} else {
blob = new Blob([ab], {type: mimeString});
return wrapJioCall(gadget, 'putAttachment', [docId, atId, blob]);
}
});
})
.push(function () {
return atId;
});
.declareMethod('putAttachment', function () {
return wrapJioCall(this, 'putAttachment', arguments);
})
.declareMethod('removeAttachment', function () {
return wrapJioCall(this, 'removeAttachment', arguments);
......
......@@ -216,7 +216,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>cedric.le.ninivin</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.52194.32966.50585</string> </value>
<value> <string>949.59977.1025.50722</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1477254062.06</float>
<float>1458319358.64</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