2016-11-25 09:46:12 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2016
|
|
|
|
*
|
|
|
|
* 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 Lubanas st. 125a-25, Riga, Latvia,
|
|
|
|
* EU, LV-1021.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* CellEditor.js
|
|
|
|
*
|
|
|
|
* CellEditor Controller
|
|
|
|
*
|
|
|
|
* Created by Maxim Kadushkin on 11/24/2016
|
2016-12-01 17:11:16 +00:00
|
|
|
* Copyright (c) 2016 Ascensio System SIA. All rights reserved.
|
2016-11-25 09:46:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
2016-12-01 17:11:16 +00:00
|
|
|
'core',
|
|
|
|
'spreadsheeteditor/mobile/app/view/CellEditor'
|
|
|
|
], function (core) {
|
2016-11-25 09:46:12 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
SSE.Controllers.CellEditor = Backbone.Controller.extend({
|
2016-12-01 17:11:16 +00:00
|
|
|
views: [
|
|
|
|
'CellEditor'
|
|
|
|
],
|
2016-11-25 09:46:12 +00:00
|
|
|
|
2016-12-21 14:33:17 +00:00
|
|
|
events: function() {
|
|
|
|
return {
|
2016-11-25 09:46:12 +00:00
|
|
|
// '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),
|
2016-12-21 14:33:17 +00:00
|
|
|
// 'click a#ce-function': _.bind(this.onInsertFunction, this)
|
|
|
|
};
|
|
|
|
},
|
2016-11-25 09:46:12 +00:00
|
|
|
|
|
|
|
initialize: function() {
|
2016-12-21 14:33:17 +00:00
|
|
|
this.addListeners({
|
|
|
|
'CellEditor': {
|
|
|
|
'function:click': this.onInsertFunction.bind(this)
|
|
|
|
}
|
2016-12-01 17:11:16 +00:00
|
|
|
// 'Viewport': {
|
2016-11-25 09:46:12 +00:00
|
|
|
// 'layout:resizedrag': _.bind(this.onLayoutResize, this)
|
2016-12-01 17:11:16 +00:00
|
|
|
// }
|
2016-12-21 14:33:17 +00:00
|
|
|
});
|
2016-11-25 09:46:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setApi: function(api) {
|
|
|
|
this.api = api;
|
|
|
|
|
|
|
|
// this.api.isCEditorFocused = false;
|
|
|
|
this.api.asc_registerCallback('asc_onSelectionNameChanged', _.bind(this.onApiCellSelection, this));
|
2016-12-26 07:48:53 +00:00
|
|
|
this.api.asc_registerCallback('asc_onEditCell', _.bind(this.onApiEditCell, this));
|
2016-11-25 09:46:12 +00:00
|
|
|
// 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_onInputKeyDown', _.bind(this.onInputKeyDown, this));
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
|
|
|
onInputKeyDown: function(e) {
|
|
|
|
if (Common.UI.Keys.UP === e.keyCode || Common.UI.Keys.DOWN === e.keyCode ||
|
|
|
|
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) {
|
|
|
|
var menu = $('#menu-formula-selection'); // for formula menu
|
|
|
|
if (menu.hasClass('open'))
|
|
|
|
menu.find('.dropdown-menu').trigger('keydown', e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onLaunch: function() {
|
2016-12-01 17:11:16 +00:00
|
|
|
this.editor = this.createView('CellEditor').render();
|
2016-11-25 09:46:12 +00:00
|
|
|
|
|
|
|
// this.bindViewEvents(this.editor, this.events);
|
|
|
|
// this.editor.$el.parent().find('.after').css({zIndex: '4'}); // for spreadsheets - bug 23127
|
|
|
|
},
|
|
|
|
|
|
|
|
onApiEditCell: function(state) {
|
|
|
|
if (state == Asc.c_oAscCellEditorState.editStart){
|
|
|
|
this.api.isCellEdited = true;
|
|
|
|
this.editor.cellNameDisabled(true);
|
|
|
|
} else if (state == Asc.c_oAscCellEditorState.editEnd) {
|
|
|
|
this.api.isCellEdited = false;
|
|
|
|
this.api.isCEditorFocused = false;
|
|
|
|
this.editor.cellNameDisabled(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onApiCellSelection: function(info) {
|
2016-12-01 17:11:16 +00:00
|
|
|
this.editor.updateCellInfo(info);
|
2016-11-25 09:46:12 +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) {
|
|
|
|
// this.editor.cellNameDisabled(status != Asc.c_oAscSelectionDialogType.None);
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
// if (Common.Utils.isIE && !$('#menu-formula-selection').hasClass('open')) {// for formula menu
|
|
|
|
// this.getApplication().getController('DocumentHolder').documentHolder.focus();
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
|
|
|
|
onKeyupCellEditor: function(e) {
|
|
|
|
if(e.keyCode == Common.UI.Keys.RETURN && !e.altKey){
|
|
|
|
this.api.isCEditorFocused = 'clear';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onInsertFunction: function() {
|
2016-12-21 14:33:17 +00:00
|
|
|
SSE.getController('AddContainer').showModal({
|
|
|
|
panel: 'function',
|
|
|
|
button: '#ce-function'
|
|
|
|
});
|
2016-11-25 09:46:12 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|