Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ONLYOFFICE/onlyoffice-nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'js/main.js')
-rw-r--r--js/main.js133
1 files changed, 131 insertions, 2 deletions
diff --git a/js/main.js b/js/main.js
index 5bd4d3e..5b388f5 100644
--- a/js/main.js
+++ b/js/main.js
@@ -29,7 +29,9 @@
(function (OCA) {
OCA.Onlyoffice = _.extend({
- AppName: "onlyoffice"
+ AppName: "onlyoffice",
+ context: null,
+ folderUrl: null
}, OCA.Onlyoffice);
OCA.Onlyoffice.setting = {};
@@ -71,6 +73,9 @@
fileList.add(response, { animate: true });
OCA.Onlyoffice.OpenEditor(response.id, dir, response.name, winEditor);
+ OCA.Onlyoffice.context = { fileList: fileList };
+ OCA.Onlyoffice.context.fileName = response.name;
+
OC.Notification.show(t(OCA.Onlyoffice.AppName, "File created"), {
timeout: 3
});
@@ -98,14 +103,77 @@
winEditor.location.href = url;
} else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.Desktop) {
winEditor = window.open(url, "_blank");
- } else {
+ } else if ($("#isPublic").val() === "1" && !$("#filestable").length) {
location.href = url;
+ } else {
+ var $iframe = $("<iframe id=\"onlyofficeFrame\" nonce=\"" + btoa(OC.requestToken) + "\" scrolling=\"no\" allowfullscreen src=\"" + url + "&inframe=true\" />");
+ $("#app-content").append($iframe);
+
+ $("body").addClass("onlyoffice-inline");
+ OC.Apps.hideAppSidebar();
+
+ $("html, body").scrollTop(0);
+
+ OCA.Onlyoffice.folderUrl = location.href;
+ window.history.pushState(null, null, url);
+ }
+ };
+
+ OCA.Onlyoffice.ShowHeaderButton = function () {
+ var wrapper = $("<div id='onlyofficeHeader' />")
+
+ var btnClose = $("<a class='icon icon-close-white'></a>");
+ btnClose.on("click", function() {
+ OCA.Onlyoffice.CloseEditor();
+ });
+ wrapper.prepend(btnClose);
+
+ if (!$("#isPublic").val()) {
+ var btnShare = $("<a class='icon icon-shared icon-white'></a>");
+ btnShare.on("click", function () {
+ OCA.Onlyoffice.OpenShareDialog();
+ })
+ wrapper.prepend(btnShare);
+ }
+
+ if (!$("#header .header-right").length) {
+ $("#header").append("<div class='header-right'></div>");
+ }
+ wrapper.prependTo(".header-right");
+ };
+
+ OCA.Onlyoffice.CloseEditor = function () {
+ $("body").removeClass("onlyoffice-inline");
+
+ $("#onlyofficeFrame").remove();
+ $("#onlyofficeHeader").remove();
+
+ OCA.Onlyoffice.context = null;
+
+ var url = OCA.Onlyoffice.folderUrl;
+ if (!!url) {
+ window.history.pushState(null, null, url);
+ OCA.Onlyoffice.folderUrl = null;
+ }
+ };
+
+ OCA.Onlyoffice.OpenShareDialog = function () {
+ if (OCA.Onlyoffice.context) {
+ if (!$("#app-sidebar").is(":visible")) {
+ OCA.Onlyoffice.context.fileList.showDetailsView(OCA.Onlyoffice.context.fileName, "shareTabView");
+ OC.Apps.showAppSidebar();
+ } else {
+ OC.Apps.hideAppSidebar();
+ }
}
};
OCA.Onlyoffice.FileClick = function (fileName, context) {
var fileInfoModel = context.fileInfoModel || context.fileList.getModelForFile(fileName);
OCA.Onlyoffice.OpenEditor(fileInfoModel.id, context.dir, fileName);
+
+ OCA.Onlyoffice.context = context;
+ OCA.Onlyoffice.context.fileName = fileName;
};
OCA.Onlyoffice.FileConvertClick = function (fileName, context) {
@@ -159,6 +227,37 @@
}
};
+ OCA.Onlyoffice.onRequestSaveAs = function (saveData) {
+ OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Save as"),
+ function (fileDir) {
+ saveData.dir = fileDir;
+ $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSaveAs(saveData);
+ },
+ false,
+ "httpd/unix-directory");
+ };
+
+ OCA.Onlyoffice.onRequestInsertImage = function (imageMimes) {
+ OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Insert image"),
+ $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorInsertImage,
+ false,
+ imageMimes);
+ };
+
+ OCA.Onlyoffice.onRequestMailMergeRecipients = function (recipientMimes) {
+ OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select recipients"),
+ $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSetRecipient,
+ false,
+ recipientMimes);
+ };
+
+ OCA.Onlyoffice.onRequestCompareFile = function (revisedMimes) {
+ OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select file to compare"),
+ $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSetRevised,
+ false,
+ revisedMimes);
+ };
+
OCA.Onlyoffice.FileList = {
attach: function (fileList) {
if (fileList.id == "trashbin") {
@@ -282,6 +381,36 @@
}
};
+ window.addEventListener("message", function(event) {
+ if ($("#onlyofficeFrame")[0].contentWindow !== event.source
+ || !event.data["method"]) {
+ return;
+ }
+ switch (event.data.method) {
+ case "editorRequestClose":
+ OCA.Onlyoffice.CloseEditor();
+ break;
+ case "editorRequestSharingSettings":
+ OCA.Onlyoffice.OpenShareDialog();
+ break;
+ case "editorRequestSaveAs":
+ OCA.Onlyoffice.onRequestSaveAs(event.data.param);
+ break;
+ case "editorRequestInsertImage":
+ OCA.Onlyoffice.onRequestInsertImage(event.data.param);
+ break;
+ case "editorRequestMailMergeRecipients":
+ OCA.Onlyoffice.onRequestMailMergeRecipients(event.data.param);
+ break;
+ case "editorRequestCompareFile":
+ OCA.Onlyoffice.onRequestCompareFile(event.data.param);
+ break;
+ case "editorShowHeaderButton":
+ OCA.Onlyoffice.ShowHeaderButton();
+ break;
+ }
+ }, false);
+
$(document).ready(initPage)
})(OCA);