PageSourceSearch

https://nube.junin.gob.ec/apps/onlyoffice/js/main.js?v=0345a561-89

js junin.gob.ec collected 2026-10-02 01:02:29 UTC 13,552 bytes, 388 lines download raw bytes

1/**
2 *
3 * (c) Copyright Ascensio System SIA 2020
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19(function (OCA) {
20
21    OCA.Onlyoffice = _.extend({
22            AppName: "onlyoffice",
23            context: null,
24            folderUrl: null,
25            frameSelector: null,
26        }, OCA.Onlyoffice);
27
28    OCA.Onlyoffice.setting = {};
29
30    OCA.Onlyoffice.CreateFile = function (name, fileList) {
31        var dir = fileList.getCurrentDirectory();
32
33        if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.Desktop) {
34            $loaderUrl = OCA.Onlyoffice.Desktop ? "" : OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/loader");
35            var winEditor = window.open($loaderUrl);
36        }
37
38        var createData = {
39            name: name,
40            dir: dir
41        };
42
43        if ($("#isPublic").val()) {
44            createData.shareToken = encodeURIComponent($("#sharingToken").val());
45        }
46
47        $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/new"),
48            createData,
49            function onSuccess(response) {
50                if (response.error) {
51                    if (winEditor) {
52                        winEditor.close();
53                    }
54                    OCP.Toast.error(response.error);
55                    return;
56                }
57
58                fileList.add(response, { animate: true });
59                OCA.Onlyoffice.OpenEditor(response.id, dir, response.name, 0, winEditor);
60
61                OCA.Onlyoffice.context = { fileList: fileList };
62                OCA.Onlyoffice.context.fileName = response.name;
63
64                OCP.Toast.success(t(OCA.Onlyoffice.AppName, "File created"));
65            }
66        );
67    };
68
69    OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, version, winEditor) {
70        var filePath = "";
71        if (fileName) {
72            filePath = fileDir.replace(new RegExp("\/$"), "") + "/" + fileName;
73        }
74        var url = OC.generateUrl("/apps/" + OCA.Onlyoffice.AppName + "/{fileId}?filePath={filePath}",
75            {
76                fileId: fileId,
77                filePath: filePath
78            });
79
80        if ($("#isPublic").val()) {
81            url = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/{shareToken}?fileId={fileId}",
82                {
83                    shareToken: encodeURIComponent($("#sharingToken").val()),
84                    fileId: fileId
85                });
86        }
87
88        if (version > 0) {
89            url += "&version=" + version;
90        }
91
92        if (winEditor && winEditor.location) {
93            winEditor.location.href = url;
94        } else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.Desktop) {
95            winEditor = window.open(url, "_blank");
96        } else if ($("#isPublic").val() === "1" && !$("#filestable").length) {
97            location.href = url;
98        } else {
99            OCA.Onlyoffice.frameSelector = "#onlyofficeFrame";
100            var $iframe = $("<iframe id=\"onlyofficeFrame\" nonce=\"" + btoa(OC.requestToken) + "\" scrolling=\"no\" allowfullscreen src=\"" + url + "&inframe=true\" />");
101            $("#app-content").append($iframe);
102
103            $("body").addClass("onlyoffice-inline");
104
105            OCA.Files.Sidebar.close();
106
107            var scrollTop = $(window).scrollTop();
108            $(OCA.Onlyoffice.frameSelector).css("top", scrollTop);
109
110            OCA.Onlyoffice.folderUrl = location.href;
111            window.history.pushState(null, null, url);
112        }
113    };
114
115    OCA.Onlyoffice.ShowHeaderButton = function () {
116        if ($("#onlyofficeHeader").length) {
117            return;
118        }
119
120        var wrapper = $("<div id='onlyofficeHeader' />")
121
122        var btnClose = $("<a class='icon icon-close-white'></a>");
123        btnClose.on("click", function() {
124            OCA.Onlyoffice.onRequestClose();
125        });
126        wrapper.prepend(btnClose);
127
128        if (!$("#isPublic").val()) {
129            var btnShare = $("<a class='icon icon-shared icon-white'></a>");
130            btnShare.on("click", function () {
131                OCA.Onlyoffice.OpenShareDialog();
132            })
133            wrapper.prepend(btnShare);
134        }
135
136        if (!$("#header .header-right").length) {
137            $("#header").append("<div class='header-right'></div>");
138        }
139        wrapper.prependTo(".header-right");
140    };
141
142    OCA.Onlyoffice.CloseEditor = function () {
143        OCA.Onlyoffice.frameSelector = null;
144
145        $("body").removeClass("onlyoffice-inline");
146        $("#onlyofficeHeader").remove();
147
148        OCA.Onlyoffice.context = null;
149
150        var url = OCA.Onlyoffice.folderUrl;
151        if (!!url) {
152            window.history.pushState(null, null, url);
153            OCA.Onlyoffice.folderUrl = null;
154        }
155
156        OCA.Onlyoffice.bindVersionClick();
157    };
158
159    OCA.Onlyoffice.OpenShareDialog = function () {
160        if (OCA.Onlyoffice.context) {
161            if (!$("#app-sidebar").is(":visible")) {
162                OCA.Onlyoffice.context.fileList.showDetailsView(OCA.Onlyoffice.context.fileName, "sharing");
163                OC.Apps.showAppSidebar();
164            } else {
165                OCA.Files.Sidebar.close();
166            }
167        }
168    };
169
170    OCA.Onlyoffice.FileClick = function (fileName, context) {
171        var fileInfoModel = context.fileInfoModel || context.fileList.getModelForFile(fileName);
172        OCA.Onlyoffice.OpenEditor(fileInfoModel.id, context.dir, fileName);
173
174        OCA.Onlyoffice.context = context;
175        OCA.Onlyoffice.context.fileName = fileName;
176    };
177
178    OCA.Onlyoffice.FileConvertClick = function (fileName, context) {
179        var fileInfoModel = context.fileInfoModel || context.fileList.getModelForFile(fileName);
180        var fileList = context.fileList;
181
182        var convertData = {
183            fileId: fileInfoModel.id
184        };
185
186        if ($("#isPublic").val()) {
187            convertData.shareToken = encodeURIComponent($("#sharingToken").val());
188        }
189
190        $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/convert"),
191            convertData,
192            function onSuccess(response) {
193                if (response.error) {
194                    OCP.Toast.error(response.error);
195                    return;
196                }
197
198                if (response.parentId == fileList.dirInfo.id) {
199                    fileList.add(response, { animate: true });
200                }
201
202                OCP.Toast.success(t(OCA.Onlyoffice.AppName, "File created"));
203            });
204    };
205
206    OCA.Onlyoffice.GetSettings = function (callbackSettings) {
207        if (OCA.Onlyoffice.setting.formats) {
208
209            callbackSettings();
210
211        } else {
212
213            $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/settings"),
214                function onSuccess(settings) {
215                    OCA.Onlyoffice.setting = settings;
216
217                    callbackSettings();
218                }
219            );
220
221        }
222    };
223
224    OCA.Onlyoffice.FileList = {
225        attach: function (fileList) {
226            if (fileList.id == "trashbin") {
227                return;
228            }
229
230            var register = function () {
231                var formats = OCA.Onlyoffice.setting.formats;
232
233                $.each(formats, function (ext, config) {
234                    if (!config.mime) {
235                        return true;
236                    }
237                    fileList.fileActions.registerAction({
238                        name: "onlyofficeOpen",
239                        displayName: t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE"),
240                        mime: config.mime,
241                        permissions: OC.PERMISSION_READ,
242                        iconClass: "icon-onlyoffice-open",
243                        actionHandler: OCA.Onlyoffice.FileClick
244                    });
245
246                    if (config.def) {
247                        fileList.fileActions.setDefault(config.mime, "onlyofficeOpen");
248                    }
249
250                    if (config.conv) {
251                        fileList.fileActions.registerAction({
252                            name: "onlyofficeConvert",
253                            displayName: t(OCA.Onlyoffice.AppName, "Convert with ONLYOFFICE"),
254                            mime: config.mime,
255                            permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ),
256                            iconClass: "icon-onlyoffice-convert",
257                            actionHandler: OCA.Onlyoffice.FileConvertClick
258                        });
259                    }
260                });
261            }
262
263            OCA.Onlyoffice.GetSettings(register);
264        }
265    };
266
267    OCA.Onlyoffice.NewFileMenu = {
268        attach: function (menu) {
269            var fileList = menu.fileList;
270
271            if (fileList.id !== "files" && fileList.id !== "files.public") {
272                return;
273            }
274
275            menu.addMenuEntry({
276                id: "onlyofficeDocx",
277                displayName: t(OCA.Onlyoffice.AppName, "Document"),
278                templateName: t(OCA.Onlyoffice.AppName, "Document"),
279                iconClass: "icon-onlyoffice-new-docx",
280                fileType: "docx",
281                actionHandler: function (name) {
282                    OCA.Onlyoffice.CreateFile(name + ".docx", fileList);
283                }
284            });
285
286            menu.addMenuEntry({
287                id: "onlyofficeXlsx",
288                displayName: t(OCA.Onlyoffice.AppName, "Spreadsheet"),
289                templateName: t(OCA.Onlyoffice.AppName, "Spreadsheet"),
290                iconClass: "icon-onlyoffice-new-xlsx",
291                fileType: "xlsx",
292                actionHandler: function (name) {
293                    OCA.Onlyoffice.CreateFile(name + ".xlsx", fileList);
294                }
295            });
296
297            menu.addMenuEntry({
298                id: "onlyofficePpts",
299                displayName: t(OCA.Onlyoffice.AppName, "Presentation"),
300                templateName: t(OCA.Onlyoffice.AppName, "Presentation"),
301                iconClass: "icon-onlyoffice-new-pptx",
302                fileType: "pptx",
303                actionHandler: function (name) {
304                    OCA.Onlyoffice.CreateFile(name + ".pptx", fileList);
305                }
306            });
307        }
308    };
309
310    var getFileExtension = function (fileName) {
311        var extension = fileName.substr(fileName.lastIndexOf(".") + 1).toLowerCase();
312        return extension;
313    }
314
315    OCA.Onlyoffice.openVersion = function (fileId, version) {
316        if (OCA.Onlyoffice.frameSelector) {
317            $(OCA.Onlyoffice.frameSelector)[0].contentWindow.OCA.Onlyoffice.onRequestHistory(version);
318            return;
319        }
320
321        OCA.Onlyoffice.OpenEditor(fileId, "", "", version)
322    };
323
324    OCA.Onlyoffice.bindVersionClick = function () {
325        OCA.Onlyoffice.unbindVersionClick();
326        $(document).on("click.onlyoffice-version", "#versionsTabView .downloadVersion", function() {
327            var versionNodes = $("#versionsTabView ul.versions>li");
328            var versionNode = $(this).closest("#versionsTabView ul.versions>li")[0];
329
330            var href = $(this).attr("href");
331            var search = new RegExp("\/versions\/(\\d+)\/\\d+$");
332            var result = search.exec(href);
333            if (result && result.length > 1) {
334                var fileId = result[1];
335            }
336            if (!fileId) {
337                return true;
338            }
339
340            var versionNum = versionNodes.length - $.inArray(versionNode, versionNodes);
341
342            OCA.Onlyoffice.openVersion(fileId, versionNum);
343
344            return false;
345        });
346    };
347
348    OCA.Onlyoffice.unbindVersionClick = function() {
349        $(document).off("click.onlyoffice-version", "#versionsTabView .downloadVersion");
350    }
351
352    var initPage = function () {
353        if ($("#isPublic").val() === "1" && !$("#filestable").length) {
354            var fileName = $("#filename").val();
355            var extension = getFileExtension(fileName);
356
357            var initSharedButton = function () {
358                var formats = OCA.Onlyoffice.setting.formats;
359
360                var config = formats[extension];
361                if (!config) {
362                    return;
363                }
364
365                var button = document.createElement("a");
366                button.href = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val()));
367                button.className = "onlyoffice-public-open button";
368                button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE")
369
370                if (!OCA.Onlyoffice.setting.sameTab) {
371                    button.target = "_blank";
372                }
373
374                $("#preview").prepend(button);
375            };
376
377            OCA.Onlyoffice.GetSettings(initSharedButton);
378        } else {
379            OC.Plugins.register("OCA.Files.FileList", OCA.Onlyoffice.FileList);
380            OC.Plugins.register("OCA.Files.NewFileMenu", OCA.Onlyoffice.NewFileMenu);
381
382            OCA.Onlyoffice.bindVersionClick();
383        }
384    };
385
386    initPage();
387
388})(OCA);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.