Skip to content

Commit

Permalink
Merge pull request #2858 from ONLYOFFICE/feature/close-editor
Browse files Browse the repository at this point in the history
Feature/close editor
  • Loading branch information
JuliaRadzhabova authored Feb 22, 2024
2 parents 3740ba4 + 2ad950f commit 2cd1224
Show file tree
Hide file tree
Showing 46 changed files with 403 additions and 59 deletions.
6 changes: 5 additions & 1 deletion apps/api/documents/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@
url: 'http://...',
text: 'Go to London',
blank: true,
requestClose: false // if true - goback send onRequestClose event instead opening url
requestClose: false // if true - goback send onRequestClose event instead opening url, deprecated, use customization.close instead
},
close: {
visible: false,
text: 'Close file'
},
reviewPermissions: {
"Group1": ["Group2"], // users from Group1 can accept/reject review changes made by users from Group2
Expand Down
18 changes: 17 additions & 1 deletion apps/common/main/lib/view/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ define([
'<div class="color-user-name"></div>' +
'</div>' +
'</div>' +
'<div class="btn-slot" id="slot-btn-close"></div>' +
'</div>' +
'</section>' +
'</section>';
Expand Down Expand Up @@ -158,6 +159,7 @@ define([
'<div class="color-user-name"></div>' +
'</div>' +
'</div>' +
'<div class="btn-slot" id="slot-btn-close"></div>' +
'</div>' +
'</section>';

Expand Down Expand Up @@ -312,6 +314,13 @@ define([
Common.NotificationCenter.trigger('goback');
});

if (me.btnClose) {
me.btnClose.on('click', function (e) {
Common.NotificationCenter.trigger('close');
});
me.btnClose.updateHint(appConfig.customization.close.text || me.textClose);
}

me.btnFavorite.on('click', function (e) {
// wait for setFavorite method
// me.options.favorite = !me.options.favorite;
Expand Down Expand Up @@ -729,6 +738,9 @@ define([
}
$btnUserName = $html.find('.color-user-name');
me.setUserName(me.options.userName);

if ( config.canCloseEditor )
me.btnClose = createTitleButton('toolbar__icon icon--inverse btn-close', $html.findById('#slot-btn-close'), false, 'bottom', 'big');
}

if (!_readonlyRights && config && (config.sharingSettingsUrl && config.sharingSettingsUrl.length || config.canRequestSharingSettings)) {
Expand Down Expand Up @@ -808,6 +820,9 @@ define([
$btnUserName = $html.find('.color-user-name');
me.setUserName(me.options.userName);

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) ) {
me.btnPrint = createTitleButton('toolbar__icon icon--inverse btn-print', $html.findById('#slot-btn-dt-print'), true, undefined, undefined, 'P');
}
Expand Down Expand Up @@ -1113,7 +1128,8 @@ define([
tipDocEdit: 'Editing',
textReview: 'Reviewing',
textReviewDesc: 'Suggest changes',
tipReview: 'Reviewing'
tipReview: 'Reviewing',
textClose: 'Close file'
}
}(), Common.Views.Header || {}))
});
11 changes: 11 additions & 0 deletions apps/common/mobile/resources/less/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,17 @@ input[type="number"]::-webkit-inner-spin-button {
border-radius: 4px;
}

// Close editor button
.close-editor-btn {
.item-inner {
padding-left: 36px;
}

.item-title {
color: @text-error;
}
}




Expand Down
1 change: 1 addition & 0 deletions apps/documenteditor/embed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
<div id="box-tools" class="dropdown">
<button class="control-btn svg-icon more-vertical"></button>
</div>
<button id="id-btn-close-editor" class="control-btn svg-icon search-close hidden"></button>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions apps/documenteditor/embed/index.html.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
<div id="box-tools" class="dropdown">
<button class="control-btn svg-icon more-vertical"></button>
</div>
<button id="id-btn-close-editor" class="control-btn svg-icon search-close hidden"></button>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions apps/documenteditor/embed/index_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
<div id="box-tools" class="dropdown">
<button class="control-btn svg-icon more-vertical"></button>
</div>
<button id="id-btn-close-editor" class="control-btn svg-icon search-close hidden"></button>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions apps/documenteditor/embed/index_loader.html.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
<div id="box-tools" class="dropdown">
<button class="control-btn svg-icon more-vertical"></button>
</div>
<button id="id-btn-close-editor" class="control-btn svg-icon search-close hidden"></button>
</div>
</div>

Expand Down
25 changes: 23 additions & 2 deletions apps/documenteditor/embed/js/ApplicationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,21 @@ DE.ApplicationController = new(function(){
ttOffset[1] = 40;
}

config.canBackToFolder = (config.canBackToFolder!==false) && config.customization && config.customization.goback &&
(config.customization.goback.url || config.customization.goback.requestClose && config.canRequestClose);
config.canCloseEditor = false;
var _canback = false;
if (typeof config.customization === 'object') {
if (typeof config.customization.goback == 'object' && config.canBackToFolder!==false) {
_canback = config.customization.close===undefined ?
config.customization.goback.url || config.customization.goback.requestClose && config.canRequestClose :
config.customization.goback.url && !config.customization.goback.requestClose;

if (config.customization.goback.requestClose)
console.log("Obsolete: The 'requestClose' parameter of the 'customization.goback' section is deprecated. Please use 'close' parameter in the 'customization' section instead.");
}
if (typeof config.customization.close === 'object')
config.canCloseEditor = !!config.customization.close.visible && config.canRequestClose && !config.isDesktopApp;
}
config.canBackToFolder = !!_canback;
}

function loadDocument(data) {
Expand Down Expand Up @@ -428,6 +441,10 @@ DE.ApplicationController = new(function(){
text && (typeof text == 'string') && $('#idt-close .caption').text(text);
}

if (config.canCloseEditor) {
$('#id-btn-close-editor').removeClass('hidden');
}

if (itemsCount < 7) {
$(dividers[0]).hide();
$(dividers[1]).hide();
Expand Down Expand Up @@ -508,6 +525,10 @@ DE.ApplicationController = new(function(){
}
});

$('#id-btn-close-editor').on('click', function(){
config.canRequestClose && Common.Gateway.requestClose();
});

var downloadAs = function(format){
api.asc_DownloadAs(new Asc.asc_CDownloadOptions(format));
Common.Analytics.trackEvent('Save');
Expand Down
1 change: 1 addition & 0 deletions apps/documenteditor/main/app/controller/LeftMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ define([
case 'external-help':
close_menu = !!isopts;
break;
case 'close-editor': Common.NotificationCenter.trigger('close'); break;
default: close_menu = false;
}

Expand Down
29 changes: 24 additions & 5 deletions apps/documenteditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ define([

Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('goback', _.bind(this.goBack, this));
Common.NotificationCenter.on('close', _.bind(this.closeEditor, this));
Common.NotificationCenter.on('markfavorite', _.bind(this.markFavorite, this));
Common.NotificationCenter.on('download:advanced', _.bind(this.onAdvancedOptions, this));
Common.NotificationCenter.on('showmessage', _.bind(this.onExternalMessage, this));
Expand Down Expand Up @@ -443,10 +444,6 @@ define([
this.appOptions.mergeFolderUrl = this.editorConfig.mergeFolderUrl;
this.appOptions.saveAsUrl = this.editorConfig.saveAsUrl;
this.appOptions.canAnalytics = false;
this.appOptions.canRequestClose = this.editorConfig.canRequestClose;
this.appOptions.canBackToFolder = (this.editorConfig.canBackToFolder!==false) && (typeof (this.editorConfig.customization) == 'object') && (typeof (this.editorConfig.customization.goback) == 'object')
&& (!_.isEmpty(this.editorConfig.customization.goback.url) || this.editorConfig.customization.goback.requestClose && this.appOptions.canRequestClose);
this.appOptions.canBack = this.appOptions.canBackToFolder === true;
this.appOptions.canPlugins = false;
this.appOptions.canMakeActionLink = this.editorConfig.canMakeActionLink;
this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers;
Expand All @@ -468,8 +465,26 @@ define([

this.appOptions.user.guest && this.appOptions.canRenameAnonymous && Common.NotificationCenter.on('user:rename', _.bind(this.showRenameUserDialog, this));

this.appOptions.canRequestClose = this.editorConfig.canRequestClose;
this.appOptions.canCloseEditor = false;

var _canback = false;
if (typeof this.appOptions.customization === 'object') {
if (typeof this.appOptions.customization.goback == 'object' && this.editorConfig.canBackToFolder!==false) {
_canback = this.appOptions.customization.close===undefined ?
!_.isEmpty(this.editorConfig.customization.goback.url) || this.editorConfig.customization.goback.requestClose && this.appOptions.canRequestClose :
!_.isEmpty(this.editorConfig.customization.goback.url) && !this.editorConfig.customization.goback.requestClose;

if (this.appOptions.customization.goback.requestClose)
console.log("Obsolete: The 'requestClose' parameter of the 'customization.goback' section is deprecated. Please use 'close' parameter in the 'customization' section instead.");
}
if (typeof this.appOptions.customization.close === 'object')
this.appOptions.canCloseEditor = !!this.appOptions.customization.close.visible && this.appOptions.canRequestClose && !this.appOptions.isDesktopApp;
}
this.appOptions.canBack = this.appOptions.canBackToFolder = !!_canback;

appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header');
appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '');
appHeader.setCanBack(this.appOptions.canBack, this.appOptions.canBack ? this.appOptions.customization.goback.text : '');

if (this.editorConfig.lang)
this.api.asc_setLocale(this.editorConfig.lang);
Expand Down Expand Up @@ -966,6 +981,10 @@ define([
}
},

closeEditor: function() {
this.appOptions.canRequestClose && this.onRequestClose();
},

markFavorite: function(favorite) {
if ( !Common.Controllers.Desktop.process('markfavorite') ) {
Common.Gateway.metaChange({
Expand Down
16 changes: 15 additions & 1 deletion apps/documenteditor/main/app/view/FileMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,19 @@ define([
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
}));
} else if (this.mode.canCloseEditor) {
$('<li class="devider" />' +
'<li id="fm-btn-close" class="fm-btn"/>').insertAfter($('#fm-btn-back', this.$el));
this.items.push(
new Common.UI.MenuItem({
el : $('#fm-btn-close', this.$el),
action : 'close-editor',
caption : this.mode.customization.close.text || this.btnCloseEditor,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
}));
}
},

Expand Down Expand Up @@ -655,6 +668,7 @@ define([
btnProtectCaption: 'Protect',
btnSaveCopyAsCaption : 'Save Copy as...',
btnExitCaption : 'Exit',
btnFileOpenCaption : 'Open...'
btnFileOpenCaption : 'Open...',
btnCloseEditor : 'Close File'
}, DE.Views.FileMenu || {}));
});
2 changes: 2 additions & 0 deletions apps/documenteditor/main/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@
"Common.Views.Header.tipViewUsers": "View users and manage document access rights",
"Common.Views.Header.txtAccessRights": "Change access rights",
"Common.Views.Header.txtRename": "Rename",
"Common.Views.Header.textClose": "Close file",
"Common.Views.History.textCloseHistory": "Close History",
"Common.Views.History.textHide": "Collapse",
"Common.Views.History.textHideAll": "Hide detailed changes",
Expand Down Expand Up @@ -2055,6 +2056,7 @@
"DE.Views.FileMenu.btnSettingsCaption": "Advanced Settings",
"DE.Views.FileMenu.btnToEditCaption": "Edit Document",
"DE.Views.FileMenu.textDownload": "Download",
"DE.Views.FileMenu.btnCloseEditor": "Close File",
"DE.Views.FileMenuPanels.CreateNew.txtBlank": "Blank document",
"DE.Views.FileMenuPanels.CreateNew.txtCreateNew": "Create New",
"DE.Views.FileMenuPanels.DocumentInfo.okButtonText": "Apply",
Expand Down
3 changes: 2 additions & 1 deletion apps/documenteditor/mobile/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@
"txtScheme6": "Concourse",
"txtScheme7": "Equity",
"txtScheme8": "Flow",
"txtScheme9": "Foundry"
"txtScheme9": "Foundry",
"textClose": "Close"
},
"Toolbar": {
"dlgLeaveMsgText": "You have unsaved changes. Click 'Stay on this Page' to wait for autosave. Click 'Leave this Page' to discard all the unsaved changes.",
Expand Down
12 changes: 7 additions & 5 deletions apps/documenteditor/mobile/src/controller/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'sto
Common.Notifications.on('toolbar:activatecontrols', activateControls);
Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls);
Common.Notifications.on('goback', goBack);
Common.Notifications.on('close', onRequestClose);

if (isDisconnected) {
f7.popover.close();
Expand All @@ -63,6 +64,7 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'sto
Common.Notifications.off('toolbar:activatecontrols', activateControls);
Common.Notifications.off('toolbar:deactivateeditcontrols', deactivateEditControls);
Common.Notifications.off('goback', goBack);
Common.Notifications.off('close', onRequestClose);
}
}, []);

Expand Down Expand Up @@ -120,11 +122,11 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'sto
// Back button
const [isShowBack, setShowBack] = useState(appOptions.canBackToFolder);
const loadConfig = (data) => {
if (data && data.config && data.config.canBackToFolder !== false &&
data.config.customization && data.config.customization.goback &&
(data.config.customization.goback.url || data.config.customization.goback.requestClose && data.config.canRequestClose))
{
setShowBack(true);
if (data && data.config && data.config?.canBackToFolder !== false && data.config?.customization && data.config?.customization.goback) {
const canback = data.config.customization.close === undefined ?
data.config.customization.goback.url || data.config.customization.goback.requestClose && data.config.canRequestClose :
data.config.customization.goback.url && !data.config.customization.goback.requestClose;
canback && setShowBack(true);
}
};

Expand Down
27 changes: 24 additions & 3 deletions apps/documenteditor/mobile/src/store/appOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,30 @@ export class storeAppOptions {
this.saveAsUrl = config.saveAsUrl;
this.canAnalytics = false;
this.canRequestClose = config.canRequestClose;
this.canBackToFolder = (config.canBackToFolder!==false) && (typeof (config.customization) == 'object') && (typeof (config.customization.goback) == 'object')
&& (!!(config.customization.goback.url) || config.customization.goback.requestClose && this.canRequestClose);
this.canBack = this.canBackToFolder === true;
this.canCloseEditor = false;

let canBack = false;

if (typeof config.customization === 'object' && config.customization !== null) {
const { goback, close } = config.customization;

if (typeof goback === 'object' && config.canBackToFolder !== false) {
const hasUrl = !!goback.url;
const requestClose = goback.requestClose && this.canRequestClose;

canBack = close === undefined ? hasUrl || requestClose : hasUrl && !goback.requestClose;

if (goback.requestClose) {
console.log("Obsolete: The 'requestClose' parameter of the 'customization.goback' section is deprecated. Please use 'close' parameter in the 'customization' section instead.");
}
}

if (typeof close === 'object' && close !== null) {
this.canCloseEditor = !!close.visible && this.canRequestClose && !this.isDesktopApp;
}
}

this.canBack = this.canBackToFolder = canBack;
this.canRequestSaveAs = config.canRequestSaveAs;
this.canPlugins = false;
this.canFeatureForms = !!Common.EditorApi.get().asc_isSupportFeature("forms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ const SettingsPage = inject("storeAppOptions", "storeReview", "storeDocumentInfo
const canFillForms = appOptions.canFillForms;
const isEditableForms = isForm && canFillForms;
const canSubmitForms = appOptions.canSubmitForms;
const canCloseEditor = appOptions.canCloseEditor;
const closeButtonText = canCloseEditor && appOptions.customization.close.text;
const canUseHistory = appOptions.canUseHistory;

let _isEdit = false,
_canDownload = false,
_canDownloadOrigin = false,
Expand Down Expand Up @@ -186,6 +188,9 @@ const SettingsPage = inject("storeAppOptions", "storeReview", "storeDocumentInfo
<Icon slot="media" icon="icon-feedback"></Icon>
</ListItem>
}
{canCloseEditor &&
<ListItem title={closeButtonText ?? t('Settings.textClose')} link="#" className='close-editor-btn no-indicator' onClick={() => Common.Notifications.trigger('close')}></ListItem>
}
</List>
</Page>
)
Expand Down
1 change: 1 addition & 0 deletions apps/pdfeditor/main/app/controller/LeftMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ define([
case 'external-help':
close_menu = !!isopts;
break;
case 'close-editor': Common.NotificationCenter.trigger('close'); break;
default: close_menu = false;
}

Expand Down
Loading

0 comments on commit 2cd1224

Please sign in to comment.