Merge pull request #148 from ONLYOFFICE/feature/de-table-formula
Feature/de table formula
This commit is contained in:
commit
3eac1bcd9d
|
@ -130,27 +130,38 @@ define([
|
|||
|
||||
var styleNames = ['Normal', 'No Spacing', 'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4', 'Heading 5',
|
||||
'Heading 6', 'Heading 7', 'Heading 8', 'Heading 9', 'Title', 'Subtitle', 'Quote', 'Intense Quote', 'List Paragraph', 'footnote text'],
|
||||
translate = {
|
||||
'Series': this.txtSeries,
|
||||
'Diagram Title': this.txtDiagramTitle,
|
||||
'X Axis': this.txtXAxis,
|
||||
'Y Axis': this.txtYAxis,
|
||||
'Your text here': this.txtArt,
|
||||
"Error! Bookmark not defined.": this.txtBookmarkError,
|
||||
"above": this.txtAbove,
|
||||
"below": this.txtBelow,
|
||||
"on page ": this.txtOnPage,
|
||||
"Header": this.txtHeader,
|
||||
"Footer": this.txtFooter,
|
||||
" -Section ": this.txtSection,
|
||||
"First Page ": this.txtFirstPage,
|
||||
"Even Page ": this.txtEvenPage,
|
||||
"Odd Page ": this.txtOddPage,
|
||||
"Same as Previous": this.txtSameAsPrev,
|
||||
"Current Document": this.txtCurrentDocument,
|
||||
"No table of contents entries found.": this.txtNoTableOfContents,
|
||||
"Table of Contents": this.txtTableOfContents
|
||||
};
|
||||
translate = {
|
||||
'Series': this.txtSeries,
|
||||
'Diagram Title': this.txtDiagramTitle,
|
||||
'X Axis': this.txtXAxis,
|
||||
'Y Axis': this.txtYAxis,
|
||||
'Your text here': this.txtArt,
|
||||
"Error! Bookmark not defined.": this.txtBookmarkError,
|
||||
"above": this.txtAbove,
|
||||
"below": this.txtBelow,
|
||||
"on page ": this.txtOnPage,
|
||||
"Header": this.txtHeader,
|
||||
"Footer": this.txtFooter,
|
||||
" -Section ": this.txtSection,
|
||||
"First Page ": this.txtFirstPage,
|
||||
"Even Page ": this.txtEvenPage,
|
||||
"Odd Page ": this.txtOddPage,
|
||||
"Same as Previous": this.txtSameAsPrev,
|
||||
"Current Document": this.txtCurrentDocument,
|
||||
"No table of contents entries found.": this.txtNoTableOfContents,
|
||||
"Table of Contents": this.txtTableOfContents,
|
||||
"Syntax Error": this.txtSyntaxError,
|
||||
"Missing Operator": this.txtMissOperator,
|
||||
"Missing Argument": this.txtMissArg,
|
||||
"Number Too Large To Format": this.txtTooLarge,
|
||||
"Zero Divide": this.txtZeroDivide,
|
||||
"Is Not In Table": this.txtNotInTable,
|
||||
"Index Too Large": this.txtIndTooLarge,
|
||||
"The Formula Not In Table": this.txtFormulaNotInTable,
|
||||
"Table Index Cannot be Zero": this.txtTableInd,
|
||||
"Undefined Bookmark": this.txtUndefBookmark,
|
||||
"Unexpected End of Formula": this.txtEndOfFormula
|
||||
};
|
||||
styleNames.forEach(function(item){
|
||||
translate[item] = me.translationTable[item] = me['txtStyle_' + item.replace(/ /g, '_')] || item;
|
||||
});
|
||||
|
@ -2530,6 +2541,17 @@ define([
|
|||
txtShape_spline: 'Curve',
|
||||
txtShape_polyline1: 'Scribble',
|
||||
txtShape_polyline2: 'Freeform',
|
||||
txtSyntaxError: 'Syntax Error',
|
||||
txtMissOperator: 'Missing Operator',
|
||||
txtMissArg: 'Missing Argument',
|
||||
txtTooLarge: 'Number Too Large To Format',
|
||||
txtZeroDivide: 'Zero Divide',
|
||||
txtNotInTable: 'Is Not In Table',
|
||||
txtIndTooLarge: 'Index Too Large',
|
||||
txtFormulaNotInTable: 'The Formula Not In Table',
|
||||
txtTableInd: 'Table Index Cannot be Zero',
|
||||
txtUndefBookmark: 'Undefined Bookmark',
|
||||
txtEndOfFormula: 'Unexpected End of Formula',
|
||||
errorEmailClient: 'No email client could be found'
|
||||
}
|
||||
})(), DE.Controllers.Main || {}))
|
||||
|
|
|
@ -137,6 +137,16 @@
|
|||
<div class="separator horizontal"></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-small" colspan=2>
|
||||
<button type="button" class="btn btn-text-default" id="table-btn-add-formula" style="width:100%;"><%= scope.textAddFormula %></button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-small" colspan=2>
|
||||
<div class="separator horizontal"></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding-small" colspan=2>
|
||||
<div id="table-checkbox-repeat-row"></div>
|
||||
|
|
247
apps/documenteditor/main/app/view/TableFormulaDialog.js
Normal file
247
apps/documenteditor/main/app/view/TableFormulaDialog.js
Normal file
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* TableFormulaDialog.js
|
||||
*
|
||||
* Created by Julia Radzhabova on 1/21/19
|
||||
* Copyright (c) 2019 Ascensio System SIA. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
define([
|
||||
'common/main/lib/component/InputField',
|
||||
'common/main/lib/component/Window'
|
||||
], function () { 'use strict';
|
||||
|
||||
DE.Views.TableFormulaDialog = Common.UI.Window.extend(_.extend({
|
||||
options: {
|
||||
width: 300,
|
||||
style: 'min-width: 230px;',
|
||||
cls: 'modal-dlg'
|
||||
},
|
||||
|
||||
initialize : function(options) {
|
||||
_.extend(this.options, {
|
||||
title: this.textTitle
|
||||
}, options || {});
|
||||
|
||||
this.template = [
|
||||
'<div class="box" style="height: 150px;">',
|
||||
'<div class="input-row">',
|
||||
'<label>' + this.textFormula + '</label>',
|
||||
'</div>',
|
||||
'<div id="id-dlg-formula-formula" class="input-row" style="margin-bottom: 5px;"></div>',
|
||||
'<div class="input-row">',
|
||||
'<label>' + this.textFormat + '</label>',
|
||||
'</div>',
|
||||
'<div id="id-dlg-formula-format" class="input-row" style="margin-bottom: 20px;"></div>',
|
||||
'<div class="input-row">',
|
||||
'<div id="id-dlg-formula-function" style="display: inline-block; width: 50%; padding-right: 10px; float: left;"></div>',
|
||||
'<div id="id-dlg-formula-bookmark" style="display: inline-block; width: 50%;"></div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="footer right">',
|
||||
'<button class="btn normal dlg-btn primary" result="ok" style="margin-right: 10px;">' + this.okButtonText + '</button>',
|
||||
'<button class="btn normal dlg-btn" result="cancel">' + this.cancelButtonText + '</button>',
|
||||
'</div>'
|
||||
].join('');
|
||||
|
||||
this.options.tpl = _.template(this.template)(this.options);
|
||||
this.bookmarks = this.options.bookmarks;
|
||||
this.api = this.options.api;
|
||||
|
||||
Common.UI.Window.prototype.initialize.call(this, this.options);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
Common.UI.Window.prototype.render.call(this);
|
||||
|
||||
var me = this,
|
||||
$window = this.getChild();
|
||||
|
||||
this.inputFormula = new Common.UI.InputField({
|
||||
el : $('#id-dlg-formula-formula'),
|
||||
allowBlank : true,
|
||||
validateOnChange: true,
|
||||
style : 'width: 100%;'
|
||||
}).on('changing', _.bind(this.checkFormulaInput, this));
|
||||
|
||||
this.cmbFormat = new Common.UI.ComboBox({
|
||||
el : $('#id-dlg-formula-format'),
|
||||
cls : 'input-group-nr',
|
||||
menuStyle : 'min-width: 100%; max-height: 200px;'
|
||||
});
|
||||
|
||||
this.cmbFunction = new Common.UI.ComboBox({
|
||||
el : $('#id-dlg-formula-function'),
|
||||
cls : 'input-group-nr',
|
||||
menuStyle : 'min-width: 100%; max-height: 150px;',
|
||||
editable : false,
|
||||
scrollAlwaysVisible: true,
|
||||
data: [
|
||||
{displayValue: 'ABS', value: 1},
|
||||
{displayValue: 'AND', value: 1},
|
||||
{displayValue: 'AVERAGE', value: 1},
|
||||
{displayValue: 'COUNT', value: 1},
|
||||
{displayValue: 'DEFINED', value: 1},
|
||||
{displayValue: 'FALSE', value: 0},
|
||||
{displayValue: 'INT', value: 1},
|
||||
{displayValue: 'MAX', value: 1},
|
||||
{displayValue: 'MIN', value: 1},
|
||||
{displayValue: 'MOD', value: 1},
|
||||
{displayValue: 'NOT', value: 1},
|
||||
{displayValue: 'OR', value: 1},
|
||||
{displayValue: 'PRODUCT', value: 1},
|
||||
{displayValue: 'ROUND', value: 1},
|
||||
{displayValue: 'SIGN', value: 1},
|
||||
{displayValue: 'SUM', value: 1},
|
||||
{displayValue: 'TRUE', value: 0}
|
||||
]
|
||||
});
|
||||
this.cmbFunction.on('selected', _.bind(function(combo, record) {
|
||||
combo.setValue(this.textInsertFunction);
|
||||
var _input = me.inputFormula._input,
|
||||
end = _input[0].selectionEnd;
|
||||
_input.val(_input.val().substring(0, end) + record.displayValue + (record.value ? '()' : '') + _input.val().substring(end));
|
||||
_input.focus();
|
||||
_input[0].selectionStart = _input[0].selectionEnd = end + record.displayValue.length + record.value;
|
||||
this.btnOk.setDisabled(false);
|
||||
}, this));
|
||||
this.cmbFunction.setValue(this.textInsertFunction);
|
||||
|
||||
this.cmbBookmark = new Common.UI.ComboBox({
|
||||
el : $('#id-dlg-formula-bookmark'),
|
||||
cls : 'input-group-nr',
|
||||
menuStyle : 'min-width: 100%; max-heigh: 150px;',
|
||||
editable : false
|
||||
});
|
||||
this.cmbBookmark.on('selected', _.bind(function(combo, record) {
|
||||
combo.setValue(this.textBookmark);
|
||||
var _input = me.inputFormula._input,
|
||||
end = _input[0].selectionEnd;
|
||||
_input.val(_input.val().substring(0, end) + record.displayValue + _input.val().substring(end));
|
||||
_input.focus();
|
||||
_input[0].selectionStart = _input[0].selectionEnd = end + record.displayValue.length;
|
||||
this.btnOk.setDisabled(false);
|
||||
}, this));
|
||||
this.cmbBookmark.setValue(this.textBookmark);
|
||||
|
||||
me.btnOk = new Common.UI.Button({
|
||||
el: $window.find('.primary')
|
||||
});
|
||||
|
||||
$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
|
||||
this.afterRender();
|
||||
},
|
||||
|
||||
onSelectItem: function(picker, item, record, e){
|
||||
this.btnOk.setDisabled(record.get('level')==0 && record.get('index')>0);
|
||||
},
|
||||
|
||||
show: function() {
|
||||
Common.UI.Window.prototype.show.apply(this, arguments);
|
||||
|
||||
var me = this;
|
||||
_.delay(function(){
|
||||
me.inputFormula.cmpEl.find('input').focus();
|
||||
},500);
|
||||
},
|
||||
|
||||
afterRender: function() {
|
||||
this.refreshBookmarks();
|
||||
this._setDefaults();
|
||||
},
|
||||
|
||||
_setDefaults: function () {
|
||||
var arr = [];
|
||||
_.each(this.api.asc_GetTableFormulaFormats(), function(item) {
|
||||
arr.push({value: item, displayValue: item});
|
||||
});
|
||||
this.cmbFormat.setData(arr);
|
||||
var formula = this.api.asc_ParseTableFormulaInstrLine(this.api.asc_GetTableFormula());
|
||||
this.inputFormula.setValue(formula[0]);
|
||||
this.cmbFormat.setValue(formula[1]);
|
||||
this.checkFormulaInput(this.inputFormula, this.inputFormula.getValue());
|
||||
},
|
||||
|
||||
refreshBookmarks: function() {
|
||||
var arr = [];
|
||||
if (this.bookmarks) {
|
||||
var count = this.bookmarks.asc_GetCount();
|
||||
for (var i=0; i<count; i++) {
|
||||
var name = this.bookmarks.asc_GetName(i);
|
||||
if (!this.bookmarks.asc_IsInternalUseBookmark(name)) {
|
||||
arr.push({value: i, displayValue: name});
|
||||
}
|
||||
}
|
||||
this.cmbBookmark.setData(arr);
|
||||
this.cmbBookmark.setValue(this.textBookmark);
|
||||
}
|
||||
this.cmbBookmark.setDisabled(arr.length<1);
|
||||
},
|
||||
|
||||
checkFormulaInput: function(cmp, newValue) {
|
||||
var value = newValue.trim();
|
||||
this.btnOk.setDisabled(value=='' || value == '=');
|
||||
},
|
||||
|
||||
getSettings: function () {
|
||||
return this.api.asc_CreateInstructionLine(this.inputFormula.getValue(), this.cmbFormat.getValue());
|
||||
},
|
||||
|
||||
onBtnClick: function(event) {
|
||||
this._handleInput(event.currentTarget.attributes['result'].value);
|
||||
},
|
||||
|
||||
onPrimary: function(event) {
|
||||
this._handleInput('ok');
|
||||
return false;
|
||||
},
|
||||
|
||||
_handleInput: function(state) {
|
||||
if (this.options.handler) {
|
||||
this.options.handler.call(this, state, this.getSettings());
|
||||
}
|
||||
|
||||
this.close();
|
||||
},
|
||||
|
||||
textFormula: 'Formula',
|
||||
textFormat: 'Number Format',
|
||||
textBookmark: 'Paste Bookmark',
|
||||
textInsertFunction: 'Paste Function',
|
||||
cancelButtonText: 'Cancel',
|
||||
okButtonText: 'Ok',
|
||||
textTitle: 'Formula Settings'
|
||||
}, DE.Views.TableFormulaDialog || {}))
|
||||
});
|
|
@ -50,7 +50,8 @@ define([
|
|||
'common/main/lib/component/ComboBorderSize',
|
||||
'common/main/lib/component/ComboDataView',
|
||||
'common/main/lib/view/InsertTableDialog',
|
||||
'documenteditor/main/app/view/TableSettingsAdvanced'
|
||||
'documenteditor/main/app/view/TableSettingsAdvanced',
|
||||
'documenteditor/main/app/view/TableFormulaDialog'
|
||||
], function (menuTemplate, $, _, Backbone) {
|
||||
'use strict';
|
||||
|
||||
|
@ -419,6 +420,12 @@ define([
|
|||
this.api.asc_DistributeTableCells(true);
|
||||
}, this));
|
||||
|
||||
this.btnAddFormula = new Common.UI.Button({
|
||||
el: $('#table-btn-add-formula')
|
||||
});
|
||||
this.lockedControls.push(this.btnAddFormula);
|
||||
this.btnAddFormula.on('click', _.bind(this.onAddFormula, this));
|
||||
|
||||
this.linkAdvanced = $('#table-advanced-link');
|
||||
$(this.el).on('click', '#table-advanced-link', _.bind(this.openAdvancedSettings, this));
|
||||
},
|
||||
|
@ -758,6 +765,26 @@ define([
|
|||
}
|
||||
},
|
||||
|
||||
onAddFormula: function(e) {
|
||||
var me = this;
|
||||
var win;
|
||||
if (me.api && !this._locked){
|
||||
(new DE.Views.TableFormulaDialog(
|
||||
{
|
||||
api: me.api,
|
||||
bookmarks: me.api.asc_GetBookmarksManager(),
|
||||
handler: function(result, value) {
|
||||
if (result == 'ok') {
|
||||
if (me.api) {
|
||||
me.api.asc_AddTableFormula(value);
|
||||
}
|
||||
}
|
||||
me.fireEvent('editcomplete', me);
|
||||
}
|
||||
})).show();
|
||||
}
|
||||
},
|
||||
|
||||
setLocked: function (locked) {
|
||||
this._locked = locked;
|
||||
},
|
||||
|
@ -822,7 +849,8 @@ define([
|
|||
textHeight: 'Height',
|
||||
textWidth: 'Width',
|
||||
textDistributeRows: 'Distribute rows',
|
||||
textDistributeCols: 'Distribute columns'
|
||||
textDistributeCols: 'Distribute columns',
|
||||
textAddFormula: 'Add formula'
|
||||
|
||||
}, DE.Views.TableSettings || {}));
|
||||
});
|
|
@ -655,6 +655,17 @@
|
|||
"DE.Controllers.Main.warnNoLicense": "This version of ONLYOFFICE Editors has certain limitations for concurrent connections to the document server.<br>If you need more please consider purchasing a commercial license.",
|
||||
"DE.Controllers.Main.warnNoLicenseUsers": "This version of ONLYOFFICE Editors has certain limitations for concurrent users.<br>If you need more please consider purchasing a commercial license.",
|
||||
"DE.Controllers.Main.warnProcessRightsChange": "You have been denied the right to edit the file.",
|
||||
"DE.Controllers.Main.txtSyntaxError": "Syntax Error",
|
||||
"DE.Controllers.Main.txtMissOperator": "Missing Operator",
|
||||
"DE.Controllers.Main.txtMissArg": "Missing Argument",
|
||||
"DE.Controllers.Main.txtTooLarge": "Number Too Large To Format",
|
||||
"DE.Controllers.Main.txtZeroDivide": "Zero Divide",
|
||||
"DE.Controllers.Main.txtNotInTable": "Is Not In Table",
|
||||
"DE.Controllers.Main.txtIndTooLarge": "Index Too Large",
|
||||
"DE.Controllers.Main.txtFormulaNotInTable": "The Formula Not In Table",
|
||||
"DE.Controllers.Main.txtTableInd": "Table Index Cannot be Zero",
|
||||
"DE.Controllers.Main.txtUndefBookmark": "Undefined Bookmark",
|
||||
"DE.Controllers.Main.txtEndOfFormula": "Unexpected End of Formula",
|
||||
"DE.Controllers.Navigation.txtBeginning": "Beginning of document",
|
||||
"DE.Controllers.Navigation.txtGotoBeginning": "Go to the beginning of the document",
|
||||
"DE.Controllers.Statusbar.textHasChanges": "New changes have been tracked",
|
||||
|
@ -1862,6 +1873,7 @@
|
|||
"DE.Views.TableSettings.splitCellsText": "Split Cell...",
|
||||
"DE.Views.TableSettings.splitCellTitleText": "Split Cell",
|
||||
"DE.Views.TableSettings.strRepeatRow": "Repeat as header row at the top of each page",
|
||||
"DE.Views.TableSettings.textAddFormula": "Add formula",
|
||||
"DE.Views.TableSettings.textAdvanced": "Show advanced settings",
|
||||
"DE.Views.TableSettings.textBackColor": "Background Color",
|
||||
"DE.Views.TableSettings.textBanded": "Banded",
|
||||
|
|
Loading…
Reference in a new issue