web-apps/apps/documenteditor/main/app/controller/LeftMenu.js

909 lines
43 KiB
JavaScript
Raw Normal View History

2016-04-01 13:17:09 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
2016-04-01 13:17:09 +00:00
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
2016-04-01 13:17:09 +00:00
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
2016-03-11 00:48:53 +00:00
/**
* LeftMenu.js
*
* Controller
*
* Created by Maxim Kadushkin on 19 February 2014
2018-03-01 12:16:38 +00:00
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
2016-03-11 00:48:53 +00:00
*
*/
define([
'core',
'common/main/lib/util/Shortcuts',
'common/main/lib/view/SaveAsDlg',
2016-03-11 00:48:53 +00:00
'documenteditor/main/app/view/LeftMenu',
'documenteditor/main/app/view/FileMenu',
'documenteditor/main/app/view/ViewTab'
2016-03-11 00:48:53 +00:00
], function () {
'use strict';
DE.Controllers.LeftMenu = Backbone.Controller.extend(_.extend({
views: [
'LeftMenu',
'FileMenu',
'ViewTab'
2016-03-11 00:48:53 +00:00
],
initialize: function() {
this.addListeners({
'Common.Views.Chat': {
'hide': _.bind(this.onHideChat, this)
},
'Common.Views.Header': {
'history:show': function () {
if ( !this.leftMenu.panelHistory.isVisible() )
this.clickMenuFileItem('header', 'history');
}.bind(this)
2016-03-11 00:48:53 +00:00
},
'Common.Views.About': {
'show': _.bind(this.aboutShowHide, this, false),
'hide': _.bind(this.aboutShowHide, this, true)
},
2017-08-11 11:01:27 +00:00
'Common.Views.Plugins': {
'plugin:open': _.bind(this.onPluginOpen, this),
'hide': _.bind(this.onHidePlugins, this)
2017-08-11 11:01:27 +00:00
},
'LeftMenu': {
'comments:show': _.bind(this.commentsShowHide, this, 'show'),
2022-03-16 19:06:42 +00:00
'comments:hide': _.bind(this.commentsShowHide, this, 'hide')
2017-08-11 11:01:27 +00:00
},
2016-03-11 00:48:53 +00:00
'FileMenu': {
2017-05-01 11:30:44 +00:00
'menu:hide': _.bind(this.menuFilesShowHide, this, 'hide'),
'menu:show': _.bind(this.menuFilesShowHide, this, 'show'),
2016-03-11 00:48:53 +00:00
'item:click': _.bind(this.clickMenuFileItem, this),
'saveas:format': _.bind(this.clickSaveAsFormat, this),
'settings:apply': _.bind(this.applySettings, this),
'create:new': _.bind(this.onCreateNew, this),
'recent:open': _.bind(this.onOpenRecent, this)
2016-03-11 00:48:53 +00:00
},
'Toolbar': {
2017-02-20 14:54:12 +00:00
'file:settings': _.bind(this.clickToolbarSettings,this),
'file:open': this.clickToolbarTab.bind(this, 'file'),
'file:close': this.clickToolbarTab.bind(this, 'other'),
'save:disabled': this.changeToolbarSaveState.bind(this)
2016-03-11 00:48:53 +00:00
},
'Common.Views.ReviewChanges': {
'collaboration:chat': _.bind(this.onShowHideChat, this)
},
'ViewTab': {
'viewtab:navigation': _.bind(this.onShowHideNavigation, this)
},
'SearchBar': {
'search:show': _.bind(this.onShowHideSearch, this)
2016-03-11 00:48:53 +00:00
}
});
Common.NotificationCenter.on('leftmenu:change', _.bind(this.onMenuChange, this));
Common.NotificationCenter.on('app:comment:add', _.bind(this.onAppAddComment, this));
Common.NotificationCenter.on('collaboration:history', _.bind(function () {
if ( !this.leftMenu.panelHistory.isVisible() )
this.clickMenuFileItem(null, 'history');
}, this));
2016-03-11 00:48:53 +00:00
},
onLaunch: function() {
this.leftMenu = this.createView('LeftMenu').render();
this.leftMenu.btnSearchBar.on('toggle', _.bind(this.onMenuSearchBar, this));
2016-03-11 00:48:53 +00:00
Common.util.Shortcuts.delegateShortcuts({
shortcuts: {
'command+shift+s,ctrl+shift+s': _.bind(this.onShortcut, this, 'save'),
'command+f,ctrl+f': _.bind(this.onShortcut, this, 'search'),
'ctrl+h': _.bind(this.onShortcut, this, 'replace'),
2016-03-11 00:48:53 +00:00
'alt+f': _.bind(this.onShortcut, this, 'file'),
'esc': _.bind(this.onShortcut, this, 'escape'),
/** coauthoring begin **/
'alt+q': _.bind(this.onShortcut, this, 'chat'),
'command+shift+h,ctrl+shift+h': _.bind(this.onShortcut, this, 'comments'),
/** coauthoring end **/
'f1': _.bind(this.onShortcut, this, 'help')
}
});
Common.util.Shortcuts.suspendEvents();
},
setApi: function(api) {
this.api = api;
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(this.onApiServerDisconnect, this));
2016-03-11 00:48:53 +00:00
Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiServerDisconnect, this));
this.api.asc_registerCallback('asc_onDownloadUrl', _.bind(this.onDownloadUrl, this));
2016-03-11 00:48:53 +00:00
/** coauthoring begin **/
if (this.mode.canCoAuthoring) {
if (this.mode.canChat)
this.api.asc_registerCallback('asc_onCoAuthoringChatReceiveMessage', _.bind(this.onApiChatMessage, this));
if (this.mode.canComments) {
this.api.asc_registerCallback('asc_onAddComment', _.bind(this.onApiAddComment, this));
this.api.asc_registerCallback('asc_onAddComments', _.bind(this.onApiAddComments, this));
2019-02-20 11:13:10 +00:00
var collection = this.getApplication().getCollection('Common.Collections.Comments'),
resolved = Common.Utils.InternalSettings.get("de-settings-resolvedcomment");
2016-03-11 00:48:53 +00:00
for (var i = 0; i < collection.length; ++i) {
2021-07-23 14:40:21 +00:00
var comment = collection.at(i);
if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id && (resolved || !comment.get('resolved'))) {
2016-03-11 00:48:53 +00:00
this.leftMenu.markCoauthOptions('comments', true);
break;
}
}
}
}
/** coauthoring end **/
this.leftMenu.getMenu('file').setApi(api);
if (this.mode.canUseHistory)
this.getApplication().getController('Common.Controllers.History').setApi(this.api).setMode(this.mode);
2021-08-26 15:39:06 +00:00
this.getApplication().getController('PageThumbnails').setApi(this.api).setMode(this.mode);
this.getApplication().getController('Search').setApi(this.api).setMode(this.mode);
this.leftMenu.setOptionsPanel('advancedsearch', this.getApplication().getController('Search').getView('Common.Views.SearchPanel'));
2016-03-11 00:48:53 +00:00
return this;
},
setMode: function(mode) {
this.mode = mode;
this.leftMenu.setMode(mode);
this.leftMenu.getMenu('file').setMode(mode);
if (!mode.isEdit) // TODO: unlock 'save as', 'open file menu' for 'view' mode
Common.util.Shortcuts.removeShortcuts({
shortcuts: {
'command+shift+s,ctrl+shift+s': _.bind(this.onShortcut, this, 'save'),
'alt+f': _.bind(this.onShortcut, this, 'file')
}
});
2016-03-11 00:48:53 +00:00
return this;
},
createDelayedElements: function() {
/** coauthoring begin **/
if ( this.mode.canCoAuthoring ) {
this.leftMenu.btnComments[(this.mode.canViewComments && !this.mode.isLightVersion) ? 'show' : 'hide']();
if (this.mode.canViewComments)
2017-03-29 16:27:44 +00:00
this.leftMenu.setOptionsPanel('comment', this.getApplication().getController('Common.Controllers.Comments').getView());
2016-03-11 00:48:53 +00:00
this.leftMenu.btnChat[(this.mode.canChat && !this.mode.isLightVersion) ? 'show' : 'hide']();
2016-03-11 00:48:53 +00:00
if (this.mode.canChat)
this.leftMenu.setOptionsPanel('chat', this.getApplication().getController('Common.Controllers.Chat').getView('Common.Views.Chat'));
} else {
this.leftMenu.btnChat.hide();
this.leftMenu.btnComments.hide();
}
/** coauthoring end **/
if (this.mode.canUseHistory)
this.leftMenu.setOptionsPanel('history', this.getApplication().getController('Common.Controllers.History').getView('Common.Views.History'));
this.leftMenu.setOptionsPanel('navigation', this.getApplication().getController('Navigation').getView('Navigation'));
2021-08-27 11:50:02 +00:00
if (this.mode.canUseThumbnails) {
this.leftMenu.btnThumbnails.show();
this.leftMenu.setOptionsPanel('thumbnails', this.getApplication().getController('PageThumbnails').getView('PageThumbnails'));
} else {
this.leftMenu.btnThumbnails.hide();
}
2020-11-02 20:26:17 +00:00
(this.mode.trialMode || this.mode.isBeta) && this.leftMenu.setDeveloperMode(this.mode.trialMode, this.mode.isBeta, this.mode.buildVersion);
2017-04-12 07:54:47 +00:00
Common.util.Shortcuts.resumeEvents();
return this;
},
enablePlugins: function() {
if (this.mode.canPlugins) {
2017-08-11 11:01:27 +00:00
// this.leftMenu.btnPlugins.show();
this.leftMenu.setOptionsPanel('plugins', this.getApplication().getController('Common.Controllers.Plugins').getView('Common.Views.Plugins'));
} else
this.leftMenu.btnPlugins.hide();
2020-11-02 20:26:17 +00:00
(this.mode.trialMode || this.mode.isBeta) && this.leftMenu.setDeveloperMode(this.mode.trialMode, this.mode.isBeta, this.mode.buildVersion);
2016-03-11 00:48:53 +00:00
},
clickMenuFileItem: function(menu, action, isopts) {
var close_menu = true;
switch (action) {
case 'back':
break;
case 'save': this.api.asc_Save(); break;
case 'save-desktop': this.api.asc_DownloadAs(); break;
case 'saveas':
if ( isopts ) close_menu = false;
2021-12-10 10:13:27 +00:00
else this.clickSaveAsFormat();
2016-03-11 00:48:53 +00:00
break;
case 'save-copy':
if ( isopts ) close_menu = false;
2021-12-10 10:13:27 +00:00
else this.clickSaveAsFormat(undefined, undefined, true);
break;
2021-11-08 14:05:18 +00:00
case 'print': this.api.asc_Print(new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86)); break;
2016-03-11 00:48:53 +00:00
case 'exit': Common.NotificationCenter.trigger('goback'); break;
case 'edit':
this.getApplication().getController('Statusbar').setStatusCaption(this.requestEditRightsText);
Common.Gateway.requestEditRights();
break;
case 'new':
if ( isopts ) close_menu = false;
else this.onCreateNew(undefined, 'blank');
break;
case 'history':
if (!this.leftMenu.panelHistory.isVisible()) {
if (this.api.isDocumentModified()) {
var me = this;
this.api.asc_stopSaving();
Common.UI.warning({
closable: false,
width: 500,
title: this.notcriticalErrorTitle,
msg: this.leavePageText,
buttons: ['ok', 'cancel'],
primary: 'ok',
callback: function(btn) {
if (btn == 'ok') {
me.api.asc_undoAllChanges();
2021-03-29 13:40:05 +00:00
me.api.asc_continueSaving();
2016-03-11 00:48:53 +00:00
me.showHistory();
} else
me.api.asc_continueSaving();
}
});
} else
this.showHistory();
}
break;
2016-09-27 12:09:32 +00:00
case 'rename':
var me = this,
documentCaption = me.api.asc_getDocumentName();
(new Common.Views.RenameDialog({
filename: documentCaption,
2021-05-12 16:04:14 +00:00
maxLength: this.mode.wopi ? this.mode.wopi.FileNameMaxLength : undefined,
2016-09-27 12:09:32 +00:00
handler: function(result, value) {
if (result == 'ok' && !_.isEmpty(value.trim()) && documentCaption !== value.trim()) {
2021-05-12 16:04:14 +00:00
me.mode.wopi ? me.api.asc_wopi_renameFile(value) : Common.Gateway.requestRename(value);
2016-09-27 12:09:32 +00:00
}
Common.NotificationCenter.trigger('edit:complete', me);
}
})).show();
break;
case 'help':
close_menu = !!isopts;
break;
2016-03-11 00:48:53 +00:00
default: close_menu = false;
}
if (close_menu && menu) {
2016-03-11 00:48:53 +00:00
menu.hide();
}
},
2021-12-10 10:13:27 +00:00
_saveAsFormat: function(menu, format, ext, textParams) {
var needDownload = !!ext;
2016-03-11 00:48:53 +00:00
if (menu) {
2021-12-10 10:13:27 +00:00
var options = new Asc.asc_CDownloadOptions(format, needDownload);
options.asc_setTextParams(textParams);
if (format == Asc.c_oAscFileType.TXT || format == Asc.c_oAscFileType.RTF) {
Common.UI.warning({
title: this.notcriticalErrorTitle,
msg: (format == Asc.c_oAscFileType.TXT) ? this.warnDownloadAs : this.warnDownloadAsRTF,
buttons: ['ok', 'cancel'],
callback: _.bind(function(btn){
if (btn == 'ok') {
this.isFromFileDownloadAs = ext;
if (format == Asc.c_oAscFileType.TXT)
2021-12-10 10:13:27 +00:00
Common.NotificationCenter.trigger('download:advanced', Asc.c_oAscAdvancedOptionsID.TXT, this.api.asc_getAdvancedOptions(), 2, options);
else
2021-12-10 10:13:27 +00:00
this.api.asc_DownloadAs(options);
menu.hide();
}
}, this)
});
} else if (format == Asc.c_oAscFileType.DOCX) {
2019-07-25 12:13:40 +00:00
if (!Common.Utils.InternalSettings.get("de-settings-compatible") && !Common.localStorage.getBool("de-hide-save-compatible") && this.api.asc_isCompatibilityMode()) {
Common.UI.warning({
closable: false,
width: 600,
title: this.notcriticalErrorTitle,
msg: this.txtCompatible,
buttons: ['ok', 'cancel'],
dontshow: true,
callback: _.bind(function(btn, dontshow){
if (dontshow) Common.localStorage.setItem("de-hide-save-compatible", 1);
if (btn == 'ok') {
this.isFromFileDownloadAs = ext;
2021-12-10 10:13:27 +00:00
this.api.asc_DownloadAs(options);
menu.hide();
}
}, this)
});
} else {
this.isFromFileDownloadAs = ext;
2021-12-10 10:13:27 +00:00
options.asc_setCompatible(!!Common.Utils.InternalSettings.get("de-settings-compatible"));
this.api.asc_DownloadAs(options);
2019-08-06 08:24:44 +00:00
menu.hide();
}
} else {
this.isFromFileDownloadAs = ext;
2021-12-10 10:13:27 +00:00
this.api.asc_DownloadAs(options);
menu.hide();
}
} else {
2021-12-10 10:13:27 +00:00
this.isFromFileDownloadAs = needDownload;
this.api.asc_DownloadOrigin(needDownload);
}
},
2021-12-10 10:13:27 +00:00
clickSaveAsFormat: function(menu, format, ext) { // ext isn't undefined for save copy as
var me = this,
fileType = this.getApplication().getController('Main').document.fileType;
if ( /^pdf|xps|oxps|djvu$/.test(fileType)) {
if (format===undefined) {
2021-12-10 10:13:27 +00:00
this._saveAsFormat(undefined, format, ext); // download original
menu && menu.hide();
} else if (format == Asc.c_oAscFileType.PDF || format == Asc.c_oAscFileType.PDFA)
this._saveAsFormat(menu, format, ext);
2021-12-10 10:13:27 +00:00
else {
2022-02-16 19:58:34 +00:00
if (format == Asc.c_oAscFileType.TXT || format == Asc.c_oAscFileType.RTF) // don't show message about pdf/xps/oxps
me._saveAsFormat(menu, format, ext, new AscCommon.asc_CTextParams(Asc.c_oAscTextAssociation.PlainLine));
else {
Common.UI.warning({
width: 600,
title: this.notcriticalErrorTitle,
msg: Common.Utils.String.format(this.warnDownloadAsPdf, fileType.toUpperCase()),
buttons: ['ok', 'cancel'],
callback: _.bind(function(btn){
if (btn == 'ok') {
me._saveAsFormat(menu, format, ext, new AscCommon.asc_CTextParams(Asc.c_oAscTextAssociation.PlainLine));
}
}, this)
});
}
2021-12-10 10:13:27 +00:00
}
} else
this._saveAsFormat(menu, format, ext);
},
onDownloadUrl: function(url, fileType) {
if (this.isFromFileDownloadAs) {
var me = this,
defFileName = this.getApplication().getController('Viewport').getView('Common.Views.Header').getDocumentCaption();
!defFileName && (defFileName = me.txtUntitled);
if (typeof this.isFromFileDownloadAs == 'string') {
var idx = defFileName.lastIndexOf('.');
if (idx>0)
defFileName = defFileName.substring(0, idx) + this.isFromFileDownloadAs;
}
2019-07-26 09:54:20 +00:00
if (me.mode.canRequestSaveAs) {
Common.Gateway.requestSaveAs(url, defFileName, fileType);
2019-07-26 09:54:20 +00:00
} else {
me._saveCopyDlg = new Common.Views.SaveAsDlg({
saveFolderUrl: me.mode.saveAsUrl,
saveFileUrl: url,
defFileName: defFileName
});
me._saveCopyDlg.on('saveaserror', function(obj, err){
var config = {
closable: false,
title: me.notcriticalErrorTitle,
msg: err,
iconCls: 'warn',
buttons: ['ok'],
callback: function(btn){
Common.NotificationCenter.trigger('edit:complete', me);
}
};
Common.UI.alert(config);
}).on('close', function(obj){
me._saveCopyDlg = undefined;
});
me._saveCopyDlg.show();
}
}
this.isFromFileDownloadAs = false;
},
2016-03-11 00:48:53 +00:00
applySettings: function(menu) {
var value;
2017-10-03 11:22:33 +00:00
value = Common.localStorage.getBool("de-settings-inputmode");
Common.Utils.InternalSettings.set("de-settings-inputmode", value);
this.api.SetTextBoxInputMode(value);
2016-03-11 00:48:53 +00:00
var fast_coauth = Common.Utils.InternalSettings.get("de-settings-coauthmode");
2016-03-11 00:48:53 +00:00
/** coauthoring begin **/
if (this.mode.isEdit && !this.mode.isOffline && this.mode.canCoAuthoring ) {
if (this.mode.canChangeCoAuthoring) {
fast_coauth = Common.localStorage.getBool("de-settings-coauthmode", true);
Common.Utils.InternalSettings.set("de-settings-coauthmode", fast_coauth);
this.api.asc_SetFastCollaborative(fast_coauth);
}
2016-03-11 00:48:53 +00:00
value = Common.localStorage.getItem((fast_coauth) ? "de-settings-showchanges-fast" : "de-settings-showchanges-strict");
Common.Utils.InternalSettings.set((fast_coauth) ? "de-settings-showchanges-fast" : "de-settings-showchanges-strict", value);
2016-03-11 00:48:53 +00:00
switch(value) {
case 'all': value = Asc.c_oAscCollaborativeMarksShowType.All; break;
case 'none': value = Asc.c_oAscCollaborativeMarksShowType.None; break;
case 'last': value = Asc.c_oAscCollaborativeMarksShowType.LastChanges; break;
default: value = (fast_coauth) ? Asc.c_oAscCollaborativeMarksShowType.None : Asc.c_oAscCollaborativeMarksShowType.LastChanges;
2016-03-11 00:48:53 +00:00
}
this.api.SetCollaborativeMarksShowType(value);
2022-04-19 15:59:18 +00:00
} else if (this.mode.canLiveView && !this.mode.isOffline && this.mode.canChangeCoAuthoring) { // viewer
2022-02-15 07:41:16 +00:00
fast_coauth = Common.localStorage.getBool("de-settings-view-coauthmode", false);
Common.Utils.InternalSettings.set("de-settings-coauthmode", fast_coauth);
this.api.asc_SetFastCollaborative(fast_coauth);
2016-03-11 00:48:53 +00:00
}
2017-10-03 11:22:33 +00:00
value = Common.localStorage.getBool("de-settings-livecomment", true);
Common.Utils.InternalSettings.set("de-settings-livecomment", value);
var resolved = Common.localStorage.getBool("de-settings-resolvedcomment");
2017-10-03 11:22:33 +00:00
Common.Utils.InternalSettings.set("de-settings-resolvedcomment", resolved);
if (this.mode.canViewComments && this.leftMenu.panelComments.isVisible())
2017-10-03 11:22:33 +00:00
value = resolved = true;
(value) ? this.api.asc_showComments(resolved) : this.api.asc_hideComments();
this.getApplication().getController('Common.Controllers.ReviewChanges').commentsShowHide(value ? 'show' : 'hide');
2016-03-11 00:48:53 +00:00
/** coauthoring end **/
2020-02-17 13:43:02 +00:00
value = Common.localStorage.getBool("de-settings-cachemode", true);
Common.Utils.InternalSettings.set("de-settings-cachemode", value);
this.api.asc_setDefaultBlitMode(value);
2016-03-11 00:48:53 +00:00
value = Common.localStorage.getItem("de-settings-fontrender");
2017-10-03 11:22:33 +00:00
Common.Utils.InternalSettings.set("de-settings-fontrender", value);
2016-03-11 00:48:53 +00:00
switch (value) {
case '1': this.api.SetFontRenderingMode(1); break;
case '2': this.api.SetFontRenderingMode(2); break;
case '0': this.api.SetFontRenderingMode(3); break;
}
if (this.mode.isEdit) {
if (this.mode.canChangeCoAuthoring || !fast_coauth) {// can change co-auth. mode or for strict mode
value = parseInt(Common.localStorage.getItem("de-settings-autosave"));
Common.Utils.InternalSettings.set("de-settings-autosave", value);
this.api.asc_setAutoSaveGap(value);
}
2016-03-11 00:48:53 +00:00
if (Common.UI.FeaturesManager.canChange('spellcheck')) {
value = Common.localStorage.getBool("de-settings-spellcheck", true);
Common.Utils.InternalSettings.set("de-settings-spellcheck", value);
this.api.asc_setSpellCheck(value);
2022-03-29 14:51:33 +00:00
var spprops = new AscCommon.CSpellCheckSettings();
value = Common.localStorage.getBool("de-spellcheck-ignore-uppercase-words", true);
Common.Utils.InternalSettings.set("de-spellcheck-ignore-uppercase-words", value);
spprops.put_IgnoreWordsInUppercase(value);
value = Common.localStorage.getBool("de-spellcheck-ignore-numbers-words", true);
Common.Utils.InternalSettings.set("de-spellcheck-ignore-numbers-words", value);
spprops.put_IgnoreWordsWithNumbers(value);
this.api.asc_setSpellCheckSettings(spprops);
}
value = parseInt(Common.localStorage.getItem("de-settings-paste-button"));
Common.Utils.InternalSettings.set("de-settings-paste-button", value);
this.api.asc_setVisiblePasteButton(!!value);
}
2016-03-11 00:48:53 +00:00
2017-10-04 15:44:01 +00:00
this.api.put_ShowSnapLines(Common.Utils.InternalSettings.get("de-settings-showsnaplines"));
2016-03-11 00:48:53 +00:00
menu.hide();
},
onCreateNew: function(menu, type) {
if ( !Common.Controllers.Desktop.process('create:new') ) {
if (type == 'blank' && this.mode.canRequestCreateNew)
Common.Gateway.requestCreateNew();
else {
var newDocumentPage = window.open(type == 'blank' ? this.mode.createUrl : type, "_blank");
if (newDocumentPage) newDocumentPage.focus();
}
}
2016-03-11 00:48:53 +00:00
if (menu) {
menu.hide();
}
},
onOpenRecent: function(menu, url) {
if (menu) {
menu.hide();
}
var recentDocPage = window.open(url);
if (recentDocPage)
recentDocPage.focus();
Common.component.Analytics.trackEvent('Open Recent');
},
clickToolbarSettings: function(obj) {
2017-02-20 14:54:12 +00:00
this.leftMenu.showMenu('file:opts');
},
clickToolbarTab: function (tab, e) {
if (tab == 'file')
this.leftMenu.showMenu('file'); else
2017-04-20 10:29:44 +00:00
this.leftMenu.menuFile.hide();
2016-03-11 00:48:53 +00:00
},
changeToolbarSaveState: function (state) {
var btnSave = this.leftMenu.menuFile.getButton('save');
btnSave && btnSave.setDisabled(state);
},
2016-03-11 00:48:53 +00:00
/** coauthoring begin **/
onHideChat: function() {
$(this.leftMenu.btnChat.el).blur();
Common.NotificationCenter.trigger('layout:changed', 'leftmenu');
},
onHidePlugins: function() {
Common.NotificationCenter.trigger('layout:changed', 'leftmenu');
},
2016-03-11 00:48:53 +00:00
/** coauthoring end **/
onApiServerDisconnect: function(enableDownload) {
2016-03-11 00:48:53 +00:00
this.mode.isEdit = false;
this.leftMenu.close();
/** coauthoring begin **/
this.leftMenu.btnComments.setDisabled(true);
this.leftMenu.btnChat.setDisabled(true);
/** coauthoring end **/
this.leftMenu.btnPlugins.setDisabled(true);
this.leftMenu.btnNavigation.setDisabled(true);
2016-03-11 00:48:53 +00:00
this.leftMenu.getMenu('file').setMode({isDisconnected: true, enableDownload: !!enableDownload});
2016-03-11 00:48:53 +00:00
},
setPreviewMode: function(mode) {
if (this.viewmode === mode) return;
this.viewmode = mode;
this.leftMenu.panelSearch && this.leftMenu.panelSearch.setSearchMode(this.viewmode ? 'no-replace' : 'search');
},
2021-06-29 13:27:44 +00:00
SetDisabled: function(disable, options) {
2021-06-29 21:31:55 +00:00
if (this.leftMenu._state.disabled !== disable) {
this.leftMenu._state.disabled = disable;
if (disable) {
this.previsEdit = this.mode.isEdit;
this.prevcanEdit = this.mode.canEdit;
this.mode.isEdit = this.mode.canEdit = !disable;
} else {
this.mode.isEdit = this.previsEdit;
this.mode.canEdit = this.prevcanEdit;
}
}
2016-03-11 00:48:53 +00:00
if (disable) this.leftMenu.close();
2021-06-29 13:27:44 +00:00
if (!options || options.comments && options.comments.disable)
this.leftMenu.btnComments.setDisabled(disable);
if (!options || options.chat)
this.leftMenu.btnChat.setDisabled(disable);
if (!options || options.navigation && options.navigation.disable)
this.leftMenu.btnNavigation.setDisabled(disable);
this.leftMenu.btnPlugins.setDisabled(disable);
2016-03-11 00:48:53 +00:00
},
/** coauthoring begin **/
onApiChatMessage: function() {
this.leftMenu.markCoauthOptions('chat');
},
onApiAddComment: function(id, data) {
2019-02-20 11:13:10 +00:00
var resolved = Common.Utils.InternalSettings.get("de-settings-resolvedcomment");
2021-07-23 14:40:21 +00:00
if (data && data.asc_getUserId() !== this.mode.user.id && (resolved || !data.asc_getSolved()) && AscCommon.UserInfoParser.canViewComment(data.asc_getUserName()))
2016-03-11 00:48:53 +00:00
this.leftMenu.markCoauthOptions('comments');
},
onApiAddComments: function(data) {
2019-02-20 11:13:10 +00:00
var resolved = Common.Utils.InternalSettings.get("de-settings-resolvedcomment");
2016-03-11 00:48:53 +00:00
for (var i = 0; i < data.length; ++i) {
2021-07-23 14:40:21 +00:00
if (data[i].asc_getUserId() !== this.mode.user.id && (resolved || !data[i].asc_getSolved()) && AscCommon.UserInfoParser.canViewComment(data.asc_getUserName())) {
2016-03-11 00:48:53 +00:00
this.leftMenu.markCoauthOptions('comments');
break;
}
}
},
onAppAddComment: function(sender) {
var me = this;
if ( this.api.can_AddQuotedComment() === false ) {
(new Promise(function(resolve, reject) {
resolve();
})).then(function () {
Common.UI.Menu.Manager.hideAll();
me.leftMenu.showMenu('comments');
var ctrl = DE.getController('Common.Controllers.Comments');
ctrl.getView().showEditContainer(true);
ctrl.onAfterShow();
});
}
},
2016-03-11 00:48:53 +00:00
commentsShowHide: function(mode) {
2017-10-03 11:22:33 +00:00
var value = Common.Utils.InternalSettings.get("de-settings-livecomment"),
resolved = Common.Utils.InternalSettings.get("de-settings-resolvedcomment");
if (!value || !resolved) {
(mode === 'show') ? this.api.asc_showComments(true) : ((value) ? this.api.asc_showComments(resolved) : this.api.asc_hideComments());
2016-03-11 00:48:53 +00:00
}
if (mode === 'show') {
this.getApplication().getController('Common.Controllers.Comments').onAfterShow();
}
$(this.leftMenu.btnComments.el).blur();
},
/** coauthoring end **/
aboutShowHide: function(value) {
if (this.api)
this.api.asc_enableKeyEvents(value);
if (value) $(this.leftMenu.btnAbout.el).blur();
if (value && this.leftMenu._state.pluginIsRunning) {
this.leftMenu.panelPlugins.show();
if (this.mode.canCoAuthoring) {
this.mode.canViewComments && this.leftMenu.panelComments['hide']();
this.mode.canChat && this.leftMenu.panelChat['hide']();
}
}
2016-03-11 00:48:53 +00:00
},
2017-05-01 11:30:44 +00:00
menuFilesShowHide: function(state) {
if (this.api && state == 'hide')
this.api.asc_enableKeyEvents(true);
2016-03-11 00:48:53 +00:00
},
onMenuChange: function (value) {
if ('hide' === value) {
if (this.api) {
if (this.leftMenu.btnComments.isActive()) {
this.leftMenu.btnComments.toggle(false);
this.leftMenu.onBtnMenuClick(this.leftMenu.btnComments);
// focus to sdk
this.api.asc_enableKeyEvents(true);
} else if (this.leftMenu.btnThumbnails.isActive()) {
this.leftMenu.btnThumbnails.toggle(false);
2022-02-07 12:28:37 +00:00
this.leftMenu.panelThumbnails.hide();
this.leftMenu.onBtnMenuClick(this.leftMenu.btnThumbnails);
2022-02-12 12:35:16 +00:00
} else if (this.leftMenu.btnSearchBar.isActive()) {
this.leftMenu.btnSearchBar.toggle(false);
this.leftMenu.onBtnMenuClick(this.leftMenu.btnSearchBar);
}
2022-04-22 16:52:40 +00:00
else if (this.leftMenu.btnNavigation.isActive()) {
this.leftMenu.btnNavigation.toggle(false);
this.leftMenu.panelNavigation.hide();
this.leftMenu.onBtnMenuClick(this.leftMenu.btnNavigation);
}
2016-03-11 00:48:53 +00:00
}
}
},
onShortcut: function(s, e) {
if (!this.mode) return;
2016-03-11 00:48:53 +00:00
switch (s) {
case 'replace':
case 'search':
this.leftMenu.btnAbout.toggle(false);
2022-06-01 19:49:52 +00:00
Common.UI.Menu.Manager.hideAll();
var selectedText = this.api.asc_GetSelectedText();
if (this.isSearchPanelVisible()) {
selectedText && this.leftMenu.panelSearch.setFindText(selectedText);
this.leftMenu.panelSearch.focus(selectedText !== '' ? s : 'search');
2022-08-24 10:29:50 +00:00
this.leftMenu.fireEvent('search:aftershow', this.leftMenu, selectedText ? selectedText : undefined);
return false;
} else if (this.getApplication().getController('Viewport').isSearchBarVisible()) {
var viewport = this.getApplication().getController('Viewport');
if (s === 'replace') {
viewport.header.btnSearch.toggle(false);
this.onShowHideSearch(true, viewport.searchBar.inputSearch.val());
} else {
selectedText && viewport.searchBar.setText(selectedText);
viewport.searchBar.focus();
return false;
}
} else if (s === 'search') {
Common.NotificationCenter.trigger('search:show');
return false;
} else {
2022-08-24 10:29:50 +00:00
this.onShowHideSearch(true, selectedText ? selectedText : undefined);
}
this.leftMenu.btnSearchBar.toggle(true,true);
2022-08-24 10:29:50 +00:00
this.leftMenu.panelSearch.focus(selectedText ? s : 'search');
2017-06-27 08:40:15 +00:00
// this.leftMenu.menuFile.hide();
2016-03-11 00:48:53 +00:00
return false;
case 'save':
if (this.mode.canDownload || this.mode.canDownloadOrigin) {
if (this.mode.isDesktopApp && this.mode.isOffline) this.api.asc_DownloadAs();
else {
if (this.mode.canDownload) {
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu('file:saveas');
} else
this.api.asc_DownloadOrigin();
}
}
return false;
case 'help':
if ( this.mode.isEdit && this.mode.canHelp ) { // TODO: unlock 'help' for 'view' mode
2017-08-09 16:59:54 +00:00
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu('file:help');
}
2016-03-11 00:48:53 +00:00
return false;
case 'file':
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu('file');
return false;
case 'escape':
// if (!this.leftMenu.isOpened()) return true;
var btnSearch = this.getApplication().getController('Viewport').header.btnSearch;
btnSearch.pressed && btnSearch.toggle(false);
2017-04-20 10:29:44 +00:00
if ( this.leftMenu.menuFile.isVisible() ) {
if (Common.UI.HintManager.needCloseFileMenu())
this.leftMenu.menuFile.hide();
2017-04-20 10:29:44 +00:00
return false;
}
2016-03-11 00:48:53 +00:00
var statusbar = DE.getController('Statusbar');
var menu_opened = statusbar.statusbar.$el.find('.open > [data-toggle="dropdown"]');
if (menu_opened.length) {
$.fn.dropdown.Constructor.prototype.keydown.call(menu_opened[0], e);
return false;
}
if (this.mode.canPlugins && this.leftMenu.panelPlugins) {
menu_opened = this.leftMenu.panelPlugins.$el.find('#menu-plugin-container.open > [data-toggle="dropdown"]');
if (menu_opened.length) {
$.fn.dropdown.Constructor.prototype.keydown.call(menu_opened[0], e);
return false;
}
}
2017-04-20 10:29:44 +00:00
if (this.leftMenu.btnAbout.pressed || this.leftMenu.btnPlugins.pressed ||
$(e.target).parents('#left-menu').length ) {
if (!Common.UI.HintManager.isHintVisible()) {
this.leftMenu.close();
Common.NotificationCenter.trigger('layout:changed', 'leftmenu');
}
2016-03-11 00:48:53 +00:00
return false;
}
break;
/** coauthoring begin **/
case 'chat':
if (this.mode.canCoAuthoring && this.mode.canChat && !this.mode.isLightVersion) {
2016-03-11 00:48:53 +00:00
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu('chat');
}
return false;
case 'comments':
if (this.mode.canCoAuthoring && this.mode.canViewComments && !this.mode.isLightVersion) {
2016-03-11 00:48:53 +00:00
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu('comments');
this.getApplication().getController('Common.Controllers.Comments').onAfterShow();
}
return false;
/** coauthoring end **/
}
},
2017-08-11 11:01:27 +00:00
onPluginOpen: function(panel, type, action) {
if ( type == 'onboard' ) {
if ( action == 'open' ) {
2017-08-18 12:17:25 +00:00
this.leftMenu.close();
2017-08-11 11:01:27 +00:00
this.leftMenu.panelPlugins.show();
this.leftMenu.onBtnMenuClick({pressed:true, options: {action: 'plugins'}});
this.leftMenu._state.pluginIsRunning = true;
2017-08-11 11:01:27 +00:00
} else {
this.leftMenu._state.pluginIsRunning = false;
2017-08-11 11:01:27 +00:00
this.leftMenu.close();
}
}
},
2016-03-11 00:48:53 +00:00
showHistory: function() {
2021-05-13 11:45:53 +00:00
if (!this.mode.wopi) {
var maincontroller = DE.getController('Main');
if (!maincontroller.loadMask)
maincontroller.loadMask = new Common.UI.LoadMask({owner: $('#viewport')});
maincontroller.loadMask.setTitle(this.textLoadHistory);
maincontroller.loadMask.show();
}
2016-03-11 00:48:53 +00:00
Common.Gateway.requestHistory();
},
onShowHideChat: function(state) {
if (this.mode.canCoAuthoring && this.mode.canChat && !this.mode.isLightVersion) {
if (state) {
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu('chat');
} else {
this.leftMenu.btnChat.toggle(false, true);
this.leftMenu.onBtnMenuClick(this.leftMenu.btnChat);
}
}
},
onShowHideNavigation: function(state) {
if (state) {
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu('navigation');
} else {
this.leftMenu.btnNavigation.toggle(false, true);
this.leftMenu.onBtnMenuClick(this.leftMenu.btnNavigation);
}
},
onShowHideSearch: function (state, findText) {
if (state) {
Common.UI.Menu.Manager.hideAll();
2022-03-16 19:06:42 +00:00
this.leftMenu.showMenu('advancedsearch', undefined, true);
this.leftMenu.fireEvent('search:aftershow', this.leftMenu, findText);
} else {
this.leftMenu.btnSearchBar.toggle(false, true);
this.leftMenu.onBtnMenuClick(this.leftMenu.btnSearchBar);
}
},
onMenuSearchBar: function(obj, show) {
if (show) {
var mode = this.mode.isEdit && !this.viewmode ? undefined : 'no-replace';
this.leftMenu.panelSearch.setSearchMode(mode);
}
},
isSearchPanelVisible: function () {
2022-06-08 14:36:18 +00:00
return this.leftMenu && this.leftMenu.panelSearch && this.leftMenu.panelSearch.isVisible();
},
isCommentsVisible: function() {
return this.leftMenu && this.leftMenu.panelComments && this.leftMenu.panelComments.isVisible();
},
2016-03-11 00:48:53 +00:00
textNoTextFound : 'Text not found',
newDocumentTitle : 'Unnamed document',
requestEditRightsText : 'Requesting editing rights...',
textReplaceSuccess : 'Search has been done. {0} occurrences have been replaced',
textReplaceSkipped : 'The replacement has been made. {0} occurrences were skipped.',
2019-11-08 10:53:10 +00:00
textLoadHistory : 'Loading version history...',
2016-03-11 00:48:53 +00:00
notcriticalErrorTitle: 'Warning',
leavePageText: 'All unsaved changes in this document will be lost.<br> Click \'Cancel\' then \'Save\' to save them. Click \'OK\' to discard all the unsaved changes.',
2018-04-18 13:20:59 +00:00
warnDownloadAs : 'If you continue saving in this format all features except the text will be lost.<br>Are you sure you want to continue?',
warnDownloadAsRTF : 'If you continue saving in this format some of the formatting might be lost.<br>Are you sure you want to continue?',
txtUntitled: 'Untitled',
2021-12-10 10:13:27 +00:00
txtCompatible: 'The document will be saved to the new format. It will allow to use all the editor features, but might affect the document layout.<br>Use the \'Compatibility\' option of the advanced settings if you want to make the files compatible with older MS Word versions.',
2022-03-17 16:57:30 +00:00
warnDownloadAsPdf: 'Your {0} will be converted to an editable format. This may take a while. The resulting document will be optimized to allow you to edit the text, so it might not look exactly like the original {0}, especially if the original file contained lots of graphics.',
warnReplaceString: '{0} is not a valid special character for the Replace With box.'
2016-03-11 00:48:53 +00:00
}, DE.Controllers.LeftMenu || {}));
});