mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
269 lines
11 KiB
HTML
269 lines
11 KiB
HTML
<!--*
|
|
*
|
|
* (c) Copyright Ascensio System SIA 2021
|
|
*
|
|
* The MIT License (MIT)
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
*-->
|
|
|
|
{% load static %}
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<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="{% static 'images/'|add:fileType|add:'.ico' %}"
|
|
type="image/x-icon" />
|
|
<link rel="stylesheet" type="text/css" href="{% static "css/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 config;
|
|
|
|
var innerAlert = function (message, inEditor) {
|
|
if (console && console.log)
|
|
console.log(message);
|
|
if (inEditor && docEditor)
|
|
docEditor.showMessage(message);
|
|
};
|
|
|
|
// the application is loaded into the browser
|
|
var onAppReady = function () {
|
|
innerAlert("Document editor ready");
|
|
};
|
|
|
|
// the document is modified
|
|
var onDocumentStateChange = function (event) {
|
|
var title = document.title.replace(/\*$/g, "");
|
|
document.title = title + (event.data ? "*" : "");
|
|
};
|
|
|
|
// the user is trying to switch the document from the viewing into the editing mode
|
|
var onRequestEditRights = function () {
|
|
location.href = location.href.replace(RegExp("mode=view\&?", "i"), "");
|
|
};
|
|
|
|
// an error or some other specific event occurs
|
|
var onError = function (event) {
|
|
if (event)
|
|
innerAlert(event.data);
|
|
};
|
|
|
|
// the document is opened for editing with the old document.key value
|
|
var onOutdatedVersion = function (event) {
|
|
location.reload(true);
|
|
};
|
|
|
|
// replace the link to the document which contains a bookmark
|
|
var replaceActionLink = function(href, linkParam) {
|
|
var link;
|
|
var actionIndex = href.indexOf("&actionLink=");
|
|
if (actionIndex != -1) {
|
|
var endIndex = href.indexOf("&", actionIndex + "&actionLink=".length);
|
|
if (endIndex != -1) {
|
|
link = href.substring(0, actionIndex) + href.substring(endIndex) + "&actionLink=" + encodeURIComponent(linkParam);
|
|
} else {
|
|
link = href.substring(0, actionIndex) + "&actionLink=" + encodeURIComponent(linkParam);
|
|
}
|
|
} else {
|
|
link = href + "&actionLink=" + encodeURIComponent(linkParam);
|
|
}
|
|
return link;
|
|
}
|
|
|
|
// the user is trying to get link for opening the document which contains a bookmark, scrolling to the bookmark position
|
|
var onMakeActionLink = function (event) {
|
|
var actionData = event.data;
|
|
var linkParam = JSON.stringify(actionData);
|
|
docEditor.setActionLink(replaceActionLink(location.href, linkParam)); // set the link to the document which contains a bookmark
|
|
};
|
|
|
|
// the meta information of the document is changed via the meta command
|
|
var onMetaChange = function (event) {
|
|
if (event.data.favorite) {
|
|
var favorite = !!event.data.favorite;
|
|
var title = document.title.replace(/^\☆/g, "");
|
|
document.title = (favorite ? "☆" : "") + title;
|
|
docEditor.setFavorite(favorite); // change the Favorite icon state
|
|
}
|
|
|
|
innerAlert("onMetaChange: " + JSON.stringify(event.data));
|
|
};
|
|
|
|
// the user is trying to insert an image by clicking the Image from Storage button
|
|
var onRequestInsertImage = function(event) {
|
|
docEditor.insertImage({ // insert an image into the file
|
|
"c": event.data.c,
|
|
{{ dataInsertImage | safe }}
|
|
})
|
|
};
|
|
|
|
// the user is trying to select document for comparing by clicking the Document from Storage button
|
|
var onRequestCompareFile = function() {
|
|
docEditor.setRevisedFile({{ dataCompareFile | safe }}); // select a document for comparing
|
|
};
|
|
|
|
// the user is trying to select recipients data by clicking the Mail merge button
|
|
var onRequestMailMergeRecipients = function (event) {
|
|
docEditor.setMailMergeRecipients( // insert recipient data for mail merge into the file
|
|
{{ dataMailMergeRecipients | safe }}
|
|
);
|
|
};
|
|
|
|
var onRequestSaveAs = function (event) { // the user is trying to save file by clicking Save Copy as... button
|
|
var title = event.data.title;
|
|
var url = event.data.url;
|
|
var data = {
|
|
title: title,
|
|
url: url
|
|
};
|
|
let xhr = new XMLHttpRequest();
|
|
xhr.open("POST", "saveas");
|
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
xhr.send(JSON.stringify(data));
|
|
xhr.onload = function () {
|
|
innerAlert(xhr.responseText);
|
|
innerAlert(JSON.parse(xhr.responseText).file, true);
|
|
}
|
|
};
|
|
|
|
var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button
|
|
innerAlert("onRequestRename: " + JSON.stringify(event.data));
|
|
|
|
var newfilename = event.data;
|
|
var data = {
|
|
newfilename: newfilename,
|
|
dockey: config.document.key,
|
|
};
|
|
let xhr = new XMLHttpRequest();
|
|
xhr.open("POST", "rename");
|
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
xhr.send(JSON.stringify(data));
|
|
xhr.onload = function () {
|
|
innerAlert(xhr.responseText);
|
|
}
|
|
};
|
|
|
|
var connectEditor = function () {
|
|
|
|
config = {{ cfg | safe }}
|
|
config.width = "100%";
|
|
config.height = "100%";
|
|
config.events = {
|
|
'onAppReady': onAppReady,
|
|
'onDocumentStateChange': onDocumentStateChange,
|
|
'onRequestEditRights': onRequestEditRights,
|
|
'onError': onError,
|
|
'onOutdatedVersion': onOutdatedVersion,
|
|
'onMakeActionLink': onMakeActionLink,
|
|
'onMetaChange': onMetaChange,
|
|
'onRequestInsertImage': onRequestInsertImage,
|
|
'onRequestCompareFile': onRequestCompareFile,
|
|
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
|
|
"onRequestRename": onRequestRename,
|
|
};
|
|
|
|
{% if history and historyData %}
|
|
|
|
// the user is trying to show the document version history
|
|
config.events['onRequestHistory'] = function () {
|
|
docEditor.refreshHistory({{ history | safe }}); // show the document version history
|
|
};
|
|
// the user is trying to click the specific document version in the document version history
|
|
config.events['onRequestHistoryData'] = function (event) {
|
|
var ver = event.data;
|
|
var histData = {{ historyData | safe }};
|
|
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
|
};
|
|
// the user is trying to go back to the document from viewing the document version history
|
|
config.events['onRequestHistoryClose'] = function () {
|
|
document.location.reload();
|
|
};
|
|
|
|
{% endif %}
|
|
|
|
{% if usersForMentions %}
|
|
|
|
// add mentions for not anonymous users
|
|
config.events['onRequestUsers'] = function () {
|
|
docEditor.setUsers({ // set a list of users to mention in the comments
|
|
"users": {{ usersForMentions | safe }}
|
|
});
|
|
};
|
|
// the user is mentioned in a comment
|
|
config.events['onRequestSendNotify'] = function (event) {
|
|
event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink));
|
|
var data = JSON.stringify(event.data);
|
|
innerAlert("onRequestSendNotify: " + data);
|
|
};
|
|
|
|
{% endif %}
|
|
|
|
if (config.editorConfig.createUrl) {
|
|
config.events.onRequestSaveAs = onRequestSaveAs;
|
|
};
|
|
|
|
if ((config.document.fileType === "docxf" || config.document.fileType === "oform")
|
|
&& DocsAPI.DocEditor.version().split(".")[0] < 7) {
|
|
innerAlert("Please update ONLYOFFICE Docs to version 7.0 to work on fillable forms online.");
|
|
return;
|
|
}
|
|
|
|
docEditor = new DocsAPI.DocEditor("iframeEditor", config);
|
|
|
|
fixSize();
|
|
};
|
|
|
|
// get the editor sizes
|
|
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>
|