Compare commits

...

8 Commits

Author SHA1 Message Date
2d2abe9a7e update sample.docxf 2021-11-10 10:37:59 +03:00
4be81ac373 nodejs: message to editor when saving a copy 2021-11-09 14:48:14 +03:00
1b91eca26e nodejs: docxf 2021-11-09 10:52:37 +03:00
e026beb5b6 nodejs: filling on mobile 2021-11-08 17:00:16 +03:00
ee5874e86c nodejs: revert filling in docx 2021-11-08 17:00:16 +03:00
7c7c32e9e7 nodejs: hide submit button 2021-11-08 17:00:15 +03:00
1cbd2ffd61 nodejs: oform 2021-11-08 17:00:15 +03:00
30baa26cd8 nodejs: onRequestSaveAs event 2021-11-08 17:00:14 +03:00
10 changed files with 134 additions and 21 deletions

View File

@ -103,6 +103,7 @@ app.get("/", function (req, res) { // define a handler for default page
preloaderUrl: siteUrl + configServer.get('preloaderUrl'),
convertExts: configServer.get('convertedDocs').join(","),
editedExts: configServer.get('editedDocs').join(","),
fillExts: configServer.get("fillDocs").join(","),
storedFiles: docManager.getStoredFiles(),
params: docManager.getCustomParams(),
users: users,
@ -195,7 +196,7 @@ app.post("/upload", function (req, res) { // define a handler for uploading fil
return;
}
const exts = [].concat(configServer.get('viewedDocs'), configServer.get('editedDocs'), configServer.get('convertedDocs')); // all the supported file extensions
const exts = [].concat(configServer.get('viewedDocs'), configServer.get('editedDocs'), configServer.get('convertedDocs'), configServer.get("fillDocs")); // all the supported file extensions
const curExt = fileUtility.getFileExtension(file.name);
const documentType = fileUtility.getFileType(file.name);
@ -224,6 +225,54 @@ app.post("/upload", function (req, res) { // define a handler for uploading fil
});
});
app.post("/create", function (req, res) {
var title = req.body.title;
var fileUrl = req.body.url;
try {
docManager.init(storageFolder, req, res);
docManager.storagePath(""); // mkdir if not exist
var fileName = docManager.getCorrectName(title);
var userAddress = docManager.curUserHostAddress();
docManager.historyPath(fileName, userAddress, true);
urllib.request(fileUrl, {method: "GET"},function(err, data) {
if (configServer.get("maxFileSize") < data.length || data.length <= 0) { // check if the file size exceeds the maximum file size
res.writeHead(200, { "Content-Type": "application/json" });
res.write(JSON.stringify({ "error": "File size is incorrect" }));
res.end();
return;
}
const exts = [].concat(configServer.get("viewedDocs"), configServer.get("editedDocs"), configServer.get("convertedDocs"), configServer.get("fillDocs")); // all the supported file extensions
const curExt = fileUtility.getFileExtension(fileName);
if (exts.indexOf(curExt) == -1) { // check if the file extension is supported
res.writeHead(200, { "Content-Type": "application/json" }); // and write the error status and message to the response
res.write(JSON.stringify({ "error": "File type is not supported" }));
res.end();
return;
}
fileSystem.writeFileSync(docManager.storagePath(fileName), data);
res.writeHead(200, { "Content-Type": "application/json" });
res.write(JSON.stringify({ "file" : fileName }));
res.end();
});
} catch (e) {
res.status(500);
res.write(JSON.stringify({
error: 1,
message: e.message
}));
res.end();
}
});
app.post("/convert", function (req, res) { // define a handler for converting files
var fileName = fileUtility.getFileName(req.body.filename);
@ -686,6 +735,7 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
res.redirect(redirectPath);
return;
}
fileExt = fileUtility.getFileExtension(fileName);
var userAddress = docManager.curUserHostAddress();
if (!docManager.existsSync(docManager.storagePath(fileName, userAddress))) { // if the file with a given name doesn't exist
@ -702,8 +752,12 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
type = new RegExp(configServer.get("mobileRegEx"), "i").test(req.get('User-Agent')) ? "mobile" : "desktop";
}
var canEdit = configServer.get('editedDocs').indexOf(fileUtility.getFileExtension(fileName)) != -1; // check if this file can be edited
var submitForm = canEdit && (mode == "edit" || mode == "fillForms");
var canEdit = configServer.get('editedDocs').indexOf(fileExt) != -1; // check if this file can be edited
if ((!canEdit && mode == "edit" || mode == "fillForms") && configServer.get('fillDocs').indexOf(fileExt) != -1) {
mode = "fillForms";
canEdit = true;
}
var submitForm = mode == "fillForms" && userid == "uid-1" && !1;
var countVersion = 1;
@ -727,7 +781,7 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
var historyD = {
version: i,
key: keyVersion,
url: i == countVersion ? url : (docManager.getlocalFileUri(fileName, i, true) + "/prev" + fileUtility.getFileExtension(fileName)),
url: i == countVersion ? url : (docManager.getlocalFileUri(fileName, i, true) + "/prev" + fileExt),
};
if (i > 1 && docManager.existsSync(docManager.diffPath(fileName, userAddress, i-1))) { // check if the path to the file with document versions differences exists

View File

@ -23,7 +23,8 @@
"preloaderUrl": "web-apps/apps/api/documents/cache-scripts.html",
"exampleUrl": null,
"viewedDocs": [".pdf", ".djvu", ".xps", ".oxps"],
"editedDocs": [".docx", ".xlsx", ".csv", ".pptx", ".txt"],
"editedDocs": [".docx", ".xlsx", ".csv", ".pptx", ".txt", ".docxf"],
"fillDocs": [".docx", ".oform"],
"convertedDocs": [".docm", ".doc", ".dotx", ".dotm", ".dot", ".odt", ".fodt", ".ott", ".xlsm", ".xls", ".xltx", ".xltm", ".xlt", ".ods", ".fods", ".ots", ".pptm", ".ppt", ".ppsx", ".ppsm", ".pps", ".potx", ".potm", ".pot", ".odp", ".fodp", ".otp", ".rtf", ".mht", ".html", ".htm", ".xml", ".epub", ".fb2"],
"storageFolder": "./files",
"storagePath": "/files",

View File

@ -63,7 +63,7 @@ fileUtility.fileType = {
}
// the document extension list
fileUtility.documentExts = [".doc", ".docx", ".docm", ".dot", ".dotx", ".dotm", ".odt", ".fodt", ".ott", ".rtf", ".txt", ".html", ".htm", ".mht", ".xml", ".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps"];
fileUtility.documentExts = [".doc", ".docx", ".oform", ".docm", ".dot", ".dotx", ".dotm", ".odt", ".fodt", ".ott", ".rtf", ".txt", ".html", ".htm", ".mht", ".xml", ".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps"];
// the spreadsheet extension list
fileUtility.spreadsheetExts = [".xls", ".xlsx", ".xlsm", ".xlt", ".xltx", ".xltm", ".ods", ".fods", ".ots", ".csv"];

View File

@ -22,7 +22,8 @@ var descr_user_1 = [
"Can review all the changes",
"Can perform all actions with comments",
"The file favorite state is undefined",
"Can create files from templates using data from the editor"
"Can create files from templates using data from the editor",
//"Can submit forms"
];
var descr_user_2 = [
@ -30,7 +31,8 @@ var descr_user_2 = [
"Can review only his own changes or changes made by users with no group",
"Can view comments, edit his own comments and comments left by users with no group. Can remove his own comments only",
"This file is marked as favorite",
"Can create new files from the editor"
"Can create new files from the editor",
//"Cant submit forms"
];
var descr_user_3 = [
@ -41,7 +43,8 @@ var descr_user_3 = [
"Cant copy data from the file to clipboard",
"Cant download the file",
"Cant print the file",
"Can create new files from the editor"
"Can create new files from the editor",
//"Cant submit forms"
];
var descr_user_0 = [
@ -51,7 +54,8 @@ var descr_user_0 = [
"Can perform all actions with comments",
"The file favorite state is undefined",
"Can't mention others in comments",
"Can't create new files from the editor"
"Can't create new files from the editor",
//"Cant submit forms"
];
var users = [

View File

@ -0,0 +1,6 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 3C0 1.34315 1.34315 0 3 0H22.9167L30 7.08333V37C30 38.6569 28.6569 40 27 40H3C1.34315 40 0 38.6569 0 37V3Z" fill="#27ABA3"/>
<path d="M22.9165 0L29.9998 7.08333H25.9165C24.2597 7.08333 22.9165 5.74019 22.9165 4.08333V0Z" fill="#008078"/>
<rect x="6.5" y="15.5" width="17" height="5" stroke="white"/>
<rect x="6.5" y="23.5" width="17" height="5" stroke="white"/>
</svg>

After

Width:  |  Height:  |  Size: 477 B

View File

@ -0,0 +1,6 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M5 5C5 3.89543 5.89543 3 7 3H16C17.1046 3 18 3.89543 18 5V8H17V6H6V18H17V16H18V19C18 20.1046 17.1046 21 16 21H7C5.89543 21 5 20.1046 5 19V5ZM13 4H10V5H13V4ZM12 19.5C12 19.7761 11.7761 20 11.5 20C11.2239 20 11 19.7761 11 19.5C11 19.2239 11.2239 19 11.5 19C11.7761 19 12 19.2239 12 19.5Z" fill="#444444"/>
<rect x="7" y="9" width="1" height="6" fill="#444444"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 8V9L11 9V15H12V16H9V15H10V9H9V8H12Z" fill="#444444"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 10H18V14H15H14H13V15H14H18C18.5523 15 19 14.5523 19 14V10C19 9.44772 18.5523 9 18 9H14H13V10H14H15Z" fill="#444444"/>
</svg>

After

Width:  |  Height:  |  Size: 790 B

View File

@ -157,6 +157,10 @@ label .checkbox {
background-image: url("../images/file_pptx.svg");
}
.try-editor.form {
background-image: url("../images/file_docxf.svg");
}
.create-sample {
color: #666666;
line-height: 24px;

View File

@ -39,9 +39,11 @@
var docEditor;
var innerAlert = function (message) {
var innerAlert = function (message, inEditor) {
if (console && console.log)
console.log(message);
if (inEditor && docEditor)
docEditor.showMessage(message);
};
var onAppReady = function () { // the application is loaded into the browser
@ -145,6 +147,22 @@
console.log("Link to comment: " + replaceActionLink(location.href, actionLink));
};
var onRequestSaveAs = function (event) { // the user is trying to save file by clicking Save Copy as... button
var title = event.data.title;
var url = event.data.url;
var data = {
title: title,
url: url
}
let xhr = new XMLHttpRequest();
xhr.open("POST", "create");
xhr.setRequestHeader( 'Content-Type', 'application/json');
xhr.send(JSON.stringify(data));
xhr.onload = function () {
innerAlert(xhr.responseText, true);
}
}
var config = {<%- include("config") %>,
events: {
"onAppReady": onAppReady,
@ -168,6 +186,10 @@
config.events.onRequestSendNotify = onRequestSendNotify;
}
if (config.editorConfig.createUrl) {
config.events.onRequestSaveAs = onRequestSaveAs;
}
var connectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor", config);
fixSize();

View File

@ -56,6 +56,9 @@
<li>
<a class="try-editor slide reload-page" target="_blank" href="editor?fileExt=pptx<%= params %>" title="Create new presentation">Presentation</a>
</li>
<li>
<a class="try-editor form reload-page" target="_blank" href="editor?fileExt=docxf<%= params %>" title="Create new master form">Master form</a>
</li>
</ul>
<label class="create-sample">
<input id="createSample" type="checkbox" class="checkbox" />With sample content
@ -202,23 +205,36 @@
<% } %>
<% if (storedFiles[i].documentType == "word") { %>
<td class="contentCells contentCells-icon">
<a href="editor?type=desktop&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms" /></a>
</td>
<% } else { %>
<td class="contentCells contentCells-icon "></td>
<% } %>
<% if (storedFiles[i].documentType == "word") { %>
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
<a href="editor?type=desktop&mode=blockcontent&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/block-content.svg" alt="Open in editor without content control modification" title="Open in editor without content control modification" /></a>
</td>
<% } else { %>
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift"></td>
<td class="contentCells contentCells-icon"></td>
<% } %>
<% if (storedFiles[i].documentType !== "word" && storedFiles[i].documentType !== "cell") {%>
<td class="contentCells contentCells-icon "></td>
<% } %>
<% if (fillExts.indexOf(storedFiles[i].name.substring(storedFiles[i].name.lastIndexOf('.')).trim().toLowerCase()) !== -1) { %>
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
<a href="editor?type=desktop&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms" /></a>
</td>
<% } else {%>
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift"></td>
<%}%>
<% } else if (fillExts.indexOf(storedFiles[i].name.substring(storedFiles[i].name.lastIndexOf('.')).trim().toLowerCase()) !== -1) { %>
<td class="contentCells contentCells-icon "></td>
<td class="contentCells contentCells-icon">
<a href="editor?type=mobile&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/mobile-fill-forms.svg" alt="Open in editor for filling in forms for mobile devices" title="Open in editor for filling in forms for mobile devices" /></a>
</td>
<td class="contentCells contentCells-icon "></td>
<td class="contentCells contentCells-icon "></td>
<td class="contentCells contentCells-icon "></td>
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift"">
<a href="editor?type=desktop&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms" /></a>
</td>
<% } else { %>
<td class="contentCells contentCells-shift contentCells-icon contentCellsEmpty" colspan="6"></td>
<% } %>