Commit 80585c28 authored by Vincent Bechu's avatar Vincent Bechu Committed by Eteri

[erp5_officejs] Fix pdf view, add parse on dataURI

parent 1410f030
...@@ -76,7 +76,13 @@ ...@@ -76,7 +76,13 @@
return jIO.util.readBlobAsDataURL(blob); return jIO.util.readBlobAsDataURL(blob);
}) })
.push(function (result) { .push(function (result) {
data = result.target.result; if (result.target.result.split('data:')[1] === '') {
data = '';
} else {
data = result.target.result.split(
/data:application\/.*;base64,/
)[1];
}
return gadget.getDeclaredGadget('form_view'); return gadget.getDeclaredGadget('form_view');
}) })
.push(function (form_gadget) { .push(function (form_gadget) {
......
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.10686.10882.5973</string> </value> <value> <string>961.12114.30061.24797</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1501855020.28</float> <float>1501861765.33</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -5,13 +5,6 @@ ...@@ -5,13 +5,6 @@
"use strict"; "use strict";
rJS(window) rJS(window)
.ready(function (gadget) {
gadget.props = {};
return gadget.getElement()
.push(function (element) {
gadget.props.element = element;
});
})
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
[].forEach.call(window.document.head.querySelectorAll("base"), function (el) { [].forEach.call(window.document.head.querySelectorAll("base"), function (el) {
// XXX GadgetField adds <base> tag to fit to the parent page location, it's BAD to remove them. // XXX GadgetField adds <base> tag to fit to the parent page location, it's BAD to remove them.
...@@ -20,10 +13,17 @@ ...@@ -20,10 +13,17 @@
// we break all dynamic links. So, deleting <base> is required. // we break all dynamic links. So, deleting <base> is required.
window.document.head.removeChild(el); window.document.head.removeChild(el);
}); });
this.props.key = options.key; return this.changeState({
var raw = window.atob(options.value); value: options.value,
var rawLength = raw.length; key: options.key
var array = new Uint8Array(new ArrayBuffer(rawLength)); });
})
.onStateChange(function () {
var gadget = this,
raw = window.atob(gadget.state.value),
rawLength = raw.length,
array = new Uint8Array(new ArrayBuffer(rawLength));
for (var i = 0; i < rawLength; i++) { for (var i = 0; i < rawLength; i++) {
array[i] = raw.charCodeAt(i); array[i] = raw.charCodeAt(i);
...@@ -32,14 +32,14 @@ ...@@ -32,14 +32,14 @@
webViewerLoad(array); webViewerLoad(array);
// hide few buttons for now // hide few buttons for now
this.props.element.querySelector('#viewBookmark').hidden = true; gadget.element.querySelector('#viewBookmark').hidden = true;
this.props.element.querySelector('#documentProperties').hidden = true; gadget.element.querySelector('#documentProperties').hidden = true;
this.props.element.querySelector('#documentProperties').hidden = true; gadget.element.querySelector('#documentProperties').hidden = true;
return; return;
}) })
.declareMethod("getContent", function () { .declareMethod("getContent", function () {
var form_data = {}; var form_data = {};
var self = this; var gadget = this;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (PDFViewerApplication.pdfDocument) { if (PDFViewerApplication.pdfDocument) {
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
}); });
}) })
.push(function (evt) { .push(function (evt) {
form_data[self.props.key] = evt.target.result; form_data[gadget.state.key] = evt.target.result;
return form_data; return form_data;
}); });
}); });
......
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.2133.47184.12219</string> </value> <value> <string>961.12202.20585.38980</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1501257080.78</float> <float>1501861642.39</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