diff options
author | Sergey Linnik <sergey.linnik@onlyoffice.com> | 2022-10-03 17:21:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-03 17:21:52 +0300 |
commit | 3179a6bbe9860fd6551644e1010c0847882e6820 (patch) | |
tree | a01240d61c6179c0e0c6f679098c4b4bedd68805 /js | |
parent | 0f484a7eb23775ee82c6a41ec7e3d2c91790c774 (diff) | |
parent | 35fe7734d1435d1a58c90e54fff69001e16c41e7 (diff) |
Merge pull request #705 from ONLYOFFICE/feature/initial-state
Feature/initial state
Diffstat (limited to 'js')
-rw-r--r-- | js/main.js | 178 | ||||
-rw-r--r-- | js/viewer.js | 50 |
2 files changed, 92 insertions, 136 deletions
@@ -25,7 +25,7 @@ frameSelector: null, }, OCA.Onlyoffice); - OCA.Onlyoffice.setting = {}; + OCA.Onlyoffice.setting = OCP.InitialState.loadState(OCA.Onlyoffice.AppName, "settings"); OCA.Onlyoffice.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini|Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints && navigator.maxTouchPoints > 1; @@ -312,92 +312,70 @@ OCA.Onlyoffice.CreateFile(name, fileList, 0, targetId, false); }; - OCA.Onlyoffice.GetSettings = function (callbackSettings) { - if (OCA.Onlyoffice.setting.formats) { - - callbackSettings(); - - } else { - - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/settings"), - function onSuccess(settings) { - OCA.Onlyoffice.setting = settings; + OCA.Onlyoffice.registerAction = function() { + var formats = OCA.Onlyoffice.setting.formats; - callbackSettings(); - } - ); + $.each(formats, function (ext, config) { + if (!config.mime) { + return true; + } + OCA.Files.fileActions.registerAction({ + name: "onlyofficeOpen", + displayName: t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE"), + mime: config.mime, + permissions: OC.PERMISSION_READ, + iconClass: "icon-onlyoffice-open", + actionHandler: OCA.Onlyoffice.FileClick + }); - } - }; + if (config.def) { + OCA.Files.fileActions.setDefault(config.mime, "onlyofficeOpen"); + } - OCA.Onlyoffice.registerAction = function() { - var register = function () { - var formats = OCA.Onlyoffice.setting.formats; + if (config.conv) { + OCA.Files.fileActions.registerAction({ + name: "onlyofficeConvert", + displayName: t(OCA.Onlyoffice.AppName, "Convert with ONLYOFFICE"), + mime: config.mime, + permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ), + iconClass: "icon-onlyoffice-convert", + actionHandler: OCA.Onlyoffice.FileConvertClick + }); + } - $.each(formats, function (ext, config) { - if (!config.mime) { - return true; - } + if (config.fillForms) { OCA.Files.fileActions.registerAction({ - name: "onlyofficeOpen", - displayName: t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE"), + name: "onlyofficeFill", + displayName: t(OCA.Onlyoffice.AppName, "Fill in form in ONLYOFFICE"), mime: config.mime, - permissions: OC.PERMISSION_READ, - iconClass: "icon-onlyoffice-open", + permissions: OC.PERMISSION_UPDATE, + iconClass: "icon-onlyoffice-fill", actionHandler: OCA.Onlyoffice.FileClick }); + } - if (config.def) { - OCA.Files.fileActions.setDefault(config.mime, "onlyofficeOpen"); - } - - if (config.conv) { - OCA.Files.fileActions.registerAction({ - name: "onlyofficeConvert", - displayName: t(OCA.Onlyoffice.AppName, "Convert with ONLYOFFICE"), - mime: config.mime, - permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ), - iconClass: "icon-onlyoffice-convert", - actionHandler: OCA.Onlyoffice.FileConvertClick - }); - } - - if (config.fillForms) { - OCA.Files.fileActions.registerAction({ - name: "onlyofficeFill", - displayName: t(OCA.Onlyoffice.AppName, "Fill in form in ONLYOFFICE"), - mime: config.mime, - permissions: OC.PERMISSION_UPDATE, - iconClass: "icon-onlyoffice-fill", - actionHandler: OCA.Onlyoffice.FileClick - }); - } - - if (config.createForm) { - OCA.Files.fileActions.registerAction({ - name: "onlyofficeCreateForm", - displayName: t(OCA.Onlyoffice.AppName, "Create form"), - mime: config.mime, - permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ), - iconClass: "icon-onlyoffice-create", - actionHandler: OCA.Onlyoffice.CreateFormClick - }); - } - - 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 - }); - } - }); - } + if (config.createForm) { + OCA.Files.fileActions.registerAction({ + name: "onlyofficeCreateForm", + displayName: t(OCA.Onlyoffice.AppName, "Create form"), + mime: config.mime, + permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ), + iconClass: "icon-onlyoffice-create", + actionHandler: OCA.Onlyoffice.CreateFormClick + }); + } - OCA.Onlyoffice.GetSettings(register); + 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 + }); + } + }); }; OCA.Onlyoffice.NewFileMenu = { @@ -534,38 +512,34 @@ var fileName = $("#filename").val(); var extension = getFileExtension(fileName); - var initSharedButton = function () { - var formats = OCA.Onlyoffice.setting.formats; - - var config = formats[extension]; - if (!config) { - return; - } + var formats = OCA.Onlyoffice.setting.formats; - var editorUrl = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val())); + var config = formats[extension]; + if (!config) { + return; + } - if (_oc_appswebroots.richdocuments - || _oc_appswebroots.files_pdfviewer && extension === "pdf" - || _oc_appswebroots.text && extension === "txt") { + var editorUrl = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val())); - var button = document.createElement("a"); - button.href = editorUrl; - button.className = "onlyoffice-public-open button"; - button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE") + if (_oc_appswebroots.richdocuments + || _oc_appswebroots.files_pdfviewer && extension === "pdf" + || _oc_appswebroots.text && extension === "txt") { - if (!OCA.Onlyoffice.setting.sameTab) { - button.target = "_blank"; - } + var button = document.createElement("a"); + button.href = editorUrl; + button.className = "onlyoffice-public-open button"; + button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE") - $("#preview").prepend(button); - } else { - OCA.Onlyoffice.frameSelector = "#onlyofficeFrame"; - var $iframe = $("<iframe id=\"onlyofficeFrame\" nonce=\"" + btoa(OC.requestToken) + "\" scrolling=\"no\" allowfullscreen src=\"" + editorUrl + "?inframe=true\" />"); - $("#app-content").append($iframe); + if (!OCA.Onlyoffice.setting.sameTab) { + button.target = "_blank"; } - }; - OCA.Onlyoffice.GetSettings(initSharedButton); + $("#preview").prepend(button); + } else { + OCA.Onlyoffice.frameSelector = "#onlyofficeFrame"; + var $iframe = $("<iframe id=\"onlyofficeFrame\" nonce=\"" + btoa(OC.requestToken) + "\" scrolling=\"no\" allowfullscreen src=\"" + editorUrl + "?inframe=true\" />"); + $("#app-content").append($iframe); + } } else { OC.Plugins.register("OCA.Files.NewFileMenu", OCA.Onlyoffice.NewFileMenu); diff --git a/js/viewer.js b/js/viewer.js index b95f72a..fc69001 100644 --- a/js/viewer.js +++ b/js/viewer.js @@ -22,29 +22,13 @@ } OCA.Onlyoffice = { - AppName: "onlyoffice", - frameSelector: null, - setting: {}, - }; - - OCA.Onlyoffice.GetSettings = function (callbackSettings) { - if (OCA.Onlyoffice.setting.formats) { - - callbackSettings(); - - } else { - - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/settings"), - function onSuccess(settings) { - OCA.Onlyoffice.setting = settings; - - callbackSettings(); - } - ); - - } + AppName: "onlyoffice", + frameSelector: null, + setting: {}, }; + OCA.Onlyoffice.setting = OCP.InitialState.loadState(OCA.Onlyoffice.AppName, "settings"); + var OnlyofficeViewerVue = { name: "OnlyofficeViewerVue", render: function (createElement) { @@ -88,21 +72,19 @@ if (OCA.Viewer) { OCA.Onlyoffice.frameSelector = "#onlyofficeViewerFrame"; - OCA.Onlyoffice.GetSettings(function () { + var mimes = $.map(OCA.Onlyoffice.setting.formats, function (format) { + if (format.def) { + return format.mime; + } + }); - var mimes = $.map(OCA.Onlyoffice.setting.formats, function (format) { - if (format.def) { - return format.mime; - } - }); + OCA.Viewer.registerHandler({ + id: OCA.Onlyoffice.AppName, + group: null, + mimes: mimes, + component: OnlyofficeViewerVue + }) - OCA.Viewer.registerHandler({ - id: OCA.Onlyoffice.AppName, - group: null, - mimes: mimes, - component: OnlyofficeViewerVue - }) - }); } }; |