Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goback from share #630

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions controller/editorapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok
$params["_file_path"] = $userFolder->getRelativePath($file->getPath());
}

if ($inframe === true) {
$params["_files_sharing"] = \OC::$server->getAppManager()->isInstalled("files_sharing");
$params["editorConfig"]["customization"]["goback"]["requestClose"] = true;
$params["editorConfig"]["customization"]["goback"]["text"] = "Close";
}

if ($folderLink !== null
&& $this->config->GetSystemValue($this->config->_customization_goback) !== false) {
$params["editorConfig"]["customization"]["goback"] = [
Expand All @@ -469,10 +475,6 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok
}
}

if ($inframe === true) {
$params["_files_sharing"] = \OC::$server->getAppManager()->isInstalled("files_sharing");
}

$params = $this->setCustomization($params);

$params = $this->setWatermark($params, !empty($shareToken), $userId, $file);
Expand Down
15 changes: 2 additions & 13 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,21 +536,10 @@

var editorUrl = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val()));

if (_oc_appswebroots.richdocuments
if (! (_oc_appswebroots.richdocuments
|| _oc_appswebroots.files_pdfviewer && extension === "pdf"
|| _oc_appswebroots.text && extension === "txt") {
|| _oc_appswebroots.text && extension === "txt")) {

var button = document.createElement("a");
button.href = editorUrl;
button.className = "onlyoffice-public-open button";
button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE")

if (!OCA.Onlyoffice.setting.sameTab) {
button.target = "_blank";
}

$("#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);
Expand Down
102 changes: 102 additions & 0 deletions js/share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
*
* (c) Copyright Ascensio System SIA 2022
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

(function (OCA) {

OCA.Onlyoffice = _.extend({
AppName: "onlyoffice",
context: null,
folderUrl: null,
frameSelector: null,
}, OCA.Onlyoffice);

OCA.Onlyoffice.setting = {};
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;

OCA.Onlyoffice.CloseEditor = function () {
OCA.Onlyoffice.frameSelector = null;

$("body").removeClass("onlyoffice-inline");

OCA.Onlyoffice.context = null;

var url = OCA.Onlyoffice.folderUrl;
if (!!url) {
window.history.pushState(null, null, url);
OCA.Onlyoffice.folderUrl = null;
}

};

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 getFileExtension = function (fileName) {
var extension = fileName.substr(fileName.lastIndexOf(".") + 1).toLowerCase();
return extension;
}

var initPage = function () {
if ($("#isPublic").val() === "1" && !$("#filestable").length) {
//file by shared link
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 editorUrl = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val()));

if (! (_oc_appswebroots.richdocuments
|| _oc_appswebroots.files_pdfviewer && extension === "pdf"
|| _oc_appswebroots.text && extension === "txt")) {

OCA.Onlyoffice.frameSelector = "#onlyofficeFrame";
var $iframe = $("<iframe id=\"onlyofficeFrame\" nonce=\"" + btoa(OC.requestToken) + "\" scrolling=\"no\" allowfullscreen src=\"" + editorUrl + "?inframe=true\" />");
$("#app-content").append($iframe);
}
};

OCA.Onlyoffice.GetSettings(initSharedButton);
}
};

initPage();

})(OCA);
2 changes: 1 addition & 1 deletion lib/listeners/filesharinglistener.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function handle(Event $event): void {

if (!empty($this->appConfig->GetDocumentServerUrl())
&& $this->appConfig->SettingsAreSuccessful()) {
Util::addScript("onlyoffice", "main");
Util::addScript("onlyoffice", "share");

if ($this->appConfig->GetSameTab()) {
Util::addScript("onlyoffice", "listener");
Expand Down