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, /*global window, rJS, RSVP, DocsAPI, console, document,
Common, require, jIO, URL, FileReader, atob, ArrayBuffer, Common, require, jIO, URL, FileReader, atob, ArrayBuffer,
Uint8Array, XMLHttpRequest, Blob, Rusha, define, Uint8Array, XMLHttpRequest, Blob, Rusha, define,
Uint8ClampedArray,
TextDecoder, DesktopOfflineAppDocumentEndSave*/ TextDecoder, DesktopOfflineAppDocumentEndSave*/
/*jslint nomen: true, maxlen:80, indent:2*/ /*jslint nomen: true, maxlen:80, indent:2*/
"use strict"; "use strict";
...@@ -72,9 +73,10 @@ DocsAPI.DocEditor.version = function () { ...@@ -72,9 +73,10 @@ DocsAPI.DocEditor.version = function () {
.declareAcquiredMethod('notifyChange', 'notifyChange') .declareAcquiredMethod('notifyChange', 'notifyChange')
.declareMethod("jio_getAttachment", function (docId, attId, opt) { .declareMethod("jio_getAttachment", function (docId, attId, opt) {
var g = this, var g = this,
queue; convert;
opt = opt || {};
if (attId === 'body.txt' || attId === 'Editor.bin') { if (attId === 'body.txt' || attId === 'Editor.bin') {
opt = 'asBinArray'; opt = { 'format': 'bin_array' };
if (!docId) { if (!docId) {
docId = '/'; docId = '/';
} }
...@@ -83,36 +85,24 @@ DocsAPI.DocEditor.version = function () { ...@@ -83,36 +85,24 @@ DocsAPI.DocEditor.version = function () {
docId = '/media/'; 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) { .push(function (blob) {
var data; if (convert === "bin_array") {
if (opt === "asText") { return new Uint8ClampedArray(blob);
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;
} }
return data; if (convert === "blob_url") {
return URL.createObjectURL(blob);
}
return blob;
}); });
return queue;
}) })
.declareMethod("jio_putAttachment", function (docId, atId, data) { .declareMethod("jio_putAttachment", function (docId, atId, data) {
var g = this, var g = this,
......
...@@ -509,7 +509,7 @@ ...@@ -509,7 +509,7 @@
queue, queue,
oThis = this; oThis = this;
if (0 === start.indexOf('jio:')) { 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) { .push(undefined, function (error) {
console.error(error); console.error(error);
return ""; 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