2016-04-01 13:17:09 +00:00
|
|
|
/*
|
|
|
|
*
|
2019-01-17 13:05:03 +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
|
|
|
|
*
|
2019-01-17 13:00:34 +00:00
|
|
|
* 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
|
|
|
/**
|
|
|
|
* CellEditor.js
|
|
|
|
*
|
|
|
|
* CellEditor Controller
|
|
|
|
*
|
|
|
|
* Created by Maxim Kadushkin on 08 April 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',
|
|
|
|
'spreadsheeteditor/main/app/view/CellEditor',
|
|
|
|
'spreadsheeteditor/main/app/view/NameManagerDlg'
|
|
|
|
], function (Viewport) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
SSE.Controllers.CellEditor = Backbone.Controller.extend({
|
|
|
|
views: [
|
|
|
|
'CellEditor'
|
|
|
|
],
|
|
|
|
|
|
|
|
events: function() {
|
|
|
|
return {
|
|
|
|
'keyup input#ce-cell-name': _.bind(this.onCellName,this),
|
|
|
|
'keyup textarea#ce-cell-content': _.bind(this.onKeyupCellEditor,this),
|
|
|
|
'blur textarea#ce-cell-content': _.bind(this.onBlurCellEditor,this),
|
|
|
|
'click button#ce-btn-expand': _.bind(this.expandEditorField,this),
|
|
|
|
'click button#ce-func-label': _.bind(this.onInsertFunction, this)
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
this.addListeners({
|
|
|
|
'CellEditor': {},
|
|
|
|
'Viewport': {
|
|
|
|
'layout:resizedrag': _.bind(this.onLayoutResize, this)
|
2018-03-21 11:28:28 +00:00
|
|
|
},
|
2022-02-06 11:50:17 +00:00
|
|
|
'ViewTab': {
|
|
|
|
'viewtab:formula': function (type, state) {
|
|
|
|
this.editor.setVisible(state);
|
|
|
|
Common.localStorage.setBool('sse-hidden-formula', !state);
|
|
|
|
Common.NotificationCenter.trigger('layout:changed', 'celleditor', !state?'hidden':'showed');
|
2018-03-21 11:28:28 +00:00
|
|
|
}.bind(this)
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setApi: function(api) {
|
|
|
|
this.api = api;
|
|
|
|
|
|
|
|
this.api.isCEditorFocused = false;
|
|
|
|
this.api.asc_registerCallback('asc_onSelectionNameChanged', _.bind(this.onApiCellSelection, this));
|
|
|
|
this.api.asc_registerCallback('asc_onEditCell', _.bind(this.onApiEditCell, this));
|
|
|
|
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(this.onApiDisconnect,this));
|
|
|
|
Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiDisconnect, this));
|
|
|
|
Common.NotificationCenter.on('cells:range', _.bind(this.onCellsRange, this));
|
|
|
|
this.api.asc_registerCallback('asc_onLockDefNameManager', _.bind(this.onLockDefNameManager, this));
|
2016-07-22 14:16:08 +00:00
|
|
|
this.api.asc_registerCallback('asc_onInputKeyDown', _.bind(this.onInputKeyDown, this));
|
2016-03-11 00:48:53 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setMode: function(mode) {
|
|
|
|
this.mode = mode;
|
|
|
|
|
|
|
|
this.editor.$btnfunc[this.mode.isEdit?'removeClass':'addClass']('disabled');
|
|
|
|
this.editor.btnNamedRanges.setVisible(this.mode.isEdit && !this.mode.isEditDiagram && !this.mode.isEditMailMerge);
|
2017-04-28 12:22:37 +00:00
|
|
|
|
|
|
|
if ( this.mode.isEdit ) {
|
|
|
|
this.api.asc_registerCallback('asc_onSelectionChanged', _.bind(this.onApiSelectionChanged, this));
|
|
|
|
}
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
|
2016-07-22 14:16:08 +00:00
|
|
|
onInputKeyDown: function(e) {
|
|
|
|
if (Common.UI.Keys.UP === e.keyCode || Common.UI.Keys.DOWN === e.keyCode ||
|
2016-07-22 15:27:22 +00:00
|
|
|
Common.UI.Keys.TAB === e.keyCode || Common.UI.Keys.RETURN === e.keyCode || Common.UI.Keys.ESC === e.keyCode ||
|
|
|
|
Common.UI.Keys.LEFT === e.keyCode || Common.UI.Keys.RIGHT === e.keyCode) {
|
2016-07-22 14:16:08 +00:00
|
|
|
var menu = $('#menu-formula-selection'); // for formula menu
|
|
|
|
if (menu.hasClass('open'))
|
|
|
|
menu.find('.dropdown-menu').trigger('keydown', e);
|
2016-07-22 15:27:22 +00:00
|
|
|
}
|
2016-07-22 14:16:08 +00:00
|
|
|
},
|
|
|
|
|
2016-03-11 00:48:53 +00:00
|
|
|
onLaunch: function() {
|
2019-10-04 14:12:54 +00:00
|
|
|
this.editor = this.getView('CellEditor');
|
2016-03-11 00:48:53 +00:00
|
|
|
this.bindViewEvents(this.editor, this.events);
|
|
|
|
|
|
|
|
this.editor.$el.parent().find('.after').css({zIndex: '4'}); // for spreadsheets - bug 23127
|
2019-10-17 14:03:31 +00:00
|
|
|
|
|
|
|
var val = Common.localStorage.getItem('sse-celleditor-height');
|
|
|
|
this.editor.keep_height = (val!==null && parseInt(val)>0) ? parseInt(val) : 74;
|
|
|
|
if (Common.localStorage.getBool('sse-celleditor-expand')) {
|
|
|
|
this.editor.$el.height(this.editor.keep_height);
|
|
|
|
this.onLayoutResize(undefined, 'cell:edit');
|
|
|
|
}
|
|
|
|
|
2016-03-11 00:48:53 +00:00
|
|
|
this.editor.btnNamedRanges.menu.on('item:click', _.bind(this.onNamedRangesMenu, this))
|
|
|
|
.on('show:before', _.bind(this.onNameBeforeShow, this));
|
|
|
|
this.namedrange_locked = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onApiEditCell: function(state) {
|
2021-02-16 11:49:13 +00:00
|
|
|
if (this.viewmode) return; // signed file
|
|
|
|
|
2016-08-16 12:32:12 +00:00
|
|
|
if (state == Asc.c_oAscCellEditorState.editStart){
|
2016-03-11 00:48:53 +00:00
|
|
|
this.api.isCellEdited = true;
|
2016-08-16 12:32:12 +00:00
|
|
|
this.editor.cellNameDisabled(true);
|
2018-09-10 09:50:06 +00:00
|
|
|
} else if (state == Asc.c_oAscCellEditorState.editInCell) {
|
|
|
|
this.api.isCEditorFocused = 'clear';
|
2016-08-16 12:32:12 +00:00
|
|
|
} else if (state == Asc.c_oAscCellEditorState.editEnd) {
|
2016-03-11 00:48:53 +00:00
|
|
|
this.api.isCellEdited = false;
|
|
|
|
this.api.isCEditorFocused = false;
|
2016-08-16 12:32:12 +00:00
|
|
|
this.editor.cellNameDisabled(false);
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
2016-11-29 11:59:05 +00:00
|
|
|
this.editor.$btnfunc.toggleClass('disabled', state == Asc.c_oAscCellEditorState.editText);
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onApiCellSelection: function(info) {
|
|
|
|
this.editor.updateCellInfo(info);
|
|
|
|
},
|
|
|
|
|
2017-04-28 12:22:37 +00:00
|
|
|
onApiSelectionChanged: function(info) {
|
2021-02-16 11:49:13 +00:00
|
|
|
if (this.viewmode) return; // signed file
|
|
|
|
|
2020-05-14 08:39:04 +00:00
|
|
|
var seltype = info.asc_getSelectionType(),
|
2019-10-04 13:17:05 +00:00
|
|
|
coauth_disable = (!this.mode.isEditMailMerge && !this.mode.isEditDiagram) ? (info.asc_getLocked() === true || info.asc_getLockedTable() === true || info.asc_getLockedPivotTable()===true) : false;
|
2017-04-28 12:22:37 +00:00
|
|
|
|
|
|
|
var is_chart_text = seltype == Asc.c_oAscSelectionType.RangeChartText,
|
|
|
|
is_chart = seltype == Asc.c_oAscSelectionType.RangeChart,
|
|
|
|
is_shape_text = seltype == Asc.c_oAscSelectionType.RangeShapeText,
|
|
|
|
is_shape = seltype == Asc.c_oAscSelectionType.RangeShape,
|
2020-06-05 16:28:11 +00:00
|
|
|
is_image = seltype == Asc.c_oAscSelectionType.RangeImage || seltype == Asc.c_oAscSelectionType.RangeSlicer,
|
2017-04-28 12:22:37 +00:00
|
|
|
is_mode_2 = is_shape_text || is_shape || is_chart_text || is_chart;
|
|
|
|
|
|
|
|
this.editor.$btnfunc.toggleClass('disabled', is_image || is_mode_2 || coauth_disable);
|
|
|
|
},
|
|
|
|
|
2016-03-11 00:48:53 +00:00
|
|
|
onApiDisconnect: function() {
|
|
|
|
this.mode.isEdit = false;
|
|
|
|
|
|
|
|
var controller = this.getApplication().getController('FormulaDialog');
|
|
|
|
if (controller) {
|
|
|
|
controller.hideDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.mode.isEdit) {
|
|
|
|
$('#ce-func-label', this.editor.el).addClass('disabled');
|
|
|
|
this.editor.btnNamedRanges.setVisible(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onCellsRange: function(status) {
|
2016-08-16 12:32:12 +00:00
|
|
|
this.editor.cellNameDisabled(status != Asc.c_oAscSelectionDialogType.None);
|
2016-11-29 11:59:05 +00:00
|
|
|
this.editor.$btnfunc.toggleClass('disabled', status != Asc.c_oAscSelectionDialogType.None);
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onLayoutResize: function(o, r) {
|
|
|
|
if (r == 'cell:edit') {
|
2021-01-21 10:14:36 +00:00
|
|
|
if (Math.floor(this.editor.$el.height()) > 19) {
|
2021-04-27 17:21:45 +00:00
|
|
|
if (!this.editor.$btnexpand.hasClass('btn-collapse')) {
|
|
|
|
this.editor.$el.addClass('expanded');
|
2016-03-11 00:48:53 +00:00
|
|
|
this.editor.$btnexpand['addClass']('btn-collapse');
|
2021-04-27 17:21:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-17 14:03:31 +00:00
|
|
|
o && Common.localStorage.setItem('sse-celleditor-height', this.editor.$el.height());
|
|
|
|
o && Common.localStorage.setBool('sse-celleditor-expand', true);
|
2016-03-11 00:48:53 +00:00
|
|
|
} else {
|
2021-04-27 17:21:45 +00:00
|
|
|
this.editor.$el.removeClass('expanded');
|
2016-03-11 00:48:53 +00:00
|
|
|
this.editor.$btnexpand['removeClass']('btn-collapse');
|
2019-10-17 14:03:31 +00:00
|
|
|
o && Common.localStorage.setBool('sse-celleditor-expand', false);
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onCellName: function(e) {
|
|
|
|
if (e.keyCode == Common.UI.Keys.RETURN){
|
|
|
|
var name = this.editor.$cellname.val();
|
|
|
|
if (name && name.length) {
|
|
|
|
this.api.asc_findCell(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.editor);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onBlurCellEditor: function() {
|
|
|
|
if (this.api.isCEditorFocused == 'clear')
|
|
|
|
this.api.isCEditorFocused = undefined;
|
|
|
|
else if (this.api.isCellEdited)
|
|
|
|
this.api.isCEditorFocused = true;
|
2016-07-26 11:48:03 +00:00
|
|
|
// if (Common.Utils.isIE && !$('#menu-formula-selection').hasClass('open')) {// for formula menu
|
|
|
|
// this.getApplication().getController('DocumentHolder').documentHolder.focus();
|
|
|
|
// }
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onKeyupCellEditor: function(e) {
|
|
|
|
if(e.keyCode == Common.UI.Keys.RETURN && !e.altKey){
|
|
|
|
this.api.isCEditorFocused = 'clear';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
expandEditorField: function() {
|
2021-01-21 10:14:36 +00:00
|
|
|
if ( Math.floor(this.editor.$el.height()) > 19) {
|
2016-03-11 00:48:53 +00:00
|
|
|
this.editor.keep_height = this.editor.$el.height();
|
|
|
|
this.editor.$el.height(19);
|
2021-04-27 17:21:45 +00:00
|
|
|
this.editor.$el.removeClass('expanded');
|
2016-03-11 00:48:53 +00:00
|
|
|
this.editor.$btnexpand['removeClass']('btn-collapse');
|
2019-10-17 14:03:31 +00:00
|
|
|
Common.localStorage.setBool('sse-celleditor-expand', false);
|
2016-03-11 00:48:53 +00:00
|
|
|
} else {
|
2019-10-17 14:03:31 +00:00
|
|
|
this.editor.$el.height(this.editor.keep_height);
|
2021-04-27 17:21:45 +00:00
|
|
|
this.editor.$el.addClass('expanded');
|
2016-03-11 00:48:53 +00:00
|
|
|
this.editor.$btnexpand['addClass']('btn-collapse');
|
2019-10-17 14:03:31 +00:00
|
|
|
Common.localStorage.setBool('sse-celleditor-expand', true);
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common.NotificationCenter.trigger('layout:changed', 'celleditor');
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.editor, {restorefocus:true});
|
|
|
|
},
|
|
|
|
|
|
|
|
onInsertFunction: function() {
|
2021-02-16 11:49:13 +00:00
|
|
|
if (this.viewmode) return; // signed file
|
|
|
|
|
2016-03-11 00:48:53 +00:00
|
|
|
if ( this.mode.isEdit && !this.editor.$btnfunc['hasClass']('disabled')) {
|
|
|
|
var controller = this.getApplication().getController('FormulaDialog');
|
|
|
|
if (controller) {
|
|
|
|
$('#ce-func-label', this.editor.el).blur();
|
|
|
|
controller.showDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onNamedRangesMenu: function(menu, item) {
|
|
|
|
var me = this;
|
|
|
|
if (item.options.value=='manager') {
|
|
|
|
var wc = this.api.asc_getWorksheetsCount(),
|
|
|
|
i = -1,
|
|
|
|
items = [], sheetNames = [];
|
|
|
|
while (++i < wc) {
|
|
|
|
if (!this.api.asc_isWorksheetHidden(i)) {
|
|
|
|
sheetNames[i] = this.api.asc_getWorksheetName(i);
|
|
|
|
items.push({displayValue: sheetNames[i], value: i});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new SSE.Views.NameManagerDlg({
|
|
|
|
api: this.api,
|
|
|
|
handler: function(result) {
|
2020-03-13 13:26:27 +00:00
|
|
|
Common.NotificationCenter.trigger('edit:complete', me.editor);
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
locked: this.namedrange_locked,
|
|
|
|
sheets: items,
|
|
|
|
sheetNames: sheetNames,
|
2016-04-05 11:52:34 +00:00
|
|
|
ranges: this.api.asc_getDefinedNames(Asc.c_oAscGetDefinedNamesList.All),
|
2016-03-11 00:48:53 +00:00
|
|
|
props : this.api.asc_getDefaultDefinedName(),
|
|
|
|
sort : this.rangeListSort
|
|
|
|
})).on('close', function(win){
|
|
|
|
me.rangeListSort = win.getSettings();
|
|
|
|
}).show();
|
|
|
|
} else {
|
|
|
|
this.api.asc_findCell(item.caption);
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.editor);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onNameBeforeShow: function() {
|
2020-08-20 08:14:36 +00:00
|
|
|
var names = this.api.asc_getDefinedNames(Asc.c_oAscGetDefinedNamesList.WorksheetWorkbook, true),
|
2016-03-11 00:48:53 +00:00
|
|
|
rangesMenu = this.editor.btnNamedRanges.menu,
|
|
|
|
prev_name='';
|
|
|
|
|
|
|
|
rangesMenu.removeItems(2, rangesMenu.items.length-1);
|
|
|
|
names.sort(function(item1, item2) {
|
2019-03-06 08:47:46 +00:00
|
|
|
var n1 = item1.asc_getName(true).toLowerCase(),
|
|
|
|
n2 = item2.asc_getName(true).toLowerCase();
|
2016-03-11 00:48:53 +00:00
|
|
|
if (n1==n2) return 0;
|
|
|
|
return (n1<n2) ? -1 : 1;
|
|
|
|
});
|
|
|
|
_.each(names, function(field, index) {
|
2019-03-06 08:47:46 +00:00
|
|
|
var name = field.asc_getName(true);
|
2016-03-11 00:48:53 +00:00
|
|
|
if (prev_name !== name) {
|
|
|
|
rangesMenu.addItem(new Common.UI.MenuItem({
|
2019-03-06 08:47:46 +00:00
|
|
|
caption : name
|
2016-03-11 00:48:53 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
prev_name = name;
|
|
|
|
});
|
2021-08-08 22:00:41 +00:00
|
|
|
this.editor.btnNamedRanges.menu.items[0].setDisabled(!!this.api.asc_isProtectedSheet());
|
2016-03-11 00:48:53 +00:00
|
|
|
this.editor.btnNamedRanges.menu.items[1].setVisible(rangesMenu.items.length>2);
|
|
|
|
},
|
|
|
|
|
|
|
|
onLockDefNameManager: function(state) {
|
2016-04-05 11:52:34 +00:00
|
|
|
this.namedrange_locked = (state == Asc.c_oAscDefinedNameReason.LockDefNameManager);
|
2020-09-23 16:01:44 +00:00
|
|
|
},
|
|
|
|
|
2021-06-28 17:12:31 +00:00
|
|
|
SetDisabled: function(disabled) {
|
2021-07-01 21:54:55 +00:00
|
|
|
this.editor.$btnfunc[!disabled && this.mode.isEdit ?'removeClass':'addClass']('disabled');
|
|
|
|
this.editor.btnNamedRanges.setVisible(!disabled && this.mode.isEdit && !this.mode.isEditDiagram && !this.mode.isEditMailMerge);
|
2021-02-16 11:49:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setPreviewMode: function(mode) {
|
|
|
|
if (this.viewmode === mode) return;
|
|
|
|
this.viewmode = mode;
|
2021-07-01 21:54:55 +00:00
|
|
|
this.editor.$btnfunc[!mode && this.mode.isEdit?'removeClass':'addClass']('disabled');
|
|
|
|
this.editor.cellNameDisabled(mode && !(this.mode.isEdit && !this.mode.isEditDiagram && !this.mode.isEditMailMerge));
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|