Commit 2bffb96b authored by Boris Kocherov's avatar Boris Kocherov Committed by Romain Courteaud

[erp5_only_office] use jio.getAttachment optional parameter format

parent 65a8b9d0
/*global window, rJS, RSVP, DocsAPI, console, document,
Common, require, jIO, URL, FileReader, atob, ArrayBuffer,
Uint8Array, XMLHttpRequest, Blob, Rusha, define,
Uint8ClampedArray,
TextDecoder, DesktopOfflineAppDocumentEndSave*/
/*jslint nomen: true, maxlen:80, indent:2*/
"use strict";
......@@ -72,9 +73,10 @@ DocsAPI.DocEditor.version = function () {
.declareAcquiredMethod('notifyChange', 'notifyChange')
.declareMethod("jio_getAttachment", function (docId, attId, opt) {
var g = this,
queue;
convert;
opt = opt || {};
if (attId === 'body.txt' || attId === 'Editor.bin') {
opt = 'asBinArray';
opt = { 'format': 'bin_array' };
if (!docId) {
docId = '/';
}
......@@ -83,36 +85,24 @@ DocsAPI.DocEditor.version = function () {
docId = '/media/';
}
}
queue = g.props.value_zip_storage.getAttachment(docId, attId)
if (opt.format === "blob_url") {
convert = opt.format;
delete opt.format;
}
if (opt.format === "bin_array") {
convert = opt.format;
opt.format = 'array_buffer';
}
return g.props.value_zip_storage.getAttachment(docId, attId, opt)
.push(function (blob) {
var data;
if (opt === "asText") {
data = jIO.util.readBlobAsText(blob)
.then(function (evt) {
return evt.target.result;
});
} else if (opt === "asBinArray") {
data = jIO.util.readBlobAsArrayBuffer(blob)
.then(function (evt) {
return new Uint8ClampedArray(evt.target.result);
});
} else 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.addEventListener('error', reject);
reader.readAsDataURL(blob);
});
} else {
data = blob;
if (convert === "bin_array") {
return new Uint8ClampedArray(blob);
}
return data;
if (convert === "blob_url") {
return URL.createObjectURL(blob);
}
return blob;
});
return queue;
})
.declareMethod("jio_putAttachment", function (docId, atId, data) {
var g = this,
......
......@@ -509,7 +509,7 @@
queue,
oThis = this;
if (0 === start.indexOf('jio:')) {
queue = Common.Gateway.jio_getAttachment(this.Api.documentId, image_id.slice(4), 'asBlobURL')
queue = Common.Gateway.jio_getAttachment(this.Api.documentId, image_id.slice(4), {format:'blob_url'})
.push(undefined, function (error) {
console.error(error);
return "";
......
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