Skip to content

Commit

Permalink
Merge pull request #483 from ONLYOFFICE/feature/pdf-form
Browse files Browse the repository at this point in the history
Feature/pdf form
  • Loading branch information
LinneyS authored Jun 25, 2024
2 parents 5e6e817 + a706964 commit 59b80b0
Show file tree
Hide file tree
Showing 46 changed files with 90 additions and 79 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

##
## Changed
- creating pdf form

## 9.1.1
## Added
- support of user avatar in editor
Expand Down
1 change: 0 additions & 1 deletion appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ function () {
$detector->registerType("ott", "application/vnd.oasis.opendocument.text-template");
$detector->registerType("ots", "application/vnd.oasis.opendocument.spreadsheet-template");
$detector->registerType("otp", "application/vnd.oasis.opendocument.presentation-template");
$detector->registerType("docxf", "application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf");

$previewManager = $container->query(IPreview::class);
if ($this->appConfig->getPreview()) {
Expand Down
2 changes: 1 addition & 1 deletion assets/document-formats
2 changes: 1 addition & 1 deletion assets/document-templates
10 changes: 8 additions & 2 deletions controller/editorapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,15 @@ public function fillempty($fileId) {
* @param bool $desktop - desktop label
* @param bool $template - file is template
* @param string $anchor - anchor link
* @param bool $forceEdit - open editing
*
* @return JSONResponse
*
* @NoAdminRequired
* @PublicPage
* @CORS
*/
public function config($fileId, $filePath = null, $shareToken = null, $version = 0, $inframe = false, $desktop = false, $template = false, $anchor = null) {
public function config($fileId, $filePath = null, $shareToken = null, $version = 0, $inframe = false, $desktop = false, $template = false, $anchor = null, $forceEdit = false) {
$user = $this->userSession->getUser();
$userId = null;
$accountId = null;
Expand Down Expand Up @@ -380,7 +381,7 @@ public function config($fileId, $filePath = null, $shareToken = null, $version =
&& $file->isUpdateable()
&& !$isPersistentLock
&& (empty($shareToken) || ($share->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE);
$params["document"]["permissions"]["edit"] = $editable;
$params["document"]["permissions"]["edit"] = $editable && ($forceEdit || !$canFillForms);
if (($editable || $restrictedEditing) && $canEdit || $canFillForms) {
$ownerId = null;
$owner = $file->getOwner();
Expand All @@ -399,6 +400,11 @@ public function config($fileId, $filePath = null, $shareToken = null, $version =
$params["document"]["permissions"]["protect"] = false;
}

if ($canFillForms) {
$params["document"]["permissions"]["fillForms"] = true;
$params["canEdit"] = $canEdit && $editable;
}

$hashCallback = $this->crypt->getHash(["userId" => $userId, "ownerId" => $ownerId, "fileId" => $file->getId(), "filePath" => $filePath, "shareToken" => $shareToken, "action" => "track"]);
$callback = $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.track", ["doc" => $hashCallback]);

Expand Down
13 changes: 8 additions & 5 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function create($name, $dir, $templateId = null, $targetPath = null, $sha
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
$documentService = new DocumentService($this->trans, $this->config);
try {
$newFileUri = $documentService->getConvertedUri($fileUrl, $targetExt, $ext, $targetKey);
$newFileUri = $documentService->getConvertedUri($fileUrl, $targetExt, $ext, $targetKey, $ext === "pdf");
} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "getConvertedUri: " . $targetFile->getId(), "app" => $this->appName]);
return ["error" => $e->getMessage()];
Expand Down Expand Up @@ -1278,6 +1278,7 @@ public function download($fileId, $toExtension = null, $template = false) {
* @param string $shareToken - access token
* @param integer $version - file version
* @param bool $inframe - open in frame
* @param bool $forceEdit - open editing
* @param bool $template - file is template
* @param string $anchor - anchor for file content
*
Expand All @@ -1286,7 +1287,7 @@ public function download($fileId, $toExtension = null, $template = false) {
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index($fileId, $filePath = null, $shareToken = null, $version = 0, $inframe = false, $template = false, $anchor = null) {
public function index($fileId, $filePath = null, $shareToken = null, $version = 0, $inframe = false, $forceEdit = false, $template = false, $anchor = null) {
$this->logger->debug("Open: $fileId ($version) $filePath", ["app" => $this->appName]);

if (empty($shareToken) && !$this->userSession->isLoggedIn()) {
Expand Down Expand Up @@ -1326,7 +1327,8 @@ public function index($fileId, $filePath = null, $shareToken = null, $version =
"version" => $version,
"template" => $template,
"inframe" => false,
"anchor" => $anchor
"anchor" => $anchor,
"forceEdit" => $forceEdit
];

if ($inframe === true) {
Expand Down Expand Up @@ -1357,15 +1359,16 @@ public function index($fileId, $filePath = null, $shareToken = null, $version =
* @param string $shareToken - access token
* @param integer $version - file version
* @param bool $inframe - open in frame
* @param bool $forceEdit - open editing
*
* @return TemplateResponse
*
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
*/
public function publicPage($fileId, $shareToken, $version = 0, $inframe = false) {
return $this->index($fileId, null, $shareToken, $version, $inframe);
public function publicPage($fileId, $shareToken, $version = 0, $inframe = false, $forceEdit = false) {
return $this->index($fileId, null, $shareToken, $version, $inframe, $forceEdit);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
.icon-onlyoffice-new-pptx {
background-image: url("../img/new-pptx.svg");
}
.icon-onlyoffice-new-docxf {
background-image: url("../img/new-docxf.svg");
.icon-onlyoffice-new-pdf {
background-image: url("../img/new-pdf.svg");
}
.icon-onlyoffice-open,
.icon-onlyoffice-convert,
.icon-onlyoffice-download,
.icon-onlyoffice-fill,
.icon-onlyoffice-create {
background-image: url("../img/app-dark.svg");
}
Expand Down
16 changes: 8 additions & 8 deletions img/new-docxf.svg → img/new-pdf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
OCA.Onlyoffice.template = $("#iframeEditor").data("template");
OCA.Onlyoffice.inframe = !!$("#iframeEditor").data("inframe");
OCA.Onlyoffice.anchor = $("#iframeEditor").attr("data-anchor");
OCA.Onlyoffice.forceEdit = $("#iframeEditor").attr("data-forceEdit");
OCA.Onlyoffice.currentWindow = window;

if (OCA.Onlyoffice.inframe) {
Expand Down Expand Up @@ -84,6 +85,10 @@
params.push("anchor=" + encodeURIComponent(OCA.Onlyoffice.anchor));
}

if (OCA.Onlyoffice.forceEdit) {
params.push("forceEdit=true");
}

if (OCA.Onlyoffice.Desktop) {
params.push("desktop=true");
}
Expand Down Expand Up @@ -181,6 +186,12 @@
config.events.onRequestSharingSettings = OCA.Onlyoffice.onRequestSharingSettings;
}

if (!config.document.permissions.edit
&& config.document.permissions.fillForms
&& config.canEdit) {
config.events.onRequestEditRights = OCA.Onlyoffice.onRequestEditRights;
}

OCA.Onlyoffice.docEditor = new DocsAPI.DocEditor("iframeEditor", config);

if (config.type === "mobile" && $("#app > iframe").css("position") === "fixed"
Expand All @@ -203,6 +214,17 @@
});
};

OCA.Onlyoffice.onRequestEditRights = function () {
if (OCA.Onlyoffice.inframe) {
window.parent.postMessage({
method: "onRequestEditRights"
},
"*");
return;
}
location.href += "&forceEdit=true";
};

OCA.Onlyoffice.onRequestHistory = function (version) {
$.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/history?fileId={fileId}",
{
Expand Down
9 changes: 8 additions & 1 deletion js/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@

OCA.Onlyoffice.onShowMessage = function (messageObj) {
OC.Notification.show(messageObj.message, messageObj.props);
}
};

OCA.Onlyoffice.onRequestEditRights = function () {
$("#onlyofficeFrame").attr("src", $("#onlyofficeFrame").attr("src") + "&forceEdit=true");
};

window.addEventListener("message", function (event) {
if ($("#onlyofficeFrame")[0]) {
Expand Down Expand Up @@ -148,6 +152,9 @@
break;
case "onShowMessage":
OCA.Onlyoffice.onShowMessage(event.data.param);
break;
case "onRequestEditRights":
OCA.Onlyoffice.onRequestEditRights();
}
}, false);

Expand Down
38 changes: 17 additions & 21 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@

fileList.add(response, { animate: true });
if (open) {
OCA.Onlyoffice.OpenEditor(response.id, dir, response.name, 0, winEditor);
let fileName = response.name;
let extension = OCA.Onlyoffice.GetFileExtension(fileName);
let forceEdit = OCA.Onlyoffice.setting.formats[extension].fillForms;
OCA.Onlyoffice.OpenEditor(response.id, dir, fileName, winEditor, forceEdit);
}

OCA.Onlyoffice.context = { fileList: fileList };
Expand All @@ -82,7 +85,7 @@
);
};

OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, version, winEditor) {
OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, version, winEditor, forceEdit) {
var filePath = "";
if (fileName) {
filePath = fileDir.replace(new RegExp("\/$"), "") + "/" + fileName;
Expand All @@ -101,6 +104,10 @@
});
}

if (forceEdit) {
url += "&forceEdit=true";
}

if (version > 0) {
url += "&version=" + version;
}
Expand Down Expand Up @@ -357,17 +364,6 @@
});
}

if (config.fillForms) {
OCA.Files.fileActions.registerAction({
name: "onlyofficeFill",
displayName: t(OCA.Onlyoffice.AppName, "Fill in form in ONLYOFFICE"),
mime: mime,
permissions: OC.PERMISSION_UPDATE,
iconClass: "icon-onlyoffice-fill",
actionHandler: OCA.Onlyoffice.FileClick
});
}

if (config.createForm) {
OCA.Files.fileActions.registerAction({
name: "onlyofficeCreateForm",
Expand Down Expand Up @@ -450,25 +446,25 @@
});

menu.addMenuEntry({
id: "onlyofficeDocxf",
id: "onlyofficePdf",
displayName: t(OCA.Onlyoffice.AppName, "PDF form"),
templateName: t(OCA.Onlyoffice.AppName, "PDF form"),
iconClass: "icon-onlyoffice-new-docxf",
fileType: "docxf",
iconClass: "icon-onlyoffice-new-pdf",
fileType: "pdf",
actionHandler: function (name) {
OCA.Onlyoffice.CreateFile(name + ".docxf", fileList);
OCA.Onlyoffice.CreateFile(name + ".pdf", fileList);
}
});

if (!$("#isPublic").val()) {
menu.addMenuEntry({
id: "onlyofficeDocxfExist",
id: "onlyofficePdfExist",
displayName: t(OCA.Onlyoffice.AppName, "PDF form from existing text file"),
templateName: t(OCA.Onlyoffice.AppName, "PDF form from existing text file"),
iconClass: "icon-onlyoffice-new-docxf",
fileType: "docxf",
iconClass: "icon-onlyoffice-new-pdf",
fileType: "pdf",
actionHandler: function (name) {
OCA.Onlyoffice.OpenFormPicker(name + ".docxf", fileList);
OCA.Onlyoffice.OpenFormPicker(name + ".pdf", fileList);
}
});
}
Expand Down
1 change: 0 additions & 1 deletion l10n/bg_BG.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ OC.L10N.register(
"PDF form": "PDF формуляр",
"PDF form from existing text file": "PDF формуляр от съществуващ текстов файл",
"Create form": "Създайте формуляр",
"Fill in form in ONLYOFFICE": "Попълнете формуляр в ONLYOFFICE",
"Create new PDF form": "Създайте нов PDF формуляр",
"Security": "Сигурност",
"Run document macros": "Изпълнение на макроси на документи",
Expand Down
1 change: 0 additions & 1 deletion l10n/bg_BG.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"PDF form": "PDF формуляр",
"PDF form from existing text file": "Избери файл за комбиниране",
"Create form": "Създайте формуляр",
"Fill in form in ONLYOFFICE": "Попълнете формуляр в ONLYOFFICE",
"Create new PDF form": "Създайте нов PDF формуляр",
"Security": "Сигурност",
"Light": "Светла",
Expand Down
1 change: 0 additions & 1 deletion l10n/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ OC.L10N.register(
"%1\$s mentioned in the %2\$s: \"%3\$s\".": "%1\$s ha esmentat en %2\$s: \"%3\$s\".",
"Choose a format to convert {fileName}": "Triï un format per a convertir {fileName}",
"Create form": "Crear formulari",
"Fill in form in ONLYOFFICE": "Omplir el formulari en ONLYOFFICE",
"Security": "Seguretat",
"Light": "Llum",
"Classic Light": "Llum clàssica",
Expand Down
1 change: 0 additions & 1 deletion l10n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"%1$s mentioned in the %2$s: \"%3$s\".": "%1$s ha esmentat en %2$s: \"%3$s\".",
"Choose a format to convert {fileName}": "Triï un format per a convertir {fileName}",
"Create form": "Crear formulari",
"Fill in form in ONLYOFFICE": "Omplir el formulari en ONLYOFFICE",
"Security": "Seguretat",
"Light": "Llum",
"Classic Light": "Llum clàssica",
Expand Down
1 change: 0 additions & 1 deletion l10n/da.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ OC.L10N.register(
"%1\$s mentioned in the %2\$s: \"%3\$s\".": "%1\$s nævnt i %2\$s: \"%3\$s\".",
"Choose a format to convert {fileName}": "Vælg et format til at konvertere {fileName}",
"Create form": "Opret formular",
"Fill in form in ONLYOFFICE": "Udfyld formularen i ONLYOFFICE",
"Security": "Sikkerhed",
"Run document macros": "Kør dokumentmakroer",
"Default editor theme": "Standard editortema",
Expand Down
1 change: 0 additions & 1 deletion l10n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"%1$s mentioned in the %2$s: \"%3$s\".": "%1$s nævnt i %2$s: \"%3$s\".",
"Choose a format to convert {fileName}": "Vælg et format til at konvertere {fileName}",
"Create form": "Opret formular",
"Fill in form in ONLYOFFICE": "Udfyld formularen i ONLYOFFICE",
"Security": "Sikkerhed",
"Run document macros": "Kør dokumentmakroer",
"Default editor theme": "Standard editortema",
Expand Down
1 change: 0 additions & 1 deletion l10n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ OC.L10N.register(
"PDF form": "PDF-Formular",
"PDF form from existing text file": "PDF-Formular aus vorhandener Textdatei",
"Create form": "Formular erstellen",
"Fill in form in ONLYOFFICE": "Formular in ONLYOFFICE ausfüllen",
"Create new PDF form": "Neues PDF-Formular erstellen",
"Security": "Sicherheit",
"Run document macros": "Makros im Dokument ausführen",
Expand Down
1 change: 0 additions & 1 deletion l10n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"PDF form": "PDF-Formular",
"PDF form from existing text file": "PDF-Formular aus vorhandener Textdatei",
"Create form": "Formular erstellen",
"Fill in form in ONLYOFFICE": "Formular in ONLYOFFICE ausfüllen",
"Create new PDF form": "Neues PDF-Formular erstellen",
"Security": "Sicherheit",
"Run document macros": "Makros im Dokument ausführen",
Expand Down
1 change: 0 additions & 1 deletion l10n/de_DE.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ OC.L10N.register(
"PDF form": "PDF-Formular",
"PDF form from existing text file": "PDF-Formular aus vorhandener Textdatei",
"Create form": "Formular erstellen",
"Fill in form in ONLYOFFICE": "Formular in ONLYOFFICE ausfüllen",
"Create new PDF form": "Neues PDF-Formular erstellen",
"Security": "Sicherheit",
"Run document macros": "Makros im Dokument ausführen",
Expand Down
1 change: 0 additions & 1 deletion l10n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"PDF form": "PDF-Formular",
"PDF form from existing text file": "PDF-Formular aus vorhandener Textdatei",
"Create form": "Formular erstellen",
"Fill in form in ONLYOFFICE": "Formular in ONLYOFFICE ausfüllen",
"Create new PDF form": "Neues PDF-Formular erstellen",
"Security": "Sicherheit",
"Run document macros": "Makros im Dokument ausführen",
Expand Down
1 change: 0 additions & 1 deletion l10n/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ OC.L10N.register(
"PDF form": "Formulario PDF",
"PDF form from existing text file": "Formulario PDF a partir de un archivo de texto existente",
"Create form": "Crear formulario",
"Fill in form in ONLYOFFICE": "Rellenar el formulario en ONLYOFFICE",
"Create new PDF form": "Crear nuevo formulario PDF",
"Security": "Seguridad",
"Run document macros": "Ejecutar macros de documentos",
Expand Down
Loading

0 comments on commit 59b80b0

Please sign in to comment.