diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index 40411c2d6..e0b4360f4 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -237,6 +237,7 @@ define([ view.pmiNumFormat.menu.on('item:click', _.bind(me.onNumberFormatSelect, me)); view.pmiNumFormat.menu.on('show:after', _.bind(me.onNumberFormatOpenAfter, me)); view.pmiAdvancedNumFormat.on('click', _.bind(me.onCustomNumberFormat, me)); + view.tableTotalMenu.on('item:click', _.bind(me.onTotalMenuClick, me)); } else { view.menuViewCopy.on('click', _.bind(me.onCopyPaste, me)); @@ -321,6 +322,7 @@ define([ this.api.asc_registerCallback('asc_onFormulaInfo', _.bind(this.onFormulaInfo, this)); this.api.asc_registerCallback('asc_ChangeCropState', _.bind(this.onChangeCropState, this)); this.api.asc_registerCallback('asc_onInputMessage', _.bind(this.onInputMessage, this)); + this.api.asc_registerCallback('asc_onTableTotalMenu', _.bind(this.onTableTotalMenu, this)); } return this; }, @@ -507,7 +509,7 @@ define([ onInsFunction: function(item) { var controller = this.getApplication().getController('FormulaDialog'); if (controller && this.api) { - controller.showDialog(); + controller.showDialog(undefined, item.value==Asc.ETotalsRowFunction.totalrowfunctionCustom); } }, @@ -2120,6 +2122,63 @@ define([ } }, + onTableTotalMenu: function(current) { + if (current !== undefined) { + var me = this, + documentHolderView = me.documentHolder, + menu = documentHolderView.tableTotalMenu, + menuContainer = documentHolderView.cmpEl.find(Common.Utils.String.format('#menu-container-{0}', menu.id)); + + if (menu.isVisible()) { + menu.hide(); + return; + } + + Common.UI.Menu.Manager.hideAll(); + + if (!menu.rendered) { + // Prepare menu container + if (menuContainer.length < 1) { + menuContainer = $(Common.Utils.String.format('
', menu.id)); + documentHolderView.cmpEl.append(menuContainer); + } + + menu.render(menuContainer); + menu.cmpEl.attr({tabindex: "-1"}); + } + + menu.clearAll(); + var func = _.find(menu.items, function(item) { return item.value == current; }); + if (func) + func.setChecked(true, true); + + var coord = me.api.asc_getActiveCellCoord(), + offset = {left:0,top:0}, + showPoint = [coord.asc_getX() + offset.left, (coord.asc_getY() < 0 ? 0 : coord.asc_getY()) + coord.asc_getHeight() + offset.top]; + menuContainer.css({left: showPoint[0], top : showPoint[1]}); + + me._preventClick = true; + menuContainer.attr('data-value', 'prevent-canvas-click'); + menu.show(); + + menu.alignPosition(); + _.delay(function() { + menu.cmpEl.focus(); + }, 10); + } else { + this.documentHolder.tableTotalMenu.hide(); + } + }, + + onTotalMenuClick: function(menu, item) { + if (item.value==Asc.ETotalsRowFunction.totalrowfunctionCustom) { + this.onInsFunction(item); + } else { + this.api.asc_insertInCell(item.value, Asc.c_oAscPopUpSelectorType.TotalRowFunc); + } + Common.NotificationCenter.trigger('edit:complete', this.documentHolder); + }, + onFormulaCompleteMenu: function(funcarr) { if (!this.documentHolder.funcMenu || Common.Utils.ModalWindow.isVisible() || this.rangeSelectionMode) return; diff --git a/apps/spreadsheeteditor/main/app/controller/FormulaDialog.js b/apps/spreadsheeteditor/main/app/controller/FormulaDialog.js index 25cb50b7c..d1e0cc5f8 100644 --- a/apps/spreadsheeteditor/main/app/controller/FormulaDialog.js +++ b/apps/spreadsheeteditor/main/app/controller/FormulaDialog.js @@ -99,7 +99,7 @@ define([ if (autocomplete) this.api.asc_insertInCell(func.name, Asc.c_oAscPopUpSelectorType.Func, !!autocomplete); else - this.api.asc_startWizard(func.name); + this.api.asc_startWizard(func.name, this._cleanCell); !autocomplete && this.updateLast10Formulas(func.origin); } } @@ -133,6 +133,7 @@ define([ }); this.formulas.on({ 'hide': function () { + me._cleanCell = undefined; // _cleanCell - clean cell when change formula in formatted table total row me.api.asc_enableKeyEvents(true); } }); @@ -212,7 +213,7 @@ define([ return null; }, - showDialog: function (group) { + showDialog: function (group, clean) { if (this.formulas) { if ( this.needUpdateFormula ) { this.needUpdateFormula = false; @@ -222,6 +223,7 @@ define([ } } this._formulagroup = group; + this._cleanCell = clean; this.api.asc_startWizard(); } }, @@ -249,6 +251,7 @@ define([ } } })).show(); + this._cleanCell = undefined; } else this.formulas.show(this._formulagroup); this._formulagroup = undefined; diff --git a/apps/spreadsheeteditor/main/app/view/DocumentHolder.js b/apps/spreadsheeteditor/main/app/view/DocumentHolder.js index 426965d04..634f89992 100644 --- a/apps/spreadsheeteditor/main/app/view/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/view/DocumentHolder.js @@ -979,6 +979,23 @@ define([ mnu.cmpEl.removeAttr('oo_editor_input').attr('oo_editor_keyboard', true); }); + this.tableTotalMenu = new Common.UI.Menu({ + maxHeight: 160, + cyclic: false, + cls: 'lang-menu', + items: [ + {caption: this.textNone, value: Asc.ETotalsRowFunction.totalrowfunctionNone, checkable: true}, + {caption: this.textAverage, value: Asc.ETotalsRowFunction.totalrowfunctionAverage, checkable: true }, + {caption: this.textCount, value: Asc.ETotalsRowFunction.totalrowfunctionCount, checkable: true }, + {caption: this.textMax, value: Asc.ETotalsRowFunction.totalrowfunctionMax, checkable: true }, + {caption: this.textMin, value: Asc.ETotalsRowFunction.totalrowfunctionMin, checkable: true }, + {caption: this.textSum, value: Asc.ETotalsRowFunction.totalrowfunctionSum, checkable: true }, + {caption: this.textStdDev, value: Asc.ETotalsRowFunction.totalrowfunctionStdDev, checkable: true }, + {caption: this.textVar, value: Asc.ETotalsRowFunction.totalrowfunctionVar, checkable: true }, + {caption: this.textMore, value: Asc.ETotalsRowFunction.totalrowfunctionCustom, checkable: true } + ] + }); + me.fireEvent('createdelayedelements', [me]); }, @@ -1111,7 +1128,15 @@ define([ textCropFit: 'Fit', textListSettings: 'List Settings', textFromStorage: 'From Storage', - advancedSlicerText: 'Slicer Advanced Settings' + advancedSlicerText: 'Slicer Advanced Settings', + textAverage: 'Average', + textMax: 'Max', + textMin: 'Min', + textCount: 'Count', + textSum: 'Sum', + textStdDev: 'StdDev', + textVar: 'Var', + textMore: 'More functions' }, SSE.Views.DocumentHolder || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 5c18b0aed..b6bb22291 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -1591,6 +1591,14 @@ "SSE.Views.DocumentHolder.vertAlignText": "Vertical Alignment", "SSE.Views.DocumentHolder.textFromStorage": "From Storage", "SSE.Views.DocumentHolder.advancedSlicerText": "Slicer Advanced Settings", + "SSE.Views.DocumentHolder.textAverage": "Average", + "SSE.Views.DocumentHolder.textMax": "Max", + "SSE.Views.DocumentHolder.textMin": "Min", + "SSE.Views.DocumentHolder.textCount": "Count", + "SSE.Views.DocumentHolder.textSum": "Sum", + "SSE.Views.DocumentHolder.textStdDev": "StdDev", + "SSE.Views.DocumentHolder.textVar": "Var", + "SSE.Views.DocumentHolder.textMore": "More functions", "SSE.Views.FieldSettingsDialog.strLayout": "Layout", "SSE.Views.FieldSettingsDialog.strSubtotals": "Subtotals", "SSE.Views.FieldSettingsDialog.textReport": "Report Form",