web-apps/apps/presentationeditor/main/app/controller/RightMenu.js

365 lines
18 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
/**
* RightMenu.js
*
* Created by Julia Radzhabova on 4/10/14
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',
'presentationeditor/main/app/view/RightMenu'
], function () {
'use strict';
PE.Controllers.RightMenu = Backbone.Controller.extend({
models: [],
collections: [],
views: [
'RightMenu'
],
initialize: function() {
this.editMode = true;
this._state = {no_slides: undefined};
2020-11-11 14:46:13 +00:00
this._initSettings = true;
2022-02-02 14:46:48 +00:00
this._priorityArr = [];
2016-03-11 00:48:53 +00:00
this.addListeners({
'RightMenu': {
'rightmenuclick': this.onRightMenuClick
}
});
},
onLaunch: function() {
this.rightmenu = this.createView('RightMenu');
this.rightmenu.on('render:after', _.bind(this.onRightMenuAfterRender, this));
},
onRightMenuAfterRender: function(rightMenu) {
2021-11-05 00:35:05 +00:00
rightMenu.imageSettings.application = rightMenu.shapeSettings.application = rightMenu.textartSettings.application = this.getApplication();
2016-03-11 00:48:53 +00:00
this._settings = [];
this._settings[Common.Utils.documentSettingsType.Paragraph] = {panelId: "id-paragraph-settings", panel: rightMenu.paragraphSettings,btn: rightMenu.btnText, hidden: 1, locked: false};
this._settings[Common.Utils.documentSettingsType.Table] = {panelId: "id-table-settings", panel: rightMenu.tableSettings, btn: rightMenu.btnTable, hidden: 1, locked: false};
this._settings[Common.Utils.documentSettingsType.Image] = {panelId: "id-image-settings", panel: rightMenu.imageSettings, btn: rightMenu.btnImage, hidden: 1, locked: false};
this._settings[Common.Utils.documentSettingsType.Slide] = {panelId: "id-slide-settings", panel: rightMenu.slideSettings, btn: rightMenu.btnSlide, hidden: 1, locked: false};
this._settings[Common.Utils.documentSettingsType.Shape] = {panelId: "id-shape-settings", panel: rightMenu.shapeSettings, btn: rightMenu.btnShape, hidden: 1, locked: false};
this._settings[Common.Utils.documentSettingsType.TextArt] = {panelId: "id-textart-settings", panel: rightMenu.textartSettings, btn: rightMenu.btnTextArt, hidden: 1, locked: false};
this._settings[Common.Utils.documentSettingsType.Chart] = {panelId: "id-chart-settings", panel: rightMenu.chartSettings, btn: rightMenu.btnChart, hidden: 1, locked: false};
this._settings[Common.Utils.documentSettingsType.Signature] = {panelId: "id-signature-settings", panel: rightMenu.signatureSettings, btn: rightMenu.btnSignature, hidden: 1, props: {}, locked: false};
2016-03-11 00:48:53 +00:00
},
setApi: function(api) {
this.api = api;
this.api.asc_registerCallback('asc_onUpdateSignatures', _.bind(this.onApiUpdateSignatures, this));
2016-03-11 00:48:53 +00:00
this.api.asc_registerCallback('asc_onCountPages', _.bind(this.onApiCountPages, this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
},
setMode: function(mode) {
this.editMode = mode.isEdit;
},
2022-02-02 14:46:48 +00:00
onRightMenuClick: function(menu, type, minimized, event) {
2016-03-11 00:48:53 +00:00
if (!minimized && this.editMode) {
2022-02-02 14:46:48 +00:00
if (event) { // user click event
var idx = this._priorityArr.indexOf(type);
if (idx>=0)
this._priorityArr.splice(idx, 1);
this._priorityArr.unshift(type);
}
2016-03-11 00:48:53 +00:00
var panel = this._settings[type].panel;
var props = this._settings[type].props;
if (props && panel)
2017-09-13 08:57:30 +00:00
panel.ChangeSettings.call(panel, (type==Common.Utils.documentSettingsType.Signature) ? undefined : props);
2016-03-11 00:48:53 +00:00
}
Common.NotificationCenter.trigger('layout:changed', 'rightmenu');
this.rightmenu.fireEvent('editcomplete', this.rightmenu);
},
2021-08-30 20:12:11 +00:00
onFocusObject: function(SelectedObjects, forceSignature) {
if (!this.editMode && !forceSignature)
2016-03-11 00:48:53 +00:00
return;
2020-11-11 14:46:13 +00:00
var open = this._initSettings ? !Common.localStorage.getBool("pe-hide-right-settings", this.rightmenu.defaultHideRightMenu) : false;
this._initSettings = false;
2016-03-11 00:48:53 +00:00
var needhide = true;
for (var i=0; i<this._settings.length; i++) {
2017-09-13 08:57:30 +00:00
if (i==Common.Utils.documentSettingsType.Signature) continue;
2016-03-11 00:48:53 +00:00
if (this._settings[i]) {
this._settings[i].hidden = 1;
this._settings[i].locked = undefined;
}
}
2016-11-15 08:55:49 +00:00
this._settings[Common.Utils.documentSettingsType.Slide].hidden = (SelectedObjects.length>0) ? 0 : 1;
2017-09-13 08:57:30 +00:00
this._settings[Common.Utils.documentSettingsType.Signature].locked = false;
2016-03-11 00:48:53 +00:00
for (i=0; i<SelectedObjects.length; i++)
{
var eltype = SelectedObjects[i].get_ObjectType(),
settingsType = this.getDocumentSettingsType(eltype);
if (settingsType===undefined || settingsType>=this._settings.length || this._settings[settingsType]===undefined)
continue;
var value = SelectedObjects[i].get_ObjectValue();
this._settings[settingsType].props = value;
this._settings[settingsType].hidden = 0;
if (settingsType==Common.Utils.documentSettingsType.Slide) {
this._settings[settingsType].locked = value.get_LockDelete();
this._settings[settingsType].lockedBackground = value.get_LockBackground();
2021-08-07 15:44:26 +00:00
/*this._settings[settingsType].lockedEffects = value.get_LockTransition();
this._settings[settingsType].lockedTransition = value.get_LockTransition();*/
this._settings[settingsType].lockedHeader = !!value.get_LockHeader && value.get_LockHeader();
2016-03-11 00:48:53 +00:00
} else {
this._settings[settingsType].locked = value.get_Locked();
if (settingsType == Common.Utils.documentSettingsType.Shape && value.asc_getTextArtProperties()) {
this._settings[Common.Utils.documentSettingsType.TextArt].props = value;
this._settings[Common.Utils.documentSettingsType.TextArt].hidden = 0;
this._settings[Common.Utils.documentSettingsType.TextArt].locked = value.get_Locked();
}
}
}
if ( this._settings[Common.Utils.documentSettingsType.Slide].locked ) { // если находимся в locked slide, то считаем, что все элементы в нем тоже недоступны
for (i=0; i<this._settings.length; i++) {
if (this._settings[i])
this._settings[i].locked = true;
}
}
var lastactive = -1, currentactive, priorityactive = -1,
activePane = this.rightmenu.GetActivePane();
2016-03-11 00:48:53 +00:00
for (i=0; i<this._settings.length; i++) {
var pnl = this._settings[i];
2017-09-13 08:57:30 +00:00
if (pnl===undefined || pnl.btn===undefined || pnl.panel===undefined) continue;
2016-03-11 00:48:53 +00:00
if ( pnl.hidden ) {
if (!pnl.btn.isDisabled()) pnl.btn.setDisabled(true);
if (activePane == pnl.panelId)
2016-03-11 00:48:53 +00:00
currentactive = -1;
} else {
if (pnl.btn.isDisabled()) pnl.btn.setDisabled(false);
2017-09-13 08:57:30 +00:00
if ( i!=Common.Utils.documentSettingsType.Slide && i!=Common.Utils.documentSettingsType.Signature)
2016-03-11 00:48:53 +00:00
lastactive = i;
if ( pnl.needShow ) {
pnl.needShow = false;
priorityactive = i;
} else if ( i != Common.Utils.documentSettingsType.Slide || this.rightmenu._settings[i].isCurrent) {
if (activePane == pnl.panelId)
2016-03-11 00:48:53 +00:00
currentactive = i;
}
if (i == Common.Utils.documentSettingsType.Slide) {
if (pnl.locked!==undefined)
2020-09-10 17:24:13 +00:00
this.rightmenu.slideSettings.setLocked(this._state.no_slides || pnl.lockedBackground || pnl.locked,
this._state.no_slides || pnl.lockedHeader || pnl.locked);
2016-03-11 00:48:53 +00:00
} else
pnl.panel.setLocked(pnl.locked);
}
}
if (!this.rightmenu.minimizedMode || open) {
2016-03-11 00:48:53 +00:00
var active;
2022-02-02 14:46:48 +00:00
if (priorityactive<0 && this._priorityArr.length>0) {
for (i=0; i<this._priorityArr.length; i++) {
var type = this._priorityArr[i],
pnl = this._settings[type];
if (pnl===undefined || pnl.btn===undefined || pnl.panel===undefined || pnl.hidden) continue;
priorityactive = type;
break;
}
}
2016-03-11 00:48:53 +00:00
if (priorityactive>-1) active = priorityactive;
else if (currentactive>=0) active = currentactive;
else if (lastactive>=0) active = lastactive;
2021-08-30 20:12:11 +00:00
else if (forceSignature && !this._settings[Common.Utils.documentSettingsType.Signature].hidden) active = Common.Utils.documentSettingsType.Signature;
2016-03-11 00:48:53 +00:00
else active = Common.Utils.documentSettingsType.Slide;
if (active !== undefined) {
this.rightmenu.SetActivePane(active, open);
2017-09-13 08:57:30 +00:00
if (active!=Common.Utils.documentSettingsType.Signature)
this._settings[active].panel.ChangeSettings.call(this._settings[active].panel, this._settings[active].props);
else
this._settings[active].panel.ChangeSettings.call(this._settings[active].panel);
2016-03-11 00:48:53 +00:00
}
}
this._settings[Common.Utils.documentSettingsType.Image].needShow = false;
this._settings[Common.Utils.documentSettingsType.Chart].needShow = false;
this._settings[Common.Utils.documentSettingsType.Shape].needShow = false;
},
onCoAuthoringDisconnect: function() {
this.SetDisabled(true);
2016-03-11 00:48:53 +00:00
this.setMode({isEdit: false});
},
SetDisabled: function(disabled, allowSignature) {
this.setMode({isEdit: !disabled});
2020-11-09 11:52:21 +00:00
if (this.rightmenu && this.rightmenu.paragraphSettings) {
2021-08-07 15:44:26 +00:00
this.rightmenu.slideSettings.SetSlideDisabled(disabled, disabled);
this.rightmenu.paragraphSettings.disableControls(disabled);
this.rightmenu.shapeSettings.disableControls(disabled);
this.rightmenu.textartSettings.disableControls(disabled);
this.rightmenu.tableSettings.disableControls(disabled);
this.rightmenu.imageSettings.disableControls(disabled);
this.rightmenu.chartSettings.disableControls(disabled);
2021-08-30 20:12:11 +00:00
if (this.rightmenu.signatureSettings) {
!allowSignature && this.rightmenu.btnSignature.setDisabled(disabled);
allowSignature && disabled && this.onFocusObject([], true); // force press signature button
}
if (disabled) {
this.rightmenu.btnSlide.setDisabled(disabled);
this.rightmenu.btnText.setDisabled(disabled);
this.rightmenu.btnTable.setDisabled(disabled);
this.rightmenu.btnImage.setDisabled(disabled);
this.rightmenu.btnShape.setDisabled(disabled);
this.rightmenu.btnTextArt.setDisabled(disabled);
this.rightmenu.btnChart.setDisabled(disabled);
} else {
var selectedElements = this.api.getSelectedElements();
if (selectedElements.length > 0)
this.onFocusObject(selectedElements);
}
}
},
2016-03-11 00:48:53 +00:00
onInsertTable: function() {
2022-02-02 14:46:48 +00:00
// this._settings[Common.Utils.documentSettingsType.Table].needShow = true;
2016-03-11 00:48:53 +00:00
},
onInsertImage: function() {
2022-02-02 14:46:48 +00:00
// this._settings[Common.Utils.documentSettingsType.Image].needShow = true;
2016-03-11 00:48:53 +00:00
},
onInsertChart: function() {
2022-02-02 14:46:48 +00:00
// this._settings[Common.Utils.documentSettingsType.Chart].needShow = true;
2016-03-11 00:48:53 +00:00
},
onInsertShape: function() {
2022-02-02 14:46:48 +00:00
// this._settings[Common.Utils.documentSettingsType.Shape].needShow = true;
2016-03-11 00:48:53 +00:00
},
onInsertTextArt: function() {
2022-02-02 14:46:48 +00:00
// this._settings[Common.Utils.documentSettingsType.TextArt].needShow = true;
2016-03-11 00:48:53 +00:00
},
UpdateThemeColors: function() {
this.rightmenu.slideSettings.UpdateThemeColors();
this.rightmenu.tableSettings.UpdateThemeColors();
this.rightmenu.shapeSettings.UpdateThemeColors();
this.rightmenu.textartSettings.UpdateThemeColors();
},
updateMetricUnit: function() {
this.rightmenu.paragraphSettings.updateMetricUnit();
this.rightmenu.chartSettings.updateMetricUnit();
this.rightmenu.imageSettings.updateMetricUnit();
this.rightmenu.tableSettings.updateMetricUnit();
2016-03-11 00:48:53 +00:00
},
createDelayedElements: function() {
if (this.editMode && this.api) {
this.api.asc_registerCallback('asc_doubleClickOnObject', _.bind(this.onDoubleClickOnObject, this));
// this.rightmenu.shapeSettings.createDelayedElements();
2016-03-11 00:48:53 +00:00
var selectedElements = this.api.getSelectedElements();
if (selectedElements.length>0) {
2020-11-11 14:46:13 +00:00
this.onFocusObject(selectedElements);
}
2016-03-11 00:48:53 +00:00
}
},
onDoubleClickOnObject: function(obj) {
if (!this.editMode) return;
var eltype = obj.get_ObjectType(),
settingsType = this.getDocumentSettingsType(eltype);
if (settingsType===undefined || settingsType>=this._settings.length || this._settings[settingsType]===undefined)
return;
if (settingsType !== Common.Utils.documentSettingsType.Paragraph) {
this.rightmenu.SetActivePane(settingsType, true);
this._settings[settingsType].panel.ChangeSettings.call(this._settings[settingsType].panel, this._settings[settingsType].props);
}
},
onApiUpdateSignatures: function(valid){
if (!this.rightmenu.signatureSettings) return;
var disabled = (!valid || valid.length<1),
type = Common.Utils.documentSettingsType.Signature;
this._settings[type].hidden = disabled ? 1 : 0;
this._settings[type].btn.setDisabled(disabled);
this._settings[type].panel.setLocked(this._settings[type].locked);
},
2016-03-11 00:48:53 +00:00
onApiCountPages: function(count) {
if (this._state.no_slides !== (count<=0) && this.editMode) {
this._state.no_slides = (count<=0);
if ( this._state.no_slides && !this.rightmenu.minimizedMode)
this.rightmenu.clearSelection();
this._settings[Common.Utils.documentSettingsType.Slide].btn.setDisabled(this._state.no_slides);
}
},
getDocumentSettingsType: function(type) {
switch (type) {
case Asc.c_oAscTypeSelectElement.Paragraph:
2016-03-11 00:48:53 +00:00
return Common.Utils.documentSettingsType.Paragraph;
case Asc.c_oAscTypeSelectElement.Table:
2016-03-11 00:48:53 +00:00
return Common.Utils.documentSettingsType.Table;
case Asc.c_oAscTypeSelectElement.Image:
2016-03-11 00:48:53 +00:00
return Common.Utils.documentSettingsType.Image;
case Asc.c_oAscTypeSelectElement.Shape:
2016-03-11 00:48:53 +00:00
return Common.Utils.documentSettingsType.Shape;
case Asc.c_oAscTypeSelectElement.Slide:
2016-03-11 00:48:53 +00:00
return Common.Utils.documentSettingsType.Slide;
case Asc.c_oAscTypeSelectElement.Chart:
2016-03-11 00:48:53 +00:00
return Common.Utils.documentSettingsType.Chart;
}
}
});
});