java: onRequestOpen for referenceData source file

This commit is contained in:
ZEROM22
2023-10-24 11:06:01 +03:00
parent 4e3f87f692
commit 4387282949
2 changed files with 32 additions and 3 deletions

View File

@ -733,6 +733,7 @@ public class IndexServlet extends HttpServlet {
data.put("directUrl", directUrl ? DocumentManager.getDownloadUrl(fileName, false) : null);
data.put("referenceData", referenceData);
data.put("path", fileName);
data.put("link", DocumentManager.getServerUrl(false) + "/EditorServlet?fileName=" + fileName);
if (DocumentManager.tokenEnabled()) {
String token = DocumentManager.createToken(data);

View File

@ -165,15 +165,41 @@
}
};
var onRequestOpen = function(event) { // user open external data source
innerAlert("onRequestOpen");
var windowName = event.data.windowName;
requestReference(event.data, function (data) {
if (data.error) {
var winEditor = window.open("", windowName);
winEditor.close();
innerAlert(data.error, true);
return;
}
var link = data.link;
window.open(link, windowName);
});
};
var onRequestReferenceData = function(event) { // user refresh external data source
event.data.directUrl = !!config.document.directUrl;
innerAlert("onRequestReferenceData");
requestReference(event.data, function (data) {
docEditor.setReferenceData(data);
});
};
var requestReference = function(data, callback) {
innerAlert(data);
data.directUrl = !!config.document.directUrl;
let xhr = new XMLHttpRequest();
xhr.open("POST", "IndexServlet?type=reference");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(event.data));
xhr.send(JSON.stringify(data));
xhr.onload = function () {
innerAlert(xhr.responseText);
docEditor.setReferenceData(JSON.parse(xhr.responseText));
callback(JSON.parse(xhr.responseText));
}
};
@ -277,6 +303,8 @@
config.events['onRequestReferenceData'] = onRequestReferenceData;
// prevent switch the document from the viewing into the editing mode for anonymous users
config.events['onRequestEditRights'] = onRequestEditRights;
// add link to reference data source file
config.events['onRequestOpen'] = onRequestOpen;
}
if (config.editorConfig.createUrl) {