diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/desktop.js | 6 | ||||
-rw-r--r-- | js/editor.js | 135 | ||||
-rw-r--r-- | js/listener.js | 18 | ||||
-rw-r--r-- | js/main.js | 94 | ||||
-rw-r--r-- | js/settings.js | 16 |
5 files changed, 235 insertions, 34 deletions
diff --git a/js/desktop.js b/js/desktop.js index 2c2f0da..f7ebc8c 100644 --- a/js/desktop.js +++ b/js/desktop.js @@ -25,6 +25,12 @@ } OCA.Onlyoffice.Desktop = true; + + if (location.href.indexOf(_oc_appswebroots.dashboard) !== -1) { + location.href = location.href.split(_oc_appswebroots.dashboard)[0] + _oc_appswebroots.files; + return; + } + $("html").addClass("AscDesktopEditor"); var domain = new RegExp("^http(s)?:\/\/[^\/]+").exec(location)[0]; diff --git a/js/editor.js b/js/editor.js index 4729fa0..062af8f 100644 --- a/js/editor.js +++ b/js/editor.js @@ -40,6 +40,7 @@ OCA.Onlyoffice.template = $("#iframeEditor").data("template"); OCA.Onlyoffice.inframe = !!$("#iframeEditor").data("inframe"); OCA.Onlyoffice.filePath = $("#iframeEditor").data("path"); + OCA.Onlyoffice.anchor = $("#iframeEditor").attr("data-anchor"); var guestName = localStorage.getItem("nick"); if (!OCA.Onlyoffice.fileId && !OCA.Onlyoffice.shareToken && !directToken) { displayError(t(OCA.Onlyoffice.AppName, "FileId is empty")); @@ -77,6 +78,9 @@ if (guestName) { params.push("guestName=" + encodeURIComponent(guestName)); } + if (OCA.Onlyoffice.anchor) { + params.push("anchor=" + encodeURIComponent(OCA.Onlyoffice.anchor)); + } if (OCA.Onlyoffice.inframe || directToken) { params.push("inframe=true"); @@ -128,18 +132,22 @@ config.events = { "onDocumentStateChange": setPageTitle, - "onRequestHistory": OCA.Onlyoffice.onRequestHistory, - "onRequestHistoryData": OCA.Onlyoffice.onRequestHistoryData, "onDocumentReady": OCA.Onlyoffice.onDocumentReady, + "onMakeActionLink": OCA.Onlyoffice.onMakeActionLink, }; - if (!OCA.Onlyoffice.version) { - config.events.onRequestHistoryClose = OCA.Onlyoffice.onRequestHistoryClose; + if (!OCA.Onlyoffice.template) { + config.events.onRequestHistory = OCA.Onlyoffice.onRequestHistory; + config.events.onRequestHistoryData = OCA.Onlyoffice.onRequestHistoryData; + + if (!OCA.Onlyoffice.version) { + config.events.onRequestHistoryClose = OCA.Onlyoffice.onRequestHistoryClose; + } } if (config.editorConfig.tenant) { config.events.onAppReady = function () { - OCA.Onlyoffice.docEditor.showMessage(t(OCA.Onlyoffice.AppName, "You are using public demo ONLYOFFICE Document Server. Please do not store private sensitive data.")); + OCA.Onlyoffice.docEditor.showMessage(t(OCA.Onlyoffice.AppName, "You are using public demo ONLYOFFICE Docs server. Please do not store private sensitive data.")); }; } @@ -149,6 +157,13 @@ config.events.onRequestInsertImage = OCA.Onlyoffice.onRequestInsertImage; config.events.onRequestMailMergeRecipients = OCA.Onlyoffice.onRequestMailMergeRecipients; config.events.onRequestCompareFile = OCA.Onlyoffice.onRequestCompareFile; + config.events.onRequestUsers = OCA.Onlyoffice.onRequestUsers; + config.events.onRequestSendNotify = OCA.Onlyoffice.onRequestSendNotify; + config.events.onMetaChange = OCA.Onlyoffice.onMetaChange; + + if (!OCA.Onlyoffice.filePath) { + OCA.Onlyoffice.filePath = config._file_path; + } } if (OCA.Onlyoffice.directEditor || OCA.Onlyoffice.inframe) { @@ -257,10 +272,12 @@ url: event.data.url }; - var arrayPath = OCA.Onlyoffice.filePath.split("/"); - arrayPath.pop(); - arrayPath.shift(); - var currentDir = "/" + arrayPath.join("/"); + if (OCA.Onlyoffice.filePath) { + var arrayPath = OCA.Onlyoffice.filePath.split("/"); + arrayPath.pop(); + arrayPath.shift(); + saveData.dir = "/" + arrayPath.join("/"); + } if (OCA.Onlyoffice.inframe) { window.parent.postMessage({ @@ -276,9 +293,9 @@ }, false, "httpd/unix-directory", - false, + true, OC.dialogs.FILEPICKER_TYPE_CHOOSE, - currentDir); + saveData.dir); } }; @@ -314,7 +331,11 @@ }, "*"); } else { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Insert image"), OCA.Onlyoffice.editorInsertImage, false, imageMimes); + OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Insert image"), + OCA.Onlyoffice.editorInsertImage, + false, + imageMimes, + true); } }; @@ -349,7 +370,11 @@ }, "*"); } else { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select recipients"), OCA.Onlyoffice.editorSetRecipient, false, recipientMimes); + OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select recipients"), + OCA.Onlyoffice.editorSetRecipient, + false, + recipientMimes, + true); } }; @@ -401,7 +426,11 @@ }, "*"); } else { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select file to compare"), OCA.Onlyoffice.editorSetRevised, false, revisedMimes); + OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select file to compare"), + OCA.Onlyoffice.editorSetRevised, + false, + revisedMimes, + true); } }; @@ -420,6 +449,84 @@ }); }; + OCA.Onlyoffice.onMakeActionLink = function (event) { + var url = location.href; + if (event && event.data) { + var indexAnchor = url.indexOf("#"); + if (indexAnchor != -1) { + url = url.substring(0, indexAnchor); + } + + var data = JSON.stringify(event.data); + data = "anchor=" + encodeURIComponent(data); + + var inframeRegex = /inframe=([^&]*&?)/g; + if (inframeRegex.test(url)) { + url = url.replace(inframeRegex, data); + } + + var anchorRegex = /anchor=([^&]*)/g; + if (anchorRegex.test(url)) { + url = url.replace(anchorRegex, data); + } else { + url += (url.indexOf("?") == -1) ? "?" : "&"; + url += data; + } + } + + OCA.Onlyoffice.docEditor.setActionLink(url); + }; + + OCA.Onlyoffice.onRequestUsers = function (event) { + $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/users"), + function onSuccess(response) { + OCA.Onlyoffice.docEditor.setUsers({ + "users": response + }); + }); + }; + + OCA.Onlyoffice.onRequestSendNotify = function (event) { + var actionLink = event.data.actionLink; + var comment = event.data.message; + var emails = event.data.emails; + + var fileId = OCA.Onlyoffice.fileId; + + $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/mention"), + { + fileId: fileId, + anchor: JSON.stringify(actionLink), + comment: comment, + emails: emails + }, + function onSuccess(response) { + if (response.error) { + OCP.Toast.error(response.error); + return; + } + + OCP.Toast.success(response.message); + }); + }; + + OCA.Onlyoffice.onMetaChange = function (event) { + if (event.data.favorite !== undefined) { + $.ajax({ + url: OC.generateUrl("apps/files/api/v1/files" + OC.encodePath(OCA.Onlyoffice.filePath)), + type: "post", + data: JSON.stringify({ + tags: event.data.favorite ? [OC.TAG_FAVORITE] : [] + }), + contentType: "application/json", + dataType: "json", + success: function(){ + OCA.Onlyoffice.docEditor.setFavorite(event.data.favorite); + } + }); + } + } + OCA.Onlyoffice.InitEditor(); })(jQuery, OCA); diff --git a/js/listener.js b/js/listener.js index a88c626..0e5dbc2 100644 --- a/js/listener.js +++ b/js/listener.js @@ -38,11 +38,6 @@ OCA.Onlyoffice.onRequestSaveAs = function (saveData) { - var arrayPath = OCA.Viewer.file.split("/"); - arrayPath.pop(); - arrayPath.shift(); - var currentDir = "/" + arrayPath.join("/"); - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Save as"), function (fileDir) { saveData.dir = fileDir; @@ -50,30 +45,33 @@ }, false, "httpd/unix-directory", - false, + true, OC.dialogs.FILEPICKER_TYPE_CHOOSE, - currentDir); + saveData.dir); }; OCA.Onlyoffice.onRequestInsertImage = function (imageMimes) { OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Insert image"), $(OCA.Onlyoffice.frameSelector)[0].contentWindow.OCA.Onlyoffice.editorInsertImage, false, - imageMimes); + imageMimes, + true); }; OCA.Onlyoffice.onRequestMailMergeRecipients = function (recipientMimes) { OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select recipients"), $(OCA.Onlyoffice.frameSelector)[0].contentWindow.OCA.Onlyoffice.editorSetRecipient, false, - recipientMimes); + recipientMimes, + true); }; OCA.Onlyoffice.onRequestCompareFile = function (revisedMimes) { OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select file to compare"), $(OCA.Onlyoffice.frameSelector)[0].contentWindow.OCA.Onlyoffice.editorSetRevised, false, - revisedMimes); + revisedMimes, + true); }; OCA.Onlyoffice.onDocumentReady = function (documentType) { @@ -26,12 +26,13 @@ }, OCA.Onlyoffice); OCA.Onlyoffice.setting = {}; + OCA.Onlyoffice.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i.test(navigator.userAgent); OCA.Onlyoffice.CreateFile = function (name, fileList, templateId) { var dir = fileList.getCurrentDirectory(); - if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.Desktop) { - $loaderUrl = OCA.Onlyoffice.Desktop ? "" : OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/loader"); + if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) { + $loaderUrl = OCA.Onlyoffice.Desktop ? "" : OC.filePath(OCA.Onlyoffice.AppName, "templates", "loader.html"); var winEditor = window.open($loaderUrl); } @@ -95,7 +96,7 @@ if (winEditor && winEditor.location) { winEditor.location.href = url; - } else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.Desktop) { + } else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) { winEditor = window.open(url, "_blank"); } else if ($("#isPublic").val() === "1" && !$("#filestable").length) { location.href = url; @@ -136,9 +137,9 @@ OCA.Onlyoffice.OpenShareDialog = function () { if (OCA.Onlyoffice.context) { - if (!$("#app-sidebar, #app-sidebar-vue").is(":visible")) { - OCA.Onlyoffice.context.fileList.showDetailsView(OCA.Onlyoffice.context.fileName, "sharing"); - OC.Apps.showAppSidebar(); + if (!$("#app-sidebar-vue").is(":visible")) { + OCA.Files.Sidebar.open(OCA.Onlyoffice.context.dir + "/" + OCA.Onlyoffice.context.fileName); + OCA.Files.Sidebar.setActiveTab("sharing"); } else { OCA.Files.Sidebar.close(); } @@ -177,10 +178,71 @@ fileList.add(response, { animate: true }); } - OCP.Toast.success(t(OCA.Onlyoffice.AppName, "File created")); + OCP.Toast.success(t(OCA.Onlyoffice.AppName, "File has been converted. Its content might look different.")); }); }; + OCA.Onlyoffice.DownloadClick = function (fileName, context) { + $.get(OC.filePath(OCA.Onlyoffice.AppName, "templates", "downloadPicker.html"), + function (tmpl) { + var dialog = $(tmpl).octemplate({ + dialog_name: "download-picker", + dialog_title: t("onlyoffice", "Download as") + }); + + $(dialog[0].querySelectorAll("p")).text(fileName + " " + t(OCA.Onlyoffice.AppName, "Convert into")); + + var extension = getFileExtension(fileName); + var selectNode = dialog[0].querySelectorAll("select")[0]; + var optionNodeOrigin = selectNode.querySelectorAll("option")[0]; + + $(optionNodeOrigin).attr("data-value", extension); + $(optionNodeOrigin).text(t(OCA.Onlyoffice.AppName, "Origin format")); + + dialog[0].dataset.format = extension; + selectNode.onclick = function() { + dialog[0].dataset.format = $("#onlyoffice-download-select option:selected").attr("data-value"); + } + + OCA.Onlyoffice.setting.formats[extension].saveas.forEach(ext => { + var optionNode = optionNodeOrigin.cloneNode(true); + + $(optionNode).attr("data-value", ext); + $(optionNode).text(ext); + + selectNode.append(optionNode); + }) + + $("body").append(dialog) + + $("#download-picker").ocdialog({ + closeOnEscape: true, + modal: true, + buttons: [{ + text: t("core", "Cancel"), + classes: "cancel", + click: function() { + $(this).ocdialog("close") + } + }, { + text: t("onlyoffice", "Download"), + classes: "primary", + click: function() { + var format = this.dataset.format; + var fileId = context.fileInfoModel.id; + var downloadLink = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/downloadas?fileId={fileId}&toExtension={toExtension}",{ + fileId: fileId, + toExtension: format + }); + + location.href = downloadLink; + $(this).ocdialog("close") + } + }] + }); + }); + } + OCA.Onlyoffice.GetSettings = function (callbackSettings) { if (OCA.Onlyoffice.setting.formats) { @@ -230,6 +292,17 @@ actionHandler: OCA.Onlyoffice.FileConvertClick }); } + + if (config.saveas && !$("#isPublic").val()) { + OCA.Files.fileActions.registerAction({ + name: "onlyofficeDownload", + displayName: t(OCA.Onlyoffice.AppName, "Download as"), + mime: config.mime, + permissions: OC.PERMISSION_READ, + iconClass: "icon-onlyoffice-download", + actionHandler: OCA.Onlyoffice.DownloadClick + }); + } }); } @@ -345,6 +418,7 @@ var initPage = function () { if ($("#isPublic").val() === "1" && !$("#filestable").length) { + //file by shared link var fileName = $("#filename").val(); var extension = getFileExtension(fileName); @@ -370,7 +444,11 @@ OCA.Onlyoffice.GetSettings(initSharedButton); } else { - OC.Plugins.register("OCA.Files.NewFileMenu", OCA.Onlyoffice.NewFileMenu); + if ($("#isPublic").val() === "1" && !!$("#filestable").length + || OC.config.version.split(".")[0] < 21) { + //folder by shared link + OC.Plugins.register("OCA.Files.NewFileMenu", OCA.Onlyoffice.NewFileMenu); + } OCA.Onlyoffice.registerAction(); diff --git a/js/settings.js b/js/settings.js index bfbccbd..7862da6 100644 --- a/js/settings.js +++ b/js/settings.js @@ -162,7 +162,7 @@ $("#onlyofficeStorageUrl").val(response.storageUrl); $("#onlyofficeSecret").val(response.secret); - $(".section-onlyoffice-common, .section-onlyoffice-watermark").toggleClass("onlyoffice-hide", (!response.documentserver.length && !demo) || !!response.error.length); + $(".section-onlyoffice-common, .section-onlyoffice-templates, .section-onlyoffice-watermark").toggleClass("onlyoffice-hide", (!response.documentserver.length && !demo) || !!response.error.length); var versionMessage = response.version ? (" (" + t(OCA.Onlyoffice.AppName, "version") + " " + response.version + ")") : ""; @@ -351,7 +351,7 @@ }); }); - $(document).on("click", ".onlyoffice-template-preview", function (event) { + $(document).on("click", ".onlyoffice-template-item p", function (event) { var item = $(event.target).parents(".onlyoffice-template-item"); var templateId = $(item).attr("data-id"); @@ -363,6 +363,18 @@ window.open(url); }); + + $(document).on("click", ".onlyoffice-template-download", function (event) { + var item = $(event.target).parents(".onlyoffice-template-item"); + var templateId = $(item).attr("data-id"); + + var downloadLink = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/downloadas?fileId={fileId}&template={template}",{ + fileId: templateId, + template: "true" + }); + + location.href = downloadLink; + }); }); })(jQuery, OC); |