Commit 49a01c56 authored by Boris Kocherov's avatar Boris Kocherov

erp5_officejs_ooffice: catch and display of document value errors

parent f9435ae1
...@@ -20,13 +20,22 @@ if (Common === undefined) { ...@@ -20,13 +20,22 @@ if (Common === undefined) {
}); });
} }
function display_error(gadget, error) {
var display_error_element;
display_error_element = gadget.props.element;
display_error_element.innerHTML =
'<br/><p style="color: red"></p><br/><br/>';
display_error_element.querySelector('p').textContent = error;
throw error;
}
function dataURLtoBlob(url) { function dataURLtoBlob(url) {
var byteString = atob(url.split(',')[1]), var byteString = atob(url.split(',')[1]),
mimeString = url.split(',')[0].split(':')[1].split(';')[0], mimeString = url.split(',')[0].split(':')[1].split(';')[0],
ab = new ArrayBuffer(byteString.length), ab = new ArrayBuffer(byteString.length),
ia = new Uint8Array(ab), ia = new Uint8Array(ab),
i; i;
for (i = 0; i < byteString.length; i++) { for (i = 0; i < byteString.length; i += 1) {
ia[i] = byteString.charCodeAt(i); ia[i] = byteString.charCodeAt(i);
} }
return new Blob([ab], {type: mimeString}); return new Blob([ab], {type: mimeString});
...@@ -228,19 +237,29 @@ if (Common === undefined) { ...@@ -228,19 +237,29 @@ if (Common === undefined) {
g.props.key = options.key || "text_content"; g.props.key = options.key || "text_content";
g.props.value = options.value; g.props.value = options.value;
if (g.props.value) { if (g.props.value) {
magic = g.props.value.slice(0, 5); if (g.props.value.slice === undefined) {
if (magic === "[obje") { display_error(g, "not suported type of document value: " +
g.props.value = ""; typeof g.props.value);
} }
magic = g.props.value.slice(0, 5);
if (magic === "data:") { if (magic === "data:") {
g.props.value = atob(g.props.value.split(',')[1]); g.props.value = atob(g.props.value.split(',')[1]);
} }
magic = g.props.value.slice(0, 4); magic = g.props.value.slice(0, 4);
if (magic === "PK\x03\x04" || magic === "PK\x05\x06") { switch (magic) {
case 'XLSY':
case 'PPTY':
case 'DOCY':
break;
case "PK\x03\x04":
case "PK\x05\x06":
g.props.value_zip_storage = jIO.createJIO({ g.props.value_zip_storage = jIO.createJIO({
type: "zipfile", type: "zipfile",
file: g.props.value file: g.props.value
}); });
break;
default:
display_error(g, 'not supported format: "' + g.props.value + '"');
} }
} }
if (!g.props.value_zip_storage) { if (!g.props.value_zip_storage) {
...@@ -512,7 +531,7 @@ if (Common === undefined) { ...@@ -512,7 +531,7 @@ if (Common === undefined) {
return {}; return {};
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
console.log('gadget_ooffice.js redner error:' + error); display_error(g, error);
}); });
}) })
......
...@@ -182,7 +182,7 @@ ...@@ -182,7 +182,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1477517617.81</float> <float>1479313191.95</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -227,7 +227,7 @@ ...@@ -227,7 +227,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.11818.53126.43110</string> </value> <value> <string>955.51056.50.46796</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -245,7 +245,7 @@ ...@@ -245,7 +245,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1478799571.16</float> <float>1481036322.7</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