Skip to content

Commit

Permalink
Merge pull request #2882 from ONLYOFFICE/feature/pdf-form
Browse files Browse the repository at this point in the history
Feature/pdf form
  • Loading branch information
JuliaRadzhabova authored Mar 15, 2024
2 parents a23b58a + 5cb8302 commit 70cd4ba
Show file tree
Hide file tree
Showing 41 changed files with 551 additions and 155 deletions.
76 changes: 46 additions & 30 deletions apps/api/documents/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@
}
}

var type = /^(?:(pdf|djvu|xps|oxps))$/.exec(_config.document.fileType);
var type = /^(?:(djvu|xps|oxps))$/.exec(_config.document.fileType);
if (type && typeof type[1] === 'string') {
_config.editorConfig.canUseHistory = false;
}
Expand Down Expand Up @@ -960,46 +960,53 @@
'word': 'documenteditor',
'cell': 'spreadsheeteditor',
'slide': 'presentationeditor',
'pdf': 'pdfeditor'
'pdf': 'pdfeditor',
'common': 'common'
},
appType = 'word';

if (typeof config.documentType === 'string') {
appType = config.documentType.toLowerCase();
if (config.type !== 'mobile' && config.type !== 'embedded' && !!config.document && typeof config.document.fileType === 'string') {
var type = /^(?:(pdf|djvu|xps|oxps))$/.exec(config.document.fileType);
if (type && typeof type[1] === 'string')
appType = 'pdf';
}
} else
if (!!config.document && typeof config.document.fileType === 'string') {
var type = /^(?:(xls|xlsx|ods|csv|xlst|xlsy|gsheet|xlsm|xlt|xltm|xltx|fods|ots|xlsb)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides|pot|potm|potx|ppsm|pptm|fodp|otp)|(pdf|djvu|xps|oxps))$/
.exec(config.document.fileType);
if (type) {
if (typeof type[1] === 'string') appType = 'cell'; else
if (typeof type[2] === 'string') appType = 'slide'; else
if (typeof type[3] === 'string' && config.type !== 'mobile' && config.type !== 'embedded') appType = 'pdf';
}
appType = 'word',
type,
fillForms = false,
isForm = false;
if (config.document) {
if (typeof config.document.fileType === 'string')
type = /^(?:(pdf)|(djvu|xps|oxps)|(xls|xlsx|ods|csv|xlst|xlsy|gsheet|xlsm|xlt|xltm|xltx|fods|ots|xlsb)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides|pot|potm|potx|ppsm|pptm|fodp|otp))$/
.exec(config.document.fileType);

if (config.document.permissions)
fillForms = (config.document.permissions.fillForms===undefined ? config.document.permissions.edit !== false : config.document.permissions.fillForms) &&
config.editorConfig && (config.editorConfig.mode !== 'view');
}
if (appType === 'pdf' && (config.type === 'mobile' || config.type === 'embedded')) {
appType = 'word';
if (type && typeof type[2] === 'string') { // djvu|xps|oxps
appType = config.type === 'mobile' || config.type === 'embedded' ? 'word' : 'pdf';
} else if (type && typeof type[1] === 'string') { // pdf - need check
isForm = config.document ? config.document.isForm : undefined;
if (config.type === 'embedded')
appType = fillForms && isForm===undefined ? 'common' : 'word';
else if (config.type !== 'mobile')
appType = isForm===undefined ? 'common' : isForm ? 'word' : 'pdf';
} else {
if (typeof config.documentType === 'string')
appType = config.documentType.toLowerCase();
else {
if (type && typeof type[3] === 'string') appType = 'cell'; else
if (type && typeof type[4] === 'string') appType = 'slide';
}
}
path += appMap[appType];

path += appMap[appType] + "/";
const path_type = config.type === "mobile"
? "mobile" : (config.type === "embedded")
? "embed" : "main";
const path_type = config.type === "mobile" ? "mobile" :
config.type === "embedded" ? (fillForms && isForm ? "forms" : "embed") : "main";
if (appType !== 'common')
path += "/" + path_type;

path += path_type;
var index = "/index.html";
if (config.editorConfig && path_type!=="forms") {
if (config.editorConfig && path_type!=="forms" && appType!=='common') {
var customization = config.editorConfig.customization;
if ( typeof(customization) == 'object' && ( customization.toolbarNoTabs ||
(config.editorConfig.targetApp!=='desktop') && (customization.loaderName || customization.loaderLogo))) {
(config.editorConfig.targetApp!=='desktop') && (customization.loaderName || customization.loaderLogo))) {
index = "/index_loader.html";
} else if (config.editorConfig.mode === 'editdiagram' || config.editorConfig.mode === 'editmerge' || config.editorConfig.mode === 'editole')
index = "/index_internal.html";

}
path += index;
return path;
Expand Down Expand Up @@ -1036,6 +1043,9 @@
if (config.editorConfig && (config.editorConfig.mode == 'editdiagram' || config.editorConfig.mode == 'editmerge' || config.editorConfig.mode == 'editole'))
params += "&internal=true";

if (config.type)
params += "&type=" + config.type;

if (config.frameEditorId)
params += "&frameEditorId=" + config.frameEditorId;

Expand Down Expand Up @@ -1064,6 +1074,12 @@
if (config.document && config.document.fileType)
params += "&fileType=" + config.document.fileType;

if (config.editorConfig) {
var customization = config.editorConfig.customization;
if ( customization && typeof(customization) == 'object' && ( customization.toolbarNoTabs || (config.editorConfig.targetApp!=='desktop') && (customization.loaderName || customization.loaderLogo))) {
params += "&indexPostfix=_loader";
}
}
return params;
}

Expand Down
62 changes: 62 additions & 0 deletions apps/common/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>ONLYOFFICE Documents</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">

<style type="text/css">
.loadmask {
left: 0;
top: 0;
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
border: none;
background: #e2e2e2;
background: var(--canvas-background, #e2e2e2);
z-index: 1002;
}

.theme-dark .loadmask, .theme-type-dark .loadmask {
background: #555;
}
</style>
<script>
function getUrlParams() {
var e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1),
urlParams = {};

while (e = r.exec(q))
urlParams[d(e[1])] = d(e[2]);

return urlParams;
}

var params = getUrlParams(),
postfix = params["indexPostfix"] || '',
embed = params["type"]==='embedded';
window.frameEditorId = params["frameEditorId"];
window.parentOrigin = params["parentOrigin"];
</script>
<script src="main/lib/util/themeinit.js"></script>
</head>
<body>
<script src="main/lib/util/htmlutils.js"></script>
<script type="text/javascript" src="checkExtendedPDF.js"></script>
<div id="loading-mask" class="loadmask"></div>
<script>
listenApiMsg(function (isform) {
var match = window.location.href.match(/(.*)common\/index.html/i);
match && window.location.replace(match[1] + (isform || embed ? 'documenteditor' : 'pdfeditor') + '/' + (isform && embed ? 'forms' : embed ? 'embed' : 'main') + '/index' + postfix + '.html' +
window.location.search + ("&isForm=" + !!isform));
});
</script>
</body>
</html>
62 changes: 62 additions & 0 deletions apps/common/index.html.deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>ONLYOFFICE Documents</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">

<style type="text/css">
.loadmask {
left: 0;
top: 0;
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
border: none;
background: #e2e2e2;
background: var(--canvas-background, #e2e2e2);
z-index: 1002;
}

.theme-dark .loadmask, .theme-type-dark .loadmask {
background: #555;
}
</style>
<script>
function getUrlParams() {
var e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1),
urlParams = {};

while (e = r.exec(q))
urlParams[d(e[1])] = d(e[2]);

return urlParams;
}

var params = getUrlParams(),
postfix = params["indexPostfix"] || '',
embed = params["type"]==='embedded';
window.frameEditorId = params["frameEditorId"];
window.parentOrigin = params["parentOrigin"];
</script>
<script src="../../../../apps/common/main/lib/util/themeinit.js?__inline=true"></script>
</head>
<body>
<script src="../../../../apps/common/main/lib/util/htmlutils.js?__inline=true"></script>
<script src="../../../../apps/common/checkExtendedPDF.js?__inline=true"></script>
<div id="loading-mask" class="loadmask"></div>
<script>
listenApiMsg(function (isform) {
var match = window.location.href.match(/(.*)common\/index.html/i);
match && window.location.replace(match[1] + (isform || embed ? 'documenteditor' : 'pdfeditor') + '/' + (isform && embed ? 'forms' : embed ? 'embed' : 'main') + '/index' + postfix + '.html' +
window.location.search + ("&isForm=" + !!isform));
});
</script>
</body>
</html>
40 changes: 20 additions & 20 deletions apps/common/main/lib/view/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ define([
} else {
$panelUsers['hide']();
}
updateDocNamePosition(appConfig);
updateDocNamePosition();
}

function onLostEditRights() {
_readonlyRights = true;
this.btnShare && this.btnShare.setVisible(false);
updateDocNamePosition(appConfig);
updateDocNamePosition();
}

function onUsersClick(e) {
Expand All @@ -223,14 +223,15 @@ define([
}

function updateDocNamePosition(config) {
config = config || appConfig;
if ( $labelDocName && config) {
var $parent = $labelDocName.parent();
if (!(config.isEdit || isPDFEditor && config.isRestrictedEdit)) {
if (!config.twoLevelHeader) {
var _left_width = $parent.position().left,
_right_width = $parent.next().outerWidth();
$parent.css('padding-left', _left_width < _right_width ? Math.max(2, _right_width - _left_width) : 2);
$parent.css('padding-right', _left_width < _right_width ? 2 : Math.max(2, _left_width - _right_width));
} else if (!(config.customization && config.customization.compactHeader)) {
} else if (!config.compactHeader) {
var _left_width = $parent.position().left,
_right_width = $parent.next().outerWidth(),
outerWidth = $labelDocName.outerWidth(),
Expand All @@ -245,7 +246,7 @@ define([
}
}

if (!(config.customization && config.customization.toolbarHideFileName) && (!(config.isEdit || isPDFEditor && config.isRestrictedEdit) || config.customization && config.customization.compactHeader)) {
if (!(config.customization && config.customization.toolbarHideFileName) && (!config.twoLevelHeader || config.compactHeader)) {
var basis = parseFloat($parent.css('padding-left') || 0) + parseFloat($parent.css('padding-right') || 0) + parseInt($labelDocName.css('min-width') || 50); // 2px - box-shadow
config.isCrypted && (basis += 20);
$parent.css('flex-basis', Math.ceil(basis) + 'px');
Expand Down Expand Up @@ -285,9 +286,8 @@ define([
}

function onResize() {
if (appConfig && (appConfig.isEdit || isPDFEditor && appConfig.isRestrictedEdit) && !(appConfig.customization && appConfig.customization.compactHeader)) {
updateDocNamePosition(appConfig);
}
if (appConfig && appConfig.twoLevelHeader && !appConfig.compactHeader)
updateDocNamePosition();
}

function onAppShowed(config) {
Expand Down Expand Up @@ -336,7 +336,7 @@ define([
});
me.btnShare.updateHint(me.tipAccessRights);
me.btnShare.setVisible(!_readonlyRights && appConfig && (appConfig.sharingSettingsUrl && appConfig.sharingSettingsUrl.length || appConfig.canRequestSharingSettings));
updateDocNamePosition(appConfig);
updateDocNamePosition();
}

if ( me.logo )
Expand Down Expand Up @@ -367,7 +367,7 @@ define([
});
$btnUsers.on('click', onUsersClick.bind(me));
$panelUsers[(appConfig && (editingUsers > 1 && (appConfig.isEdit || appConfig.isRestrictedEdit) || editingUsers > 0 && appConfig.canLiveView)) ? 'show' : 'hide']();
updateDocNamePosition(appConfig);
updateDocNamePosition();
}

if (appConfig.user.guest && appConfig.canRenameAnonymous) {
Expand Down Expand Up @@ -413,7 +413,7 @@ define([
});
}

if ( !(mode.isEdit || isPDFEditor && mode.isRestrictedEdit) ) {
if ( !appConfig.twoLevelHeader ) {
if ( me.btnDownload ) {
me.btnDownload.updateHint(me.tipDownload);
me.btnDownload.on('click', function (e) {
Expand Down Expand Up @@ -505,7 +505,7 @@ define([
Common.NotificationCenter.trigger('doc:mode-apply', item.value, true);
});
}
if ((appConfig.isEdit || isPDFEditor && appConfig.isRestrictedEdit) && !(appConfig.customization && appConfig.customization.compactHeader))
if (appConfig.twoLevelHeader && !appConfig.compactHeader)
Common.NotificationCenter.on('window:resize', onResize);
}

Expand Down Expand Up @@ -629,7 +629,7 @@ define([
Common.NotificationCenter.on({
'app:ready': function(mode) {Common.Utils.asyncCall(onAppReady, me, mode);},
'app:face': function(mode) {Common.Utils.asyncCall(onAppShowed, me, mode);},
'tab:visible': function() {Common.Utils.asyncCall(updateDocNamePosition, me, appConfig);},
'tab:visible': function() {Common.Utils.asyncCall(updateDocNamePosition, me);},
'collaboration:sharingdeny': function(mode) {Common.Utils.asyncCall(onLostEditRights, me, mode);}
});
Common.NotificationCenter.on('uitheme:changed', this.changeLogo.bind(this));
Expand Down Expand Up @@ -706,7 +706,7 @@ define([
$html.find('#slot-btn-favorite').hide();
}

if ( !(config.isEdit || isPDFEditor && config.isRestrictedEdit)) {
if ( !config.twoLevelHeader) {
if ( (config.canDownload || config.canDownloadOrigin) && !config.isOffline )
this.btnDownload = createTitleButton('toolbar__icon icon--inverse btn-download', $html.findById('#slot-hbtn-download'), undefined, 'bottom', 'big');

Expand All @@ -721,7 +721,7 @@ define([
}
me.btnSearch.render($html.find('#slot-btn-search'));

if (!(config.isEdit || isPDFEditor && config.isRestrictedEdit) || config.customization && !!config.customization.compactHeader) {
if (!config.twoLevelHeader || config.compactHeader) {
if (config.user.guest && config.canRenameAnonymous) {
me.btnUserName = new Common.UI.Button({
el: $html.findById('.slot-btn-user-name'),
Expand Down Expand Up @@ -823,13 +823,13 @@ define([
if ( config.canCloseEditor )
me.btnClose = createTitleButton('toolbar__icon icon--inverse btn-close', $html.findById('#slot-btn-close'), false, 'left', '10, 10');

if ( config.canPrint && (config.isEdit || isPDFEditor && config.isRestrictedEdit) ) {
if ( config.canPrint && config.twoLevelHeader ) {
me.btnPrint = createTitleButton('toolbar__icon icon--inverse btn-print', $html.findById('#slot-btn-dt-print'), true, undefined, undefined, 'P');
}
if ( config.canQuickPrint && (config.isEdit || isPDFEditor && config.isRestrictedEdit) )
if ( config.canQuickPrint && config.twoLevelHeader )
me.btnPrintQuick = createTitleButton('toolbar__icon icon--inverse btn-quick-print', $html.findById('#slot-btn-dt-print-quick'), true, undefined, undefined, 'Q');

if (!isPDFEditor || !config.isForm)
if (!isPDFEditor && !(config.isPDFForm && config.canFillForms && config.isRestrictedEdit) || isPDFEditor && !config.isForm)
me.btnSave = createTitleButton('toolbar__icon icon--inverse btn-save', $html.findById('#slot-btn-dt-save'), true, undefined, undefined, 'S');
me.btnUndo = createTitleButton('toolbar__icon icon--inverse btn-undo', $html.findById('#slot-btn-dt-undo'), true, undefined, undefined, 'Z',
[Common.enumLock.undoLock, Common.enumLock.fileMenuOpened]);
Expand Down Expand Up @@ -901,7 +901,7 @@ define([
this.btnGoBack[value ? 'show' : 'hide']();
if (value)
this.btnGoBack.updateHint((text && typeof text == 'string') ? text : this.textBack);
updateDocNamePosition(appConfig);
updateDocNamePosition();
return this;
},

Expand All @@ -914,7 +914,7 @@ define([
this.btnFavorite[value!==undefined && value!==null ? 'show' : 'hide']();
this.btnFavorite.changeIcon(!!value ? {next: 'btn-in-favorite', curr: 'btn-favorite'} : {next: 'btn-favorite', curr: 'btn-in-favorite'});
this.btnFavorite.updateHint(!value ? this.textAddFavorite : this.textRemoveFavorite);
updateDocNamePosition(appConfig);
updateDocNamePosition();
return this;
},

Expand Down
Loading

0 comments on commit 70cd4ba

Please sign in to comment.