Commit 94cbd2b2 authored by Boris Kocherov's avatar Boris Kocherov

erp5_officejs_ooffice: fix OnlyOffice work in standalone gadget mode

add depended libraries
fix urls
add landing page and scripts
parent 144196c6
<!doctype html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>OfficeJS OnlyOffice Loader Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_onlyoffice_landing.js" type="text/javascript"></script>
</head>
<body>
<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration"></script>
<script data-renderjs-configuration="child-gadget" type="text/x-renderjs-configuration">ooffice/gadget_ooffice.html</script>
</body>
</html>
\ No newline at end of file
/*global window, rJS, jIO, URI, location, console, document, RSVP, loopEventListener, navigator, XMLHttpRequest, ProgressEvent*/
/*jslint nomen: true, indent: 2*/
(function (window, rJS, jIO) {
"use strict";
function this_func_link(name) {
return function (opt) {
return this[name].apply(this, opt);
};
}
var gadget_klass = rJS(window),
SCOPE = "main",
SETTING_STORAGE = jIO.createJIO({
type: "indexeddb",
database: "setting"
});
gadget_klass
.ready(function (gadget) {
gadget.props = {};
return gadget.getElement()
.push(function (element) {
var element_list =
element.querySelectorAll("[data-renderjs-configuration]"),
len = element_list.length,
key,
value,
i;
gadget.props.element = element;
gadget.props.configuration = {};
for (i = 0; i < len; i += 1) {
key = element_list[i].getAttribute('data-renderjs-configuration');
value = element_list[i].textContent;
gadget.props.configuration[key] = value;
}
})
.push(function () {
// Resources are now ready
// Modify base to provides same base as gadget
var base = document.createElement('base'),
child_gadget_url = gadget.props.configuration["child-gadget"];
base.href = new URI(child_gadget_url + '/../').normalize()
.toString();
document.head.appendChild(base);
return gadget.declareGadget(
child_gadget_url,
{
scope: SCOPE
}
);
})
.push(function (child_gadget) {
return child_gadget.getElement();
})
.push(function (child_element) {
gadget.props.element.appendChild(child_element);
});
})
.declareMethod('getSetting', function (key, default_value) {
var from_html = this.props.configuration[key];
if (from_html !== undefined) {
return from_html;
}
return SETTING_STORAGE.get("setting")
.push(function (doc) {
return doc[key] || default_value;
}, function (error) {
if (error.status_code === 404) {
return default_value;
}
throw error;
});
})
.allowPublicAcquisition('getSetting', this_func_link('getSetting'))
.declareMethod('setSetting', function (key, value) {
return SETTING_STORAGE.get("setting")
.push(undefined, function (error) {
if (error.status_code === 404) {
return {};
}
throw error;
})
.push(function (doc) {
doc[key] = value;
return SETTING_STORAGE.put('setting', doc);
});
})
.allowPublicAcquisition('setSetting', this_func_link('setSetting'))
.declareAcquiredMethod("triggerSubmit", "triggerSubmit")
.allowPublicAcquisition('triggerSubmit', this_func_link('triggerMaximize'))
.declareAcquiredMethod("triggerMaximize", "triggerMaximize")
.allowPublicAcquisition('triggerMaximize', this_func_link('triggerMaximize'))
.declareAcquiredMethod("setFillStyle", "setFillStyle")
.allowPublicAcquisition('setFillStyle', this_func_link('setFillStyle'))
.declareMethod('render', function (options) {
var gadget = this;
return RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget(SCOPE);
})
.push(function (child_gadget) {
return child_gadget.render(options);
});
})
.declareMethod('getContent', function () {
var gadget = this;
return RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget(SCOPE);
})
.push(function (child_gadget) {
return child_gadget.getContent();
});
});
}(window, rJS, jIO));
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>OfficeJS Presentation Loader Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_onlyoffice_landing.js" type="text/javascript"></script>
</head>
<body>
<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration">Presentation</script>
<script data-renderjs-configuration="child-gadget" type="text/x-renderjs-configuration">ooffice/gadget_ooffice.html</script>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>OfficeJS Spreadsheet Loader Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_onlyoffice_landing.js" type="text/javascript"></script>
</head>
<body>
<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration">Spreadsheet</script>
<script data-renderjs-configuration="child-gadget" type="text/x-renderjs-configuration">ooffice/gadget_ooffice.html</script>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>OfficeJS Text Loader Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_onlyoffice_landing.js" type="text/javascript"></script>
</head>
<body>
<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration">Text</script>
<script data-renderjs-configuration="child-gadget" type="text/x-renderjs-configuration">ooffice/gadget_ooffice.html</script>
</body>
</html>
\ No newline at end of file
......@@ -51,10 +51,10 @@
</style>
<script src="../../rsvp.js" type="text/javascript"></script>
<script src="../../renderjs.js" type="text/javascript"></script>
<script src="../../jiodev.js" type="text/javascript"></script>
<script src="../../zipfilestorage-with-jszip.js" type="text/javascript"></script>
<script src="../rsvp.js" type="text/javascript"></script>
<script src="../renderjs.js" type="text/javascript"></script>
<script src="../jiodev.js" type="text/javascript"></script>
<script src="../zipfilestorage-with-jszip.js" type="text/javascript"></script>
<script src="./vendor/requirejs/require.js" type="text/javascript"></script>
<!--script src="./sdkjs/common/applyDocumentChanges.js" type="text/javascript"></script-->
<script src="./gadget_ooffice.js" type="text/javascript"></script>
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.30412.57307.9625</string> </value>
<value> <string>957.24802.24995.24046</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -258,7 +258,7 @@
</tuple>
<state>
<tuple>
<float>1483724971.81</float>
<float>1487676107.2</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -237,55 +237,86 @@ if (Common === undefined) {
queue = new RSVP.Queue();
return queue
.push(function () {
var magic;
return g.getSetting('portal_type');
})
.push(undefined, function (error) {
return "";
})
.push(function (portal_type) {
var value;
g.props.jio_key = options.jio_key;
g.props.key = options.key || "text_content";
g.props.value = options.value;
if (g.props.value === "data:") {
g.props.value = undefined;
g.props.documentType = portal_type.toLowerCase();
value = options.value;
if (value === "data:" || value === undefined) {
// fix empty value
value = "";
}
if (g.props.value) {
if (g.props.value.slice === undefined) {
throw "not suported type of document value: " +
typeof g.props.value;
if (value) {
if (value.slice === undefined) {
throw "not suported type of variable containing the document: " +
typeof value;
}
magic = g.props.value.slice(0, 5);
if (magic === "data:") {
g.props.value = atob(g.props.value.split(',')[1]);
if (value.slice(0, 5) === "data:") {
value = atob(value.split(',')[1]);
}
magic = g.props.value.slice(0, 4);
switch (magic) {
case 'XLSY':
case 'PPTY':
case 'DOCY':
break;
}
if (value) {
switch (value.slice(0, 4)) {
case "PK\x03\x04":
case "PK\x05\x06":
g.props.value_zip_storage = jIO.createJIO({
type: "zipfile",
file: g.props.value
file: value
});
g.props.value_zip_storage.getAttachment('/', 'body.txt')
.then(undefined, function (error) {
return g.props.value_zip_storage.getAttachment('/', 'body.txt')
.push(undefined, function (error) {
if (error.status_code === 404) {
throw 'not supported format: "' + g.props.value + '"';
throw 'not supported format of document: "' + value.slice(0, 100) + '"';
}
throw error;
})
.push(jIO.util.readBlobAsText)
.push(function (evt) {
return evt.target.result;
});
}
}
return value;
})
.push(function (value) {
var magic, documentType;
g.props.value = value;
if (!g.props.documentType && value === "") {
throw "can not create empty document because portal_type is unknown";
}
if (value) {
magic = g.props.value.slice(0, 4);
switch (magic) {
case 'XLSY':
documentType = "spreadsheet";
break;
case 'PPTY':
documentType = "presentation";
break;
case 'DOCY':
documentType = "text";
break;
default:
throw 'not supported format: "' + g.props.value + '"';
throw "can not detect document type by magic: " + magic;
}
if (g.props.documentType) {
if (documentType !== g.props.documentType) {
throw "editor not fit the document type";
}
} else {
//set editor type by docuementType
g.props.documentType = documentType;
}
}
if (!g.props.value_zip_storage) {
g.props.value_zip_storage = jIO.createJIO({type: "zipfile"});
}
})
.push(function () {
return g.getSetting('portal_type');
})
.push(function (portal_type) {
g.props.documentType = portal_type.toLowerCase();
return g.setFillStyle();
})
.push(function (size) {
......
......@@ -231,7 +231,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.7363.64405.13704</string> </value>
<value> <string>957.32306.28027.27204</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -249,7 +249,7 @@
</tuple>
<state>
<tuple>
<float>1482402560.96</float>
<float>1487770743.1</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