Skip to content

Commit

Permalink
Merge pull request #2931 from ONLYOFFICE/feature/pdf-form
Browse files Browse the repository at this point in the history
Feature/pdf form
  • Loading branch information
JuliaRadzhabova authored Apr 11, 2024
2 parents a27b742 + 3bac4c8 commit 6778ceb
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apps/api/documents/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@
if (!(type && typeof type[1] === 'string') && (config.editorConfig && config.editorConfig.mode == 'view' ||
config.document && config.document.permissions && (config.document.permissions.edit === false && !config.document.permissions.review )))
params += "&mode=view";
if (type && typeof type[1] === 'string' && config.document && config.document.permissions && config.document.permissions.edit === false)
if (type && typeof type[1] === 'string' && (config.document && config.document.permissions && config.document.permissions.edit === false || config.editorConfig && config.editorConfig.mode == 'view'))
params += "&mode=fillforms";

if (config.document) {
Expand Down
2 changes: 1 addition & 1 deletion apps/common/main/lib/view/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ define([
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.isPDFForm && config.canFillForms && config.isRestrictedEdit) || isPDFEditor && !config.isForm)
if (config.showSaveButton)
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
2 changes: 1 addition & 1 deletion apps/documenteditor/main/app/controller/LeftMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ define([
switch (action) {
case 'back':
break;
case 'save': this.api.asc_Save(); break;
case 'save': Common.NotificationCenter.trigger('leftmenu:save'); break;
case 'save-desktop': this.api.asc_DownloadAs(); break;
case 'saveas':
if ( isopts ) close_menu = false;
Expand Down
20 changes: 14 additions & 6 deletions apps/documenteditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,9 @@ define([

if (this.api && this.appOptions.isEdit && !toolbarView._state.previewmode) {
var cansave = this.api.asc_isDocumentCanSave(),
forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary,
forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary || !this.appOptions.canSaveToFile,
isSyncButton = (toolbarView.btnCollabChanges.rendered) ? toolbarView.btnCollabChanges.cmpEl.hasClass('notify') : false,
isDisabled = !cansave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave;
isDisabled = !cansave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave || !this.appOptions.showSaveButton;
toolbarView.btnSave.setDisabled(isDisabled);
}

Expand Down Expand Up @@ -1657,6 +1657,13 @@ define([
this.appOptions.canHelp = !((typeof (this.editorConfig.customization) == 'object') && this.editorConfig.customization.help===false);
this.appOptions.canFillForms = this.appOptions.canLicense && (this.appOptions.isEdit ? true : this.permissions.fillForms) && (this.editorConfig.mode !== 'view');
this.appOptions.isRestrictedEdit = !this.appOptions.isEdit && (this.appOptions.canComments || this.appOptions.canFillForms);
this.appOptions.canSaveToFile = this.appOptions.isEdit || this.appOptions.isRestrictedEdit;
this.appOptions.showSaveButton = this.appOptions.isEdit || !this.appOptions.isRestrictedEdit && this.appOptions.isPDFForm; // save to file or save to file copy (for pdf-form viewer)

if (this.appOptions.isPDFForm && !this.appOptions.isEdit) {
this.appOptions.canFillForms = this.appOptions.isRestrictedEdit = true; // can fill forms in viewer!
}

if (this.appOptions.isRestrictedEdit && this.appOptions.canComments && this.appOptions.canFillForms) // must be one restricted mode, priority for filling forms
this.appOptions.canComments = false;
this.appOptions.canSwitchMode = this.appOptions.isEdit;
Expand Down Expand Up @@ -1734,6 +1741,7 @@ define([
}

this.api.asc_setViewMode(!this.appOptions.isEdit && !this.appOptions.isRestrictedEdit);
this.api.asc_setCanSendChanges(this.appOptions.canSaveToFile);
this.appOptions.isRestrictedEdit && this.appOptions.canComments && this.api.asc_setRestriction(Asc.c_oAscRestrictionType.OnlyComments);
this.appOptions.isRestrictedEdit && this.appOptions.canFillForms && this.api.asc_setRestriction(Asc.c_oAscRestrictionType.OnlyForms);
this.api.asc_LoadDocument();
Expand Down Expand Up @@ -2348,8 +2356,8 @@ define([
var toolbarView = this.getApplication().getController('Toolbar').getView();
if (toolbarView && toolbarView.btnCollabChanges && !toolbarView._state.previewmode) {
var isSyncButton = toolbarView.btnCollabChanges.cmpEl.hasClass('notify'),
forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary,
isDisabled = !isModified && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave;
forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary || !this.appOptions.canSaveToFile,
isDisabled = !isModified && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave || !this.appOptions.showSaveButton;
toolbarView.btnSave.setDisabled(isDisabled);
}

Expand All @@ -2365,8 +2373,8 @@ define([

if (toolbarView && this.api && !toolbarView._state.previewmode) {
var isSyncButton = toolbarView.btnCollabChanges.cmpEl.hasClass('notify'),
forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary,
isDisabled = !isCanSave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave;
forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary || !this.appOptions.canSaveToFile,
isDisabled = !isCanSave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave || !this.appOptions.showSaveButton;
toolbarView.btnSave.setDisabled(isDisabled);
}
},
Expand Down
52 changes: 41 additions & 11 deletions apps/documenteditor/main/app/controller/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ define([
_main.onPrintQuick();
},
'save': function (opts) {
this.api.asc_Save();
this.tryToSave();
},
'undo': this.onUndo,
'redo': this.onRedo,
Expand Down Expand Up @@ -275,7 +275,7 @@ define([
attachRestrictedEditFormsUIEvents: function(toolbar) {
toolbar.btnPrint.on('click', _.bind(this.onPrint, this));
toolbar.btnPrint.on('disabled', _.bind(this.onBtnChangeState, this, 'print:disabled'));
toolbar.btnSave.on('click', _.bind(this.onSave, this));
toolbar.btnSave.on('click', _.bind(this.tryToSave, this));
toolbar.btnUndo.on('click', _.bind(this.onUndo, this));
toolbar.btnUndo.on('disabled', _.bind(this.onBtnChangeState, this, 'undo:disabled'));
toolbar.btnRedo.on('click', _.bind(this.onRedo, this));
Expand All @@ -286,7 +286,7 @@ define([
toolbar.btnSelectAll.on('click', _.bind(this.onSelectAll, this));
toolbar.btnSelectTool.on('toggle', _.bind(this.onSelectTool, this, 'select'));
toolbar.btnHandTool.on('toggle', _.bind(this.onSelectTool, this, 'hand'));

Common.NotificationCenter.on('leftmenu:save', _.bind(this.tryToSave, this));
this.onBtnChangeState('undo:disabled', toolbar.btnUndo, toolbar.btnUndo.isDisabled());
this.onBtnChangeState('redo:disabled', toolbar.btnRedo, toolbar.btnRedo.isDisabled());
},
Expand All @@ -298,7 +298,7 @@ define([

toolbar.btnPrint.on('click', _.bind(this.onPrint, this));
toolbar.btnPrint.on('disabled', _.bind(this.onBtnChangeState, this, 'print:disabled'));
toolbar.btnSave.on('click', _.bind(this.onSave, this));
toolbar.btnSave.on('click', _.bind(this.tryToSave, this));
toolbar.btnUndo.on('click', _.bind(this.onUndo, this));
toolbar.btnUndo.on('disabled', _.bind(this.onBtnChangeState, this, 'undo:disabled'));
toolbar.btnRedo.on('click', _.bind(this.onRedo, this));
Expand Down Expand Up @@ -416,7 +416,7 @@ define([
$('#id-toolbar-menu-new-control-color').on('click', _.bind(this.onNewControlsColor, this));
toolbar.listStylesAdditionalMenuItem.on('click', this.onMenuSaveStyle.bind(this));
toolbar.btnPrint.menu && toolbar.btnPrint.menu.on('item:click', _.bind(this.onPrintMenu, this));

Common.NotificationCenter.on('leftmenu:save', _.bind(this.tryToSave, this));
this.onSetupCopyStyleButton();
this.onBtnChangeState('undo:disabled', toolbar.btnUndo, toolbar.btnUndo.isDisabled());
this.onBtnChangeState('redo:disabled', toolbar.btnRedo, toolbar.btnRedo.isDisabled());
Expand Down Expand Up @@ -1095,18 +1095,44 @@ define([
this.onPrint(e);
},

onSave: function(e) {
var toolbar = this.toolbar;
if (this.api) {
tryToSave: function(e) {
var toolbar = this.toolbar,
mode = toolbar.mode,
me = this;
if (!mode.canSaveToFile) {
var canDownload = mode.canDownload && (!mode.isDesktopApp || !mode.isOffline),
saveSopy = (mode.canDownload && (!mode.isDesktopApp || !mode.isOffline)) && (mode.canRequestSaveAs || mode.saveAsUrl),
saveAs = mode.canDownload && mode.isDesktopApp && mode.isOffline,
buttons = (saveSopy || saveAs ? [{value: 'copy', caption: this.txtSaveCopy}] : []).concat(canDownload ? [{value: 'download', caption: this.txtDownload}] : []),
primary = saveSopy || saveAs ? 'copy' : (canDownload ? 'download' : 'ok');

Common.UI.info({
maxwidth: 500,
buttons: !mode.canDownload ? ['ok'] : buttons.concat(['cancel']),
primary: !mode.canDownload ? 'ok' : primary,
msg: mode.canDownload ? this.txtNeedDownload : this.errorAccessDeny,
callback: function(btn) {
if (saveAs && btn==='copy')
me.api.asc_DownloadAs();
else if (btn==='copy' || btn==='download') {
me.isFromFormSaveAs = (btn==='copy');
var options = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.PDF, me.isFromFormSaveAs);
options.asc_setIsSaveAs(me.isFromFormSaveAs);
me.api.asc_DownloadAs(options);
}
Common.NotificationCenter.trigger('edit:complete', toolbar);
}
});
} else if (this.api) {
var isModified = this.api.asc_isDocumentCanSave();
var isSyncButton = toolbar.btnCollabChanges && toolbar.btnCollabChanges.cmpEl.hasClass('notify');
if (!isModified && !isSyncButton && !toolbar.mode.forcesave && !toolbar.mode.canSaveDocumentToBinary)
if (!isModified && !isSyncButton && !mode.forcesave && !mode.canSaveDocumentToBinary)
return;

this.api.asc_Save();
}

toolbar.btnSave.setDisabled(!toolbar.mode.forcesave && !toolbar.mode.canSaveDocumentToBinary);
toolbar.btnSave.setDisabled(!mode.forcesave && !mode.canSaveDocumentToBinary && mode.canSaveToFile || !mode.showSaveButton);

Common.NotificationCenter.trigger('edit:complete', toolbar);

Expand Down Expand Up @@ -4135,7 +4161,11 @@ define([
textConvertFormDownload: 'Download file as a fillable PDF form to be able to fill it out.',
txtUntitled: 'Untitled',
textSavePdf: 'Save as pdf',
textDownloadPdf: 'Download pdf'
textDownloadPdf: 'Download pdf',
txtNeedDownload: 'PDF viewer can only save new changes in separate file copies. It doesn\'t support co-editing and other users won\'t see your changes unless you share a new file version.',
txtDownload: 'Download',
txtSaveCopy: 'Save copy',
errorAccessDeny: 'You are trying to perform an action you do not have rights for.<br>Please contact your Document Server administrator.',

}, DE.Controllers.Toolbar || {}));
});
2 changes: 1 addition & 1 deletion apps/documenteditor/main/app/view/FileMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ define([
var isBCSupport = Common.Controllers.Desktop.isActive() ? Common.Controllers.Desktop.call("isBlockchainSupport") : false;
this.miSaveCopyAs[((this.mode.canDownload || this.mode.canDownloadOrigin) && (!this.mode.isDesktopApp || !this.mode.isOffline)) && (this.mode.canRequestSaveAs || this.mode.saveAsUrl) && !isBCSupport ?'show':'hide']();
this.miSaveAs[((this.mode.canDownload || this.mode.canDownloadOrigin) && this.mode.isDesktopApp && this.mode.isOffline)?'show':'hide']();
this.miSave[this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') ?'show':'hide']();
this.miSave[this.mode.showSaveButton && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') ?'show':'hide']();
this.miEdit[!this.mode.isEdit && this.mode.canEdit && this.mode.canRequestEditRights ?'show':'hide']();
this.miPrint[this.mode.canPrint && !this.mode.canPreviewPrint ?'show':'hide']();
this.miPrintWithPreview[this.mode.canPreviewPrint?'show':'hide']();
Expand Down
2 changes: 1 addition & 1 deletion apps/documenteditor/main/app/view/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3119,7 +3119,7 @@ define([
this.synchTooltip.hide();
this.btnCollabChanges.updateHint(this.btnSaveTip);

this.btnSave.setDisabled(!me.mode.forcesave && !me.mode.canSaveDocumentToBinary);
this.btnSave.setDisabled(!me.mode.forcesave && !me.mode.canSaveDocumentToBinary && me.mode.canSaveToFile || !me.mode.showSaveButton);
this._state.hasCollaborativeChanges = false;
}
}
Expand Down
4 changes: 4 additions & 0 deletions apps/documenteditor/main/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,10 @@
"DE.Controllers.Toolbar.txtSymbol_xsi": "Xi",
"DE.Controllers.Toolbar.txtSymbol_zeta": "Zeta",
"DE.Controllers.Toolbar.txtUntitled": "Untitled",
"DE.Controllers.Toolbar.txtNeedDownload": "PDF viewer can only save new changes in separate file copies. It doesn't support co-editing and other users won't see your changes unless you share a new file version.",
"DE.Controllers.Toolbar.txtDownload": "Download",
"DE.Controllers.Toolbar.txtSaveCopy": "Save copy",
"DE.Controllers.Toolbar.errorAccessDeny": "You are trying to perform an action you do not have rights for.<br>Please contact your Document Server administrator.",
"DE.Controllers.Viewport.textFitPage": "Fit to Page",
"DE.Controllers.Viewport.textFitWidth": "Fit to Width",
"DE.Controllers.Viewport.txtDarkMode": "Dark mode",
Expand Down
3 changes: 3 additions & 0 deletions apps/pdfeditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,8 @@ define([
this.appOptions.canFillForms = this.appOptions.canLicense && this.appOptions.isForm && ((this.permissions.fillForms===undefined) ? (this.permissions.edit !== false) : this.permissions.fillForms) && (this.editorConfig.mode !== 'view');
this.appOptions.isAnonymousSupport = !!this.api.asc_isAnonymousSupport();
this.appOptions.isRestrictedEdit = !this.appOptions.isEdit && this.appOptions.canFillForms;
this.appOptions.canSaveToFile = this.appOptions.isEdit && this.appOptions.isDesktopApp && this.appOptions.isOffline || this.appOptions.isRestrictedEdit;
this.appOptions.showSaveButton = this.appOptions.isEdit;

this.appOptions.compactHeader = this.appOptions.customization && (typeof (this.appOptions.customization) == 'object') && !!this.appOptions.customization.compactHeader;
this.appOptions.twoLevelHeader = this.appOptions.isEdit || this.appOptions.isRestrictedEdit; // when compactHeader=true some buttons move to toolbar
Expand Down Expand Up @@ -1318,6 +1320,7 @@ define([
}

this.api.asc_setViewMode(!this.appOptions.isEdit && !this.appOptions.isRestrictedEdit);
this.api.asc_setCanSendChanges(this.appOptions.canSaveToFile);
this.appOptions.isRestrictedEdit && this.api.asc_setRestriction(Asc.c_oAscRestrictionType.OnlyForms);
this.api.asc_LoadDocument();
},
Expand Down
2 changes: 1 addition & 1 deletion apps/pdfeditor/main/app/view/FileMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ define([
var isBCSupport = Common.Controllers.Desktop.isActive() ? Common.Controllers.Desktop.call("isBlockchainSupport") : false;
this.miSaveCopyAs[((this.mode.canDownload || this.mode.canDownloadOrigin) && (!this.mode.isDesktopApp || !this.mode.isOffline)) && (this.mode.canRequestSaveAs || this.mode.saveAsUrl) && !isBCSupport ?'show':'hide']();
this.miSaveAs[((this.mode.canDownload || this.mode.canDownloadOrigin) && this.mode.isDesktopApp && this.mode.isOffline)?'show':'hide']();
this.miSave[this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') ?'show':'hide']();
this.miSave[this.mode.showSaveButton && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') ?'show':'hide']();
this.miEdit[!this.mode.isEdit && this.mode.canEdit && this.mode.canRequestEditRights ?'show':'hide']();
this.miPrint[this.mode.canPrint && !this.mode.canPreviewPrint ?'show':'hide']();
this.miPrintWithPreview[this.mode.canPreviewPrint?'show':'hide']();
Expand Down
Loading

0 comments on commit 6778ceb

Please sign in to comment.