diff options
-rw-r--r-- | appinfo/application.php | 22 | ||||
-rw-r--r-- | css/viewer.css | 37 | ||||
-rw-r--r-- | js/editor.js | 4 | ||||
-rw-r--r-- | js/listener.js | 10 | ||||
-rw-r--r-- | js/viewer.js | 121 |
5 files changed, 192 insertions, 2 deletions
diff --git a/appinfo/application.php b/appinfo/application.php index f35aff6..ebe7595 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -30,9 +30,12 @@ namespace OCA\Onlyoffice\AppInfo; use OCP\AppFramework\App; +use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\DirectEditing\RegisterDirectEditorEvent; use OCP\Util; +use OCA\Viewer\Event\LoadViewer; + use OCA\Onlyoffice\AppConfig; use OCA\Onlyoffice\Controller\CallbackController; use OCA\Onlyoffice\Controller\EditorController; @@ -82,6 +85,25 @@ class Application extends App { } }); + if (class_exists(LoadViewer::class)) { + $eventDispatcher->addListener(LoadViewer::class, + function() { + if (!empty($this->appConfig->GetDocumentServerUrl()) + && $this->appConfig->SettingsAreSuccessful() + && $this->appConfig->isUserAllowedToUse()) { + Util::addScript("onlyoffice", "viewer"); + Util::addScript("onlyoffice", "listener"); + + Util::addStyle("onlyoffice", "viewer"); + + $csp = new ContentSecurityPolicy(); + $csp->addAllowedFrameDomain("'self'"); + $cspManager = $this->getContainer()->getServer()->getContentSecurityPolicyManager(); + $cspManager->addDefaultPolicy($csp); + } + }); + } + $eventDispatcher->addListener("OCA\Files_Sharing::loadAdditionalScripts", function() { if (!empty($this->appConfig->GetDocumentServerUrl()) diff --git a/css/viewer.css b/css/viewer.css new file mode 100644 index 0000000..48f97e3 --- /dev/null +++ b/css/viewer.css @@ -0,0 +1,37 @@ +/** + * + * (c) Copyright Ascensio System SIA 2020 + * + * This program is a free software product. + * You can redistribute it and/or modify it under the terms of the GNU Affero General Public License + * (AGPL) version 3 as published by the Free Software Foundation. + * In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * For details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions of the Program + * must display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product logo when distributing the program. + * Pursuant to Section 7(e) we decline to grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as well as technical + * writing content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International. + * See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +#onlyofficeViewerFrame { + background-color: #fff; + width: 100%; + height: calc(100vh - 50px); + display: block; + position: absolute; + top: 50px; + z-index: 110; +} diff --git a/js/editor.js b/js/editor.js index 841104a..2b6bf7b 100644 --- a/js/editor.js +++ b/js/editor.js @@ -152,7 +152,9 @@ config.events.onRequestClose = OCA.Onlyoffice.onRequestClose; } - if (OCA.Onlyoffice.inframe && config._files_sharing && !shareToken) { + if (OCA.Onlyoffice.inframe + && config._files_sharing && !shareToken + && window.parent.OCA.Onlyoffice.context) { config.events.onRequestSharingSettings = OCA.Onlyoffice.onRequestSharingSettings; } diff --git a/js/listener.js b/js/listener.js index b8d2915..4a78189 100644 --- a/js/listener.js +++ b/js/listener.js @@ -32,10 +32,15 @@ AppName: "onlyoffice", context: null, folderUrl: null, - frameSelector: null + frameSelector: null, + canExpandHeader: true, }, OCA.Onlyoffice); OCA.Onlyoffice.ShowHeaderButton = function () { + if (!OCA.Onlyoffice.canExpandHeader) { + return; + } + var wrapper = $("<div id='onlyofficeHeader' />") var btnClose = $("<a class='icon icon-close-white'></a>"); @@ -63,6 +68,9 @@ $(OCA.Onlyoffice.frameSelector).remove(); $("#onlyofficeHeader").remove(); + if (OCA.Viewer) { + OCA.Viewer.close(); + } OCA.Onlyoffice.context = null; diff --git a/js/viewer.js b/js/viewer.js new file mode 100644 index 0000000..183a8e3 --- /dev/null +++ b/js/viewer.js @@ -0,0 +1,121 @@ +/** + * + * (c) Copyright Ascensio System SIA 2020 + * + * This program is a free software product. + * You can redistribute it and/or modify it under the terms of the GNU Affero General Public License + * (AGPL) version 3 as published by the Free Software Foundation. + * In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * For details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions of the Program + * must display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product logo when distributing the program. + * Pursuant to Section 7(e) we decline to grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as well as technical + * writing content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International. + * See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +(function (OCA) { + if (OCA.Onlyoffice) { + return; + } + + 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(); + } + ); + + } + }; + + var OnlyofficeViewerVue = { + name: "OnlyofficeViewerVue", + render: function (createElement) { + var self = this; + + return createElement("iframe", { + attrs: { + id: "onlyofficeViewerFrame", + scrolling: "no", + src: self.url + "&inframe=true", + }, + on: { + load: function() { + self.doneLoading(); + }, + }, + }) + }, + props: { + filename: { + type: String, + default: null + }, + fileid: { + type: Number, + default: null + } + }, + data: function () { + return { + url: OC.generateUrl("/apps/" + OCA.Onlyoffice.AppName + "/{fileId}?filePath={filePath}", + { + fileId: this.fileid, + filePath: this.filename + }) + } + } + }; + + var initPage = function () { + if (OCA.Viewer) { + OCA.Onlyoffice.canExpandHeader = false; + + OCA.Onlyoffice.frameSelector = "#onlyofficeViewerFrame"; + + OCA.Onlyoffice.GetSettings(function(){ + + var mimes = $.map(OCA.Onlyoffice.setting.formats, function(format) { + return format.mime; + }); + + OCA.Viewer.registerHandler({ + id: OCA.Onlyoffice.AppName, + group: "documents", + mimes: mimes, + component: OnlyofficeViewerVue + }) + }); + } + }; + + $(document).ready(initPage) + +})(OCA); |