Files
document-server-integration/web/documentserver-example/nodejs/views/editor.ejs
2017-02-09 18:58:45 +03:00

174 lines
6.9 KiB
Plaintext

<!--*
*
* (c) Copyright Ascensio System Limited 2010-2017
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*-->
<!DOCTYPE html>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<title>ONLYOFFICE</title>
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="stylesheets/editor.css" />
</head>
<body>
<div class="form">
<div id="iframeEditor">
</div>
</div>
<script type="text/javascript" src="<%= apiUrl %>"></script>
<script type="text/javascript" language="javascript">
var docEditor;
var fileName = "<%= file.name %>";
var fileType = "<%= file.ext %>";
var innerAlert = function (message) {
if (console && console.log)
console.log(message);
};
var onReady = function () {
innerAlert("Document editor ready");
};
var onDocumentStateChange = function (event) {
var title = document.title.replace(/\*$/g, "");
document.title = title + (event.data ? "*" : "");
};
var onRequestEditRights = function () {
location.href = location.href.replace(RegExp("mode=view\&?", "i"), "");
};
var onRequestHistory = function (event) {
var historyObj = <%- JSON.stringify(history) %> || null;
docEditor.refreshHistory(
{
currentVersion: "<%= file.version %>",
history: historyObj
});
};
var onRequestHistoryData = function (data) {
var version = data.data;
var url_arr = "<%= setHistoryData.url %>".split(",");
var changesUrl_arr = "<%= setHistoryData.changesUrl %>".split(",");
docEditor.setHistoryData({
version: version,
url: url_arr[version - 1] != "" ? url_arr[version - 1] : null,
changesUrl: changesUrl_arr[version - 1] != "" ? changesUrl_arr[version - 1] : null
});
};
var onRequestHistoryClose = function (event){
document.location.reload();
};
var onError = function (event) {
if (event)
innerAlert(event.data);
};
var onOutdatedVersion = function (event) {
location.reload(true);
};
var connectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor",
{
width: "100%",
height: "100%",
type: "<%= editor.type %>",
documentType: "<%= editor.documentType %>",
document: {
title: fileName,
url: "<%= file.uri %>",
fileType: fileType,
key: "<%= editor.key %>",
info: {
author: "Me",
created: new Date().toDateString()
},
permissions: {
download: true,
edit: "<%= editor.isEdit %>" == "true",
review: true,
}
},
editorConfig: {
mode: "<%= editor.mode %>",
lang: "<%= editor.lang %>",
callbackUrl: "<%- editor.callbackUrl %>",
user: {
id: "<%= editor.userid %>",
name: "<%= editor.name %>",
},
embedded: {
saveUrl: "<%= file.uri %>",
embedUrl: "<%= file.uri %>",
shareUrl: "<%= file.uri %>",
toolbarDocked: "top"
},
customization: {
about: true,
chat: true,
comments: true,
feedback: true,
goback: {
url: "<%= editor.getServerUrl %>"
}
},
fileChoiceUrl: "<%= editor.fileChoiceUrl %>",
plugins: <%- JSON.stringify(editor.plugins) %>
},
events: {
"onReady": onReady,
"onDocumentStateChange": onDocumentStateChange,
'onRequestEditRights': onRequestEditRights,
"onError": onError,
"onRequestHistory": onRequestHistory,
"onRequestHistoryData": onRequestHistoryData,
"onRequestHistoryClose": onRequestHistoryClose,
"onOutdatedVersion": onOutdatedVersion,
}
});
};
if (window.addEventListener) {
window.addEventListener("load", connectEditor);
} else if (window.attachEvent) {
window.attachEvent("onload", connectEditor);
}
</script>
</body>
</html>