web-apps/apps/presentationeditor/main/app/view/FileMenu.js

662 lines
27 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
/**
* FileMenu.js
*
* Describes menu 'File' for the left tool menu
*
* Created by Maxim Kadushkin on 14 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([
'text!presentationeditor/main/app/template/FileMenu.template',
'underscore',
'common/main/lib/component/BaseView'
], function (tpl, _) {
'use strict';
PE.Views.FileMenu = Common.UI.BaseView.extend(_.extend({
el: '#file-menu-panel',
2019-08-22 14:43:51 +00:00
rendered: false,
2017-04-20 13:34:39 +00:00
options: {alias:'FileMenu'},
2016-03-11 00:48:53 +00:00
template: _.template(tpl),
events: function() {
return {
'click .fm-btn': _.bind(function(event){
var $item = $(event.currentTarget);
if ($item.hasClass('disabled')) {
return;
} else
if (!$item.hasClass('active')) {
$('.fm-btn',this.el).removeClass('active');
$item.addClass('active');
}
var item = _.findWhere(this.items, {el: event.currentTarget});
if (item) {
var panel = this.panels[item.options.action];
2022-10-11 19:12:02 +00:00
if (item.options.action === 'help') {
if ( panel.noHelpContents === true && navigator.onLine ) {
this.fireEvent('item:click', [this, 'external-help', true]);
2022-12-11 10:40:41 +00:00
const helpCenter = Common.Utils.InternalSettings.get('url-help-center');
!!helpCenter && window.open(helpCenter, '_blank');
2022-10-11 19:12:02 +00:00
return;
}
}
2016-03-11 00:48:53 +00:00
this.fireEvent('item:click', [this, item.options.action, !!panel]);
if (panel) {
this.$el.find('.content-box:visible').hide();
this.active = item.options.action;
panel.show();
}
}
}, this)
};
},
initialize: function () {
},
render: function () {
2019-08-22 14:43:51 +00:00
var $markup = $(this.template());
2016-03-11 00:48:53 +00:00
this.miClose = new Common.UI.MenuItem({
el : $markup.elementById('#fm-btn-return'),
action : 'back',
caption : this.btnCloseMenuCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
});
2017-07-18 13:33:10 +00:00
this.miSave = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-save'),
2017-07-18 13:33:10 +00:00
action : 'save',
caption : this.btnSaveCaption,
canFocused: false,
disabled: true,
dataHint: 1,
dataHintDirection: 'left-top',
2021-11-12 15:54:49 +00:00
dataHintOffset: [2, 14],
dataHintTitle: 'S'
2017-07-18 13:33:10 +00:00
});
2019-08-22 14:43:51 +00:00
if ( !!this.options.miSave ) {
this.miSave.setDisabled(this.options.miSave.isDisabled());
delete this.options.miSave;
}
2017-07-18 13:33:10 +00:00
this.miEdit = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-edit'),
2017-07-18 13:33:10 +00:00
action : 'edit',
caption : this.btnToEditCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
2017-07-18 13:33:10 +00:00
});
this.miDownload = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-download'),
2017-07-18 13:33:10 +00:00
action : 'saveas',
caption : this.btnDownloadCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
2017-07-18 13:33:10 +00:00
});
this.miSaveCopyAs = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-save-copy'),
action : 'save-copy',
caption : this.btnSaveCopyAsCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
});
2017-07-18 13:33:10 +00:00
this.miSaveAs = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-save-desktop'),
2017-07-18 13:33:10 +00:00
action : 'save-desktop',
caption : this.btnSaveAsCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
2017-07-18 13:33:10 +00:00
});
this.miPrint = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-print'),
2017-07-18 13:33:10 +00:00
action : 'print',
caption : this.btnPrintCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
2021-11-12 15:54:49 +00:00
dataHintOffset: [2, 14],
dataHintTitle: 'P'
2017-07-18 13:33:10 +00:00
});
2022-10-27 12:40:52 +00:00
this.miPrintWithPreview = new Common.UI.MenuItem({
el : $markup.elementById('#fm-btn-print-with-preview'),
action : 'printpreview',
caption : this.btnPrintCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14],
dataHintTitle: 'P'
});
2017-07-18 13:33:10 +00:00
this.miRename = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-rename'),
2017-07-18 13:33:10 +00:00
action : 'rename',
caption : this.btnRenameCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
2017-07-18 13:33:10 +00:00
});
2021-06-28 17:03:50 +00:00
if ( !!this.options.miRename ) {
this.miRename.setDisabled(this.options.miRename.isDisabled());
delete this.options.miRename;
}
2017-07-18 13:33:10 +00:00
this.miProtect = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-protect'),
action : 'protect',
caption : this.btnProtectCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
});
2020-09-07 11:27:35 +00:00
if ( !!this.options.miProtect ) {
this.miProtect.setDisabled(this.options.miProtect.isDisabled());
delete this.options.miProtect;
}
2017-07-18 13:33:10 +00:00
this.miRecent = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-recent'),
2017-07-18 13:33:10 +00:00
action : 'recent',
caption : this.btnRecentFilesCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
2017-07-18 13:33:10 +00:00
});
this.miNew = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-create'),
2017-07-18 13:33:10 +00:00
action : 'new',
caption : this.btnCreateNewCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
2017-07-18 13:33:10 +00:00
});
this.miInfo = new Common.UI.MenuItem({
el : $markup.elementById('#fm-btn-info'),
action : 'info',
caption : this.btnInfoCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
});
2017-07-18 13:33:10 +00:00
this.miAccess = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-rights'),
2017-07-18 13:33:10 +00:00
action : 'rights',
caption : this.btnRightsCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
2017-07-18 13:33:10 +00:00
});
this.miHelp = new Common.UI.MenuItem({
2019-08-22 14:43:51 +00:00
el : $markup.elementById('#fm-btn-help'),
action : 'help',
caption : this.btnHelpCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
});
this.miSettings = new Common.UI.MenuItem({
el : $markup.elementById('#fm-btn-settings'),
action : 'opts',
caption : this.btnSettingsCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
});
2021-03-24 07:39:09 +00:00
this.miHistory = new Common.UI.MenuItem({
el : $markup.elementById('#fm-btn-history'),
action : 'history',
caption : this.btnHistoryCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
2021-03-24 07:39:09 +00:00
});
2021-06-30 22:10:14 +00:00
if ( !!this.options.miHistory ) {
this.miHistory.setDisabled(this.options.miHistory.isDisabled());
delete this.options.miHistory;
}
2021-03-24 07:39:09 +00:00
this.miBack = new Common.UI.MenuItem({
el : $markup.elementById('#fm-btn-back'),
action : 'exit',
caption : this.btnBackCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
});
2016-03-11 00:48:53 +00:00
this.items = [];
this.items.push(
this.miClose,
2017-07-18 13:33:10 +00:00
this.miSave,
this.miEdit,
this.miDownload,
this.miSaveCopyAs,
2017-07-18 13:33:10 +00:00
this.miSaveAs,
this.miPrint,
2022-10-27 12:40:52 +00:00
this.miPrintWithPreview,
2017-07-18 13:33:10 +00:00
this.miRename,
this.miProtect,
2017-07-18 13:33:10 +00:00
this.miRecent,
this.miNew,
this.miInfo,
2017-07-18 13:33:10 +00:00
this.miAccess,
2021-03-24 07:39:09 +00:00
this.miHistory,
this.miSettings,
this.miHelp,
this.miBack
2016-03-11 00:48:53 +00:00
);
2019-08-22 14:43:51 +00:00
this.rendered = true;
this.$el.html($markup);
this.$el.find('.content-box').hide();
2021-07-14 21:35:56 +00:00
if (_.isUndefined(this.scroller)) {
var me = this;
this.scroller = new Common.UI.Scroller({
el: this.$el.find('.panel-menu'),
suppressScrollX: true,
alwaysVisibleY: true
});
Common.NotificationCenter.on('window:resize', function() {
me.scroller.update();
});
}
2019-08-22 14:43:51 +00:00
this.applyMode();
2016-12-13 12:33:28 +00:00
2019-08-22 14:43:51 +00:00
if ( !!this.api ) {
this.panels['info'].setApi(this.api);
2020-07-03 12:15:17 +00:00
if (this.panels['opts']) this.panels['opts'].setApi(this.api);
2019-08-22 14:43:51 +00:00
if ( this.panels['protect'] )
2019-08-27 14:26:14 +00:00
this.panels['protect'].setApi(this.api);
2019-08-22 14:43:51 +00:00
}
2016-03-11 00:48:53 +00:00
return this;
},
2020-08-25 16:38:52 +00:00
show: function(panel, opts) {
if (this.isVisible() && panel===undefined || !this.mode) return;
2016-03-11 00:48:53 +00:00
2019-08-22 14:43:51 +00:00
if ( !this.rendered )
this.render();
var defPanel = (this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline)) ? 'saveas' : 'info';
2016-03-11 00:48:53 +00:00
if (!panel)
panel = this.active || defPanel;
2016-03-11 00:48:53 +00:00
this.$el.show();
2021-07-14 21:35:56 +00:00
this.scroller.update();
2020-08-25 16:38:52 +00:00
this.selectMenu(panel, opts, defPanel);
2019-01-11 11:02:28 +00:00
this.api && this.api.asc_enableKeyEvents(false);
this.fireEvent('menu:show', [this]);
2016-03-11 00:48:53 +00:00
},
hide: function() {
this.$el.hide();
this.fireEvent('menu:hide', [this]);
2019-01-11 11:02:28 +00:00
this.api && this.api.asc_enableKeyEvents(true);
2016-03-11 00:48:53 +00:00
},
applyMode: function() {
2021-06-30 22:10:14 +00:00
if (!this.rendered) return;
2019-08-22 14:43:51 +00:00
if (!this.panels) {
this.panels = {
'opts' : (new PE.Views.FileMenuPanels.Settings({menu:this})).render(this.$el.find('#panel-settings')),
'info' : (new PE.Views.FileMenuPanels.DocumentInfo({menu:this})).render(this.$el.find('#panel-info')),
'rights' : (new PE.Views.FileMenuPanels.DocumentRights({menu:this})).render(this.$el.find('#panel-rights'))
};
}
if (!this.mode) return;
var lastSeparator,
separatorVisible = false;
var isVisible = Common.UI.LayoutManager.isElementVisible('toolbar-file-close');
this.miClose[isVisible?'show':'hide']();
this.miClose.$el.find('+.devider')[isVisible?'show':'hide']();
isVisible && (lastSeparator = this.miClose.$el.find('+.devider'));
2019-08-19 11:49:58 +00:00
this.miDownload[(this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline))?'show':'hide']();
2022-05-25 13:48:17 +00:00
var isBCSupport = Common.Controllers.Desktop.isActive() ? Common.Controllers.Desktop.call("isBlockchainSupport") : false;
this.miSaveCopyAs[(this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline)) && (this.mode.canRequestSaveAs || this.mode.saveAsUrl) && !isBCSupport ?'show':'hide']();
2019-08-19 11:49:58 +00:00
this.miSaveAs[(this.mode.canDownload && this.mode.isDesktopApp && this.mode.isOffline)?'show':'hide']();
2021-11-18 14:46:14 +00:00
this.miSave[this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') ?'show':'hide']();
2019-08-19 11:49:58 +00:00
this.miEdit[!this.mode.isEdit && this.mode.canEdit && this.mode.canRequestEditRights ?'show':'hide']();
2022-10-27 12:40:52 +00:00
this.miPrint[this.mode.canPrint && !this.mode.canPreviewPrint ?'show':'hide']();
this.miPrintWithPreview[this.mode.canPreviewPrint?'show':'hide']();
2017-07-18 13:33:10 +00:00
this.miRename[(this.mode.canRename && !this.mode.isDesktopApp) ?'show':'hide']();
this.miProtect[this.mode.canProtect ?'show':'hide']();
2021-11-18 14:46:14 +00:00
separatorVisible = (this.mode.canDownload || this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') || this.mode.canPrint || this.mode.canProtect ||
!this.mode.isEdit && this.mode.canEdit && this.mode.canRequestEditRights || this.mode.canRename && !this.mode.isDesktopApp) && !this.mode.isDisconnected;
this.miProtect.$el.find('+.devider')[separatorVisible?'show':'hide']();
separatorVisible && (lastSeparator = this.miProtect.$el.find('+.devider'));
2017-07-18 13:33:10 +00:00
this.miRecent[this.mode.canOpenRecent?'show':'hide']();
this.miNew[this.mode.canCreateNew?'show':'hide']();
separatorVisible = this.mode.canCreateNew;
this.miNew.$el.find('+.devider')[separatorVisible?'show':'hide']();
separatorVisible && (lastSeparator = this.miNew.$el.find('+.devider'));
isVisible = Common.UI.LayoutManager.isElementVisible('toolbar-file-info');
separatorVisible = isVisible;
this.miInfo[isVisible?'show':'hide']();
isVisible = !this.mode.isOffline && this.document&&this.document.info &&
(this.document.info.sharingSettings&&this.document.info.sharingSettings.length>0 ||
(this.mode.sharingSettingsUrl&&this.mode.sharingSettingsUrl.length || this.mode.canRequestSharingSettings));
separatorVisible = separatorVisible || isVisible;
this.miAccess[isVisible?'show':'hide']();
isVisible = this.mode.canUseHistory&&!this.mode.isDisconnected;
separatorVisible = separatorVisible || isVisible;
this.miHistory[isVisible?'show':'hide']();
this.miHistory.$el.find('+.devider')[separatorVisible?'show':'hide']();
separatorVisible && (lastSeparator = this.miHistory.$el.find('+.devider'));
isVisible = Common.UI.LayoutManager.isElementVisible('toolbar-file-settings');
this.miSettings[isVisible?'show':'hide']();
this.miSettings.$el.find('+.devider')[isVisible?'show':'hide']();
isVisible && (lastSeparator = this.miSettings.$el.find('+.devider'));
isVisible = this.mode.canHelp;
this.miHelp[isVisible ?'show':'hide']();
this.miHelp.$el.find('+.devider')[isVisible?'show':'hide']();
isVisible && (lastSeparator = this.miHelp.$el.find('+.devider'));
isVisible = this.mode.canBack;
this.miBack[isVisible ?'show':'hide']();
lastSeparator && !isVisible && lastSeparator.hide();
2016-03-11 00:48:53 +00:00
2020-01-31 14:25:22 +00:00
if (!this.customizationDone) {
this.customizationDone = true;
Common.Utils.applyCustomization(this.mode.customization, {goback: '#fm-btn-back > a'});
}
2016-03-11 00:48:53 +00:00
this.panels['opts'].setMode(this.mode);
this.panels['info'].setMode(this.mode);
!this.mode.isDisconnected && this.panels['info'].updateInfo(this.document);
this.panels['rights'].setMode(this.mode);
!this.mode.isDisconnected && this.panels['rights'].updateInfo(this.document);
2016-03-11 00:48:53 +00:00
if ( this.mode.canCreateNew ) {
if (this.mode.templates && this.mode.templates.length) {
!this.panels['new'] && (this.panels['new'] = (new PE.Views.FileMenuPanels.CreateNew({menu: this, docs: this.mode.templates, blank: this.mode.canRequestCreateNew || !!this.mode.createUrl})).render());
2016-03-11 00:48:53 +00:00
}
}
2019-08-22 14:43:51 +00:00
if ( this.mode.canOpenRecent && this.mode.recent ) {
!this.panels['recent'] && (this.panels['recent'] = (new PE.Views.FileMenuPanels.RecentFiles({menu:this, recent: this.mode.recent})).render());
2016-03-11 00:48:53 +00:00
}
if (this.mode.canProtect) {
2019-08-22 14:43:51 +00:00
!this.panels['protect'] && (this.panels['protect'] = (new PE.Views.FileMenuPanels.ProtectDoc({menu:this})).render());
this.panels['protect'].setMode(this.mode);
2016-03-11 00:48:53 +00:00
}
2019-07-26 09:54:20 +00:00
if (this.mode.canDownload) {
2021-07-20 18:30:09 +00:00
!this.panels['saveas'] && (this.panels['saveas'] = ((new PE.Views.FileMenuPanels.ViewSaveAs({menu: this, fileType: this.document.fileType})).render()));
2019-07-26 09:54:20 +00:00
}
if (this.mode.canDownload && (this.mode.canRequestSaveAs || this.mode.saveAsUrl)) {
2021-07-20 18:30:09 +00:00
!this.panels['save-copy'] && (this.panels['save-copy'] = ((new PE.Views.FileMenuPanels.ViewSaveCopy({menu: this, fileType: this.document.fileType})).render()));
2019-07-26 09:54:20 +00:00
}
2019-08-22 14:43:51 +00:00
if (this.mode.canHelp && !this.panels['help']) {
this.panels['help'] = ((new PE.Views.FileMenuPanels.Help({menu: this})).render());
this.panels['help'].setLangConfig(this.mode.lang);
}
2021-03-24 07:39:09 +00:00
2022-10-27 12:40:52 +00:00
if (this.mode.canPreviewPrint) {
var printPanel = PE.getController('Print').getView('PrintWithPreview');
printPanel.menu = this;
!this.panels['printpreview'] && (this.panels['printpreview'] = printPanel.render(this.$el.find('#panel-print')));
}
2021-11-30 17:13:56 +00:00
if ( Common.Controllers.Desktop.isActive() ) {
$('<li id="fm-btn-local-open" class="fm-btn"/>').insertAfter($('#fm-btn-recent', this.$el));
this.items.push(
new Common.UI.MenuItem({
el : $('#fm-btn-local-open', this.$el),
action : 'file:open',
caption : this.btnFileOpenCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
}));
$('<li class="devider" />' +
'<li id="fm-btn-exit" class="fm-btn"/>').insertAfter($('#fm-btn-back', this.$el));
this.items.push(
new Common.UI.MenuItem({
el : $('#fm-btn-exit', this.$el),
action : 'file:exit',
caption : this.btnExitCaption,
canFocused: false,
dataHint: 1,
dataHintDirection: 'left-top',
dataHintOffset: [2, 14]
}));
}
2016-03-11 00:48:53 +00:00
},
setMode: function(mode, delay) {
if (mode.isDisconnected) {
this.mode.canEdit = this.mode.isEdit = false;
this.mode.canOpenRecent = this.mode.canCreateNew = false;
this.mode.isDisconnected = mode.isDisconnected;
2016-09-27 12:09:32 +00:00
this.mode.canRename = false;
if (!mode.enableDownload)
this.mode.canPrint = this.mode.canDownload = false;
2016-03-11 00:48:53 +00:00
} else {
this.mode = mode;
}
2019-08-22 14:43:51 +00:00
if (!delay) {
2021-06-30 22:10:14 +00:00
this.applyMode();
2019-08-22 14:43:51 +00:00
}
2016-03-11 00:48:53 +00:00
},
setApi: function(api) {
this.api = api;
2019-08-22 14:43:51 +00:00
if ( this.rendered ) {
this.panels['info'].setApi(api);
2020-07-03 12:15:17 +00:00
if (this.panels['opts']) this.panels['opts'].setApi(api);
2019-08-22 14:43:51 +00:00
if (this.panels['protect']) this.panels['protect'].setApi(api);
}
2016-03-11 00:48:53 +00:00
this.api.asc_registerCallback('asc_onDocumentName', _.bind(this.onDocumentName, this));
2019-08-22 14:43:51 +00:00
return this;
2016-03-11 00:48:53 +00:00
},
loadDocument: function(data) {
this.document = data.doc;
},
2020-08-25 16:38:52 +00:00
selectMenu: function(menu, opts, defMenu) {
2016-03-11 00:48:53 +00:00
if ( menu ) {
var item = this._getMenuItem(menu),
2016-03-11 00:48:53 +00:00
panel = this.panels[menu];
if ( item.isDisabled() || !item.isVisible()) {
item = this._getMenuItem(defMenu);
panel = this.panels[defMenu];
}
2016-03-11 00:48:53 +00:00
if ( item && panel ) {
$('.fm-btn',this.el).removeClass('active');
item.$el.addClass('active');
this.$el.find('.content-box:visible').hide();
2020-08-25 16:38:52 +00:00
panel.show(opts);
2016-03-11 00:48:53 +00:00
2021-07-14 21:35:56 +00:00
if (this.scroller) {
var itemTop = item.$el.position().top,
itemHeight = item.$el.outerHeight(),
listHeight = this.$el.outerHeight();
if (itemTop < 0 || itemTop + itemHeight > listHeight) {
var height = this.scroller.$el.scrollTop() + itemTop + (itemHeight - listHeight)/2;
height = (Math.floor(height/itemHeight) * itemHeight);
this.scroller.scrollTop(height);
}
}
2016-03-11 00:48:53 +00:00
this.active = menu;
}
}
},
disableMenu: function(menu, status) {
if ( menu ) {
var item = this._getMenuItem(menu);
if ( item ) {
item.setDisabled(status);
}
}
},
_getMenuItem: function(action) {
return _.find(this.items, function(item) {
return item.options.action == action;
});
},
onDocumentName: function(name) {
this.document.title = name;
2019-08-22 14:43:51 +00:00
if (this.rendered)
this.panels['info'].updateInfo(this.document);
2016-03-11 00:48:53 +00:00
},
2017-04-20 13:34:39 +00:00
isVisible: function () {
return !this.$el.is(':hidden');
},
getButton: function(type) {
2020-09-07 11:27:35 +00:00
if ( !this.rendered ) {
if (type == 'save') {
2019-08-22 14:43:51 +00:00
return this.options.miSave ? this.options.miSave : (this.options.miSave = new Common.UI.MenuItem({}));
2020-09-07 11:27:35 +00:00
} else
2021-03-24 07:39:09 +00:00
if (type == 'rename') {
return this.options.miRename ? this.options.miRename : (this.options.miRename = new Common.UI.MenuItem({}));
} else
2020-09-07 11:27:35 +00:00
if (type == 'protect') {
return this.options.miProtect ? this.options.miProtect : (this.options.miProtect = new Common.UI.MenuItem({}));
2021-06-30 22:10:14 +00:00
} else
if (type == 'history') {
return this.options.miHistory ? this.options.miHistory : (this.options.miHistory = new Common.UI.MenuItem({}));
2020-09-07 11:27:35 +00:00
}
} else {
if (type == 'save') {
return this.miSave;
} else
2021-03-24 07:39:09 +00:00
if (type == 'rename') {
return this.miRename;
} else
2020-09-07 11:27:35 +00:00
if (type == 'protect') {
return this.miProtect;
2021-06-30 22:10:14 +00:00
}else
if (type == 'history') {
return this.miHistory;
2020-09-07 11:27:35 +00:00
}
2019-08-22 14:43:51 +00:00
}
},
2021-06-30 22:10:14 +00:00
SetDisabled: function(disable, options) {
var _btn_protect = this.getButton('protect'),
_btn_history = this.getButton('history');
2021-03-24 07:39:09 +00:00
2021-06-30 22:10:14 +00:00
options && options.protect && _btn_protect.setDisabled(disable);
options && options.history && _btn_history.setDisabled(disable);
2021-03-24 07:39:09 +00:00
},
2016-03-11 00:48:53 +00:00
btnSaveCaption : 'Save',
btnDownloadCaption : 'Download as...',
btnInfoCaption : 'Document Info...',
btnRightsCaption : 'Access Rights...',
btnCreateNewCaption : 'Create New',
btnRecentFilesCaption : 'Open Recent...',
btnPrintCaption : 'Print',
btnHelpCaption : 'Help...',
btnReturnCaption : 'Back to Document',
btnToEditCaption : 'Edit Document',
btnBackCaption : 'Go to Documents',
btnSettingsCaption : 'Advanced Settings...',
2016-09-27 12:09:32 +00:00
btnSaveAsCaption : 'Save as',
btnRenameCaption : 'Rename...',
2017-11-27 11:15:10 +00:00
btnCloseMenuCaption : 'Close Menu',
btnProtectCaption: 'Protect',
2021-03-24 07:39:09 +00:00
btnSaveCopyAsCaption : 'Save Copy as...',
2021-11-30 17:13:56 +00:00
btnHistoryCaption : 'Versions History',
btnExitCaption : 'Exit',
btnFileOpenCaption : 'Open...'
2016-03-11 00:48:53 +00:00
}, PE.Views.FileMenu || {}));
});