/** * * (c) Copyright Ascensio System SIA 2021 * * 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.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"); var winEditor = window.open($loaderUrl); } var createData = { name: name, dir: dir }; if (templateId) { createData.templateId = templateId; } if ($("#isPublic").val()) { createData.shareToken = encodeURIComponent($("#sharingToken").val()); } $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/new"), createData, function onSuccess(response) { if (response.error) { if (winEditor) { winEditor.close(); } OCP.Toast.error(response.error); return; } fileList.add(response, { animate: true }); OCA.Onlyoffice.OpenEditor(response.id, dir, response.name, 0, winEditor); OCA.Onlyoffice.context = { fileList: fileList }; OCA.Onlyoffice.context.fileName = response.name; OCP.Toast.success(t(OCA.Onlyoffice.AppName, "File created")); } ); }; OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, version, winEditor) { var filePath = ""; if (fileName) { filePath = fileDir.replace(new RegExp("\/$"), "") + "/" + fileName; } var url = OC.generateUrl("/apps/" + OCA.Onlyoffice.AppName + "/{fileId}?filePath={filePath}", { fileId: fileId, filePath: filePath }); if ($("#isPublic").val()) { url = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/{shareToken}?fileId={fileId}", { shareToken: encodeURIComponent($("#sharingToken").val()), fileId: fileId }); } if (version > 0) { url += "&version=" + version; } if (winEditor && winEditor.location) { winEditor.location.href = url; } else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.Desktop) { winEditor = window.open(url, "_blank"); } else if ($("#isPublic").val() === "1" && !$("#filestable").length) { location.href = url; } else { OCA.Onlyoffice.frameSelector = "#onlyofficeFrame"; var $iframe = $("