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

356 lines
12 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;
}
.app-error-panel {
position: absolute;
width: 100%;
height: 100%;
top: 0;
background-color: #f4f4f4;
z-index: 10;
}
.message-block {
display: inline-block;
vertical-align: middle;
width: 100%;
}
.message-inner {
width: 550px;
margin: auto;
padding: 30px;
background-color: #e3e3e3;
text-align: center;
}
.title {
font-size: 24px;
margin: 0 0 14px;
}
.text {
font-size: 16px;
}
2021-04-22 18:02:56 +00:00
</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-29 23:24:02 +00:00
var postMessageOrigin;
var lang = "en-US";
var startTime;
2021-05-06 11:37:46 +00:00
var documentChanged;
var sendNotificationTimer;
2021-05-12 16:04:14 +00:00
var sessionId;
var fileInfo;
2021-04-22 18:02:56 +00:00
var innerAlert = function (message) {
if (console && console.log)
console.log(message);
};
2021-04-29 23:24:02 +00:00
var commandMap = {
'Blur_Focus': function (data) {
innerAlert('Blur_Focus');
2021-05-06 11:37:46 +00:00
docEditor.blurFocus();
2021-04-29 23:24:02 +00:00
},
'Grab_Focus': function (data) {
innerAlert('Grab_Focus');
2021-05-06 11:37:46 +00:00
docEditor.grabFocus();
2021-04-29 23:24:02 +00:00
},
'Host_PostmessageReady': function (data) {
innerAlert('Host_PostmessageReady');
}
};
var _postMessage = function(msgId, msgData) {
if (window.parent && window.JSON) {
msgData = msgData || {};
msgData["ui-language"] = lang;
2021-05-12 16:04:14 +00:00
msgData["wdUserSession"] = sessionId;
2021-04-29 23:24:02 +00:00
var msg = {
"MessageId": msgId,
"SendTime": Date.now(),
"Values": msgData
};
window.parent.postMessage(window.JSON.stringify(msg), postMessageOrigin);
}
};
var _onMessage = function(msg) {
if (msg.origin !== postMessageOrigin) return;
var data = msg.data;
if (Object.prototype.toString.apply(data) !== '[object String]' || !window.JSON) {
return;
}
var cmd, handler;
try {
cmd = window.JSON.parse(data)
} catch(e) {
cmd = '';
}
if (cmd) {
2021-05-06 11:37:46 +00:00
handler = commandMap[cmd.MessageId];
2021-04-29 23:24:02 +00:00
if (handler) {
2021-05-06 11:37:46 +00:00
handler.call(this, cmd);
2021-04-29 23:24:02 +00:00
}
}
};
var fn = function(e) { _onMessage(e); };
if (window.attachEvent) {
window.attachEvent('onmessage', fn);
} else {
window.addEventListener('message', fn, false);
}
2021-04-22 18:02:56 +00:00
var onAppReady = function () {
2021-04-29 23:24:02 +00:00
_postMessage('App_LoadingStatus', {
"DocumentLoadedTime": Date.now() - startTime
});
innerAlert("App ready");
2021-04-22 18:02:56 +00:00
};
2021-05-06 11:37:46 +00:00
var sendEditNotification = function () {
documentChanged && _postMessage('Edit_Notification', {});
documentChanged = false;
};
2021-04-22 18:02:56 +00:00
var onDocumentStateChange = function (event) {
2021-05-06 11:37:46 +00:00
if (event.data) {
documentChanged = true;
if (sendNotificationTimer===undefined) {
sendNotificationTimer = setInterval(sendEditNotification, 30000);
sendEditNotification();
}
2021-04-29 23:24:02 +00:00
}
2021-04-22 18:02:56 +00:00
};
2021-04-29 23:24:02 +00:00
var onRequestRename = function (event) {
if (event.data) {
_postMessage('File_Rename', {
"NewName": event.data
});
}
2021-04-22 18:02:56 +00:00
};
2021-04-29 23:24:02 +00:00
var onRequestClose = function () {
if (fileInfo.ClosePostMessage)
_postMessage('UI_Close', {});
else if (fileInfo.CloseUrl)
window.parent.location.href = fileInfo.CloseUrl;
2021-04-22 18:02:56 +00:00
};
2021-04-29 23:24:02 +00:00
var onRequestEditRights = function () {
if (fileInfo.EditModePostMessage)
_postMessage('UI_Edit', {});
else if (fileInfo.HostEditUrl)
window.open(fileInfo.HostEditUrl, "_blank");
2021-04-22 18:02:56 +00:00
};
2021-05-13 11:45:53 +00:00
var onRequestSharingSettings = function (event) {
if (fileInfo.FileSharingPostMessage)
_postMessage('UI_Sharing', {});
else if (fileInfo.FileSharingUrl)
window.open(fileInfo.FileSharingUrl, "_blank");
2021-04-29 23:24:02 +00:00
};
2021-05-13 11:45:53 +00:00
var onRequestHistory = function (event) {
if (fileInfo.FileVersionPostMessage)
_postMessage('UI_FileVersions', {});
else if (fileInfo.FileVersionUrl)
window.open(fileInfo.FileVersionUrl, "_blank");
};
2021-04-29 23:24:02 +00:00
var onError = function (event) {
if (event)
innerAlert(event.data);
2021-04-22 18:02:56 +00:00
};
var connectEditor = function () {
fileInfo = <%- JSON.stringify(fileInfo) %>;
2021-04-22 18:02:56 +00:00
var key = "<%- key %>";
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
if (!fileInfo.BaseFileName) {
showError();
return;
}
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-28 16:58:11 +00:00
"fileType": fileInfo.FileExtension ? fileInfo.FileExtension.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,
2021-05-06 21:26:42 +00:00
"review": (fileInfo.SupportsReviewing===false) ? false : (fileInfo.UserCanReview===false ? false : fileInfo.UserCanReview),
2021-04-27 22:41:36 +00:00
"copy": fileInfo.CopyPasteRestrictions!=="CurrentDocumentOnly" && fileInfo.CopyPasteRestrictions!=="BlockAll",
"print": !fileInfo.DisablePrint && !fileInfo.HidePrintOption
2021-04-22 18:02:56 +00:00
}
},
"editorConfig": {
2021-04-23 14:44:57 +00:00
"mode": queryParams.mode,
2021-05-12 19:04:39 +00:00
"lang": queryParams.lang || queryParams.ui || "en-US",
"region": queryParams.rs,
2021-04-22 18:02:56 +00:00
"callbackUrl": JSON.stringify(userAuth),
"user": {
2021-04-28 16:58:11 +00:00
"id": fileInfo.UserId,
"name": fileInfo.IsAnonymousUser ? "" : fileInfo.UserFriendlyName
2021-04-22 18:02:56 +00:00
},
"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-05-12 19:04:39 +00:00
},
"chat": queryParams.dchat!=="1",
"uiTheme": queryParams.thm==="1" ? "theme-light" : (queryParams.thm==="2" ? "theme-dark" : undefined)
2021-04-29 23:24:02 +00:00
},
"coEditing": {
"mode": "fast",
"change": false
2021-05-12 16:04:14 +00:00
},
"wopi": {
"FileNameMaxLength": fileInfo.FileNameMaxLength && fileInfo.FileNameMaxLength>0 ? fileInfo.FileNameMaxLength : 250
2021-04-29 23:24:02 +00:00
}
2021-04-22 18:02:56 +00:00
},
2021-05-06 22:05:26 +00:00
"events": {
"onAppReady": onAppReady,
"onDocumentStateChange": fileInfo.EditNotificationPostMessage ? onDocumentStateChange : undefined,
'onRequestEditRights': fileInfo.EditModePostMessage || fileInfo.HostEditUrl ? onRequestEditRights : undefined,
2021-05-06 22:05:26 +00:00
"onError": onError,
"onRequestClose": fileInfo.ClosePostMessage || fileInfo.CloseUrl ? onRequestClose : undefined,
2021-05-06 22:05:26 +00:00
"onRequestRename": fileInfo.SupportsRename && fileInfo.UserCanRename ? onRequestRename : undefined,
2021-05-13 11:45:53 +00:00
"onRequestSharingSettings": fileInfo.FileSharingPostMessage || fileInfo.FileSharingUrl ? onRequestSharingSettings : undefined,
"onRequestHistory": fileInfo.FileVersionUrl || fileInfo.FileVersionPostMessage ? onRequestHistory : undefined
2021-05-06 22:05:26 +00:00
}
2021-04-22 18:02:56 +00:00
};
2021-04-29 23:24:02 +00:00
postMessageOrigin = fileInfo.PostMessageOrigin;
2021-05-06 11:37:46 +00:00
if (postMessageOrigin && (typeof postMessageOrigin === 'string') && postMessageOrigin.charAt(postMessageOrigin.length-1)=='/')
postMessageOrigin = postMessageOrigin.substring(0, postMessageOrigin.length - 1);
2021-04-29 23:24:02 +00:00
lang = config.editorConfig.lang;
2021-05-12 16:04:14 +00:00
sessionId = userAuth.userSessionId;
2021-04-27 22:41:36 +00:00
2021-04-29 23:24:02 +00:00
startTime = Date.now();
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";
}
};
var showError = function(msg, title) {
msg = msg || 'Sorry, editor could not be loaded. Please contact your administrator.';
var newDiv = document.createElement("div");
newDiv.className = "app-error-panel";
newDiv.innerHTML = '<div class="message-block">' +
'<div class="message-inner">' +
(title ? '<div class="title">' + title + '</div>' : '') +
'<div class="text">' + msg + '</div>' +
'</div>' +
'</div>';
document.body.appendChild(newDiv);
};
2021-04-22 18:02:56 +00:00
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>