diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index 03743a1a8..ff3625d21 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; }, @@ -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/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