web-apps/apps/api/wopi/editor-wopi.ejs

186 lines
5.6 KiB
Plaintext
Raw Normal View History

2021-04-22 18:02:56 +00:00
<!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" />
<!--
*
* (c) Copyright Ascensio System SIA 2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
-->
<title>ONLYOFFICE</title>
<style type="text/css">
html {
height: 100%;
width: 100%;
}
body {
background: #fff;
color: #333;
font-family: Arial, Tahoma,sans-serif;
font-size: 12px;
font-weight: normal;
height: 100%;
margin: 0;
overflow-y: hidden;
padding: 0;
text-decoration: none;
}
.form {
height: 100%;
}
div {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div class="form">
<div id="iframeEditor">
</div>
</div>
2021-04-23 15:15:26 +00:00
<script type="text/javascript" src="../../web-apps/apps/api/documents/api.js"></script>
2021-04-22 18:02:56 +00:00
<script type="text/javascript" language="javascript">
var docEditor;
2021-04-27 22:41:36 +00:00
var closeUrl;
var hostEditUrl;
2021-04-22 18:02:56 +00:00
var innerAlert = function (message) {
if (console && console.log)
console.log(message);
};
var onAppReady = function () {
innerAlert("Document editor ready");
};
var onDocumentStateChange = function (event) {
var title = document.title.replace(/\*$/g, "");
document.title = title + (event.data ? "*" : "");
};
var onRequestEditRights = function () {
2021-04-27 22:41:36 +00:00
hostEditUrl && (location.href = hostEditUrl);
2021-04-22 18:02:56 +00:00
};
var onError = function (event) {
if (event)
innerAlert(event.data);
};
var onOutdatedVersion = function (event) {
location.reload(true);
};
2021-04-27 22:41:36 +00:00
var onRequestClose = function (event) {
closeUrl && (location.href = closeUrl);
2021-04-22 18:02:56 +00:00
};
var connectEditor = function () {
var key = "<%- key %>";
var fileInfo = <%- JSON.stringify(fileInfo) %>;
var userAuth = <%- JSON.stringify(userAuth) %>;
var token = "<%- token %>";
2021-04-23 14:44:57 +00:00
var queryParams = <%- JSON.stringify(queryParams) %>;
2021-04-27 22:41:36 +00:00
2021-04-22 18:02:56 +00:00
var fileType = fileInfo.BaseFileName ? fileInfo.BaseFileName.substr(fileInfo.BaseFileName.lastIndexOf('.') + 1) : "";
var config = {
"width": "100%",
"height": "100%",
"type": "desktop",
2021-04-23 14:44:57 +00:00
"documentType": queryParams.documenttype,
2021-04-22 18:02:56 +00:00
"token": token,
"document": {
2021-04-27 22:41:36 +00:00
"title": fileInfo.BreadcrumbDocName || fileInfo.BaseFileName,
2021-04-22 18:02:56 +00:00
"url": userAuth.wopiSrc,
2021-04-27 22:41:36 +00:00
"fileType": fileInfo.FileExtension ? fileInfo.BaseFileName.substr(1) : fileType,
2021-04-22 18:02:56 +00:00
"key": key,
2021-04-27 22:41:36 +00:00
"info": {
"folder": fileInfo.BreadcrumbFolderName
},
2021-04-22 18:02:56 +00:00
"permissions": {
2021-04-27 22:41:36 +00:00
"edit": !fileInfo.ReadOnly && fileInfo.UserCanWrite,
"copy": fileInfo.CopyPasteRestrictions!=="CurrentDocumentOnly" && fileInfo.CopyPasteRestrictions!=="BlockAll",
"print": !fileInfo.DisablePrint
2021-04-22 18:02:56 +00:00
}
},
"editorConfig": {
2021-04-23 14:44:57 +00:00
"mode": queryParams.mode,
2021-04-27 22:41:36 +00:00
"lang": queryParams.lang || "en",
2021-04-22 18:02:56 +00:00
"callbackUrl": JSON.stringify(userAuth),
2021-04-27 22:41:36 +00:00
"sharingSettingsUrl": fileInfo.FileSharingUrl,
2021-04-22 18:02:56 +00:00
"user": {
2021-04-27 22:41:36 +00:00
"id": fileInfo.IsAnonymousUser ? "" : fileInfo.UserId,
2021-04-22 18:02:56 +00:00
"name": fileInfo.UserFriendlyName
},
"customization": {
"about": true,
"goback": {
2021-04-27 22:41:36 +00:00
"url": fileInfo.BreadcrumbFolderUrl
2021-04-22 18:02:56 +00:00
},
2021-04-27 22:41:36 +00:00
"customer": {
"name": fileInfo.BreadcrumbBrandName,
"www": fileInfo.BreadcrumbBrandUrl
}
}
2021-04-22 18:02:56 +00:00
},
events: {
"onAppReady": onAppReady,
"onDocumentStateChange": onDocumentStateChange,
'onRequestEditRights': onRequestEditRights,
"onError": onError,
"onOutdatedVersion": onOutdatedVersion,
2021-04-27 22:41:36 +00:00
"onRequestClose": onRequestClose
2021-04-22 18:02:56 +00:00
}
};
2021-04-27 22:41:36 +00:00
closeUrl = fileInfo.CloseUrl;
hostEditUrl = fileInfo.HostEditUrl;
2021-04-22 18:02:56 +00:00
docEditor = new DocsAPI.DocEditor("iframeEditor", config);
fixSize();
};
var fixSize = function () {
var wrapEl = document.getElementsByClassName("form");
if (wrapEl.length) {
wrapEl[0].style.height = screen.availHeight + "px";
window.scrollTo(0, -1);
wrapEl[0].style.height = window.innerHeight + "px";
}
};
if (window.addEventListener) {
window.addEventListener("load", connectEditor);
window.addEventListener("resize", fixSize);
} else if (window.attachEvent) {
window.attachEvent("onload", connectEditor);
window.attachEvent("onresize", fixSize);
}
</script>
</body>
</html>