From 072f8b771599760815d14a3ca75f4e16e1b495c4 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 24 Jun 2019 15:57:28 +0300 Subject: [PATCH] [SSE] Formula tab: add recent, autosum buttons --- .../main/app/controller/FormulaDialog.js | 18 +- .../main/app/controller/Toolbar.js | 7 +- .../main/app/template/Toolbar.template | 7 +- .../main/app/view/FormulaTab.js | 207 +++++++++++------- apps/spreadsheeteditor/main/locale/en.json | 6 + 5 files changed, 159 insertions(+), 86 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/FormulaDialog.js b/apps/spreadsheeteditor/main/app/controller/FormulaDialog.js index 2ccca7791c..f7d8644148 100644 --- a/apps/spreadsheeteditor/main/app/controller/FormulaDialog.js +++ b/apps/spreadsheeteditor/main/app/controller/FormulaDialog.js @@ -79,14 +79,21 @@ define([ }, 'FormulaTab': { 'function:apply': this.applyFunction + }, + 'Toolbar': { + 'function:apply': this.applyFunction } }); }, - applyFunction: function(func) { + applyFunction: function(func, autocomplete) { if (func) { - this.api.asc_insertFormula(func.name, Asc.c_oAscPopUpSelectorType.Func); - this.updateLast10Formulas(func.origin); + if (func.origin === 'more') { + this.showDialog(); + } else { + this.api.asc_insertFormula(func.name, Asc.c_oAscPopUpSelectorType.Func, !!autocomplete); + !autocomplete && this.updateLast10Formulas(func.origin); + } } }, @@ -122,6 +129,8 @@ define([ }); } + this.formulaTab && this.formulaTab.setApi(this.api); + return this; }, @@ -224,6 +233,7 @@ define([ if (this.formulasGroups) { var group = this.formulasGroups.findWhere({name : 'Last10'}); group && group.set('functions', this.loadingLast10Formulas(this.getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale")))); + this.formulaTab && this.formulaTab.updateRecent(); } }, @@ -329,7 +339,7 @@ define([ _.sortBy(allFunctions, function (model) {return model.get('name'); })); } } - this.formulaTab.fillFunctions(); + this.formulaTab && this.formulaTab.fillFunctions(); }, sCategoryAll: 'All', sCategoryLast10: '10 last used', diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index c2bc2d9fe4..0397cd728d 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -1182,10 +1182,8 @@ define([ controller.showDialog(); } } else { - item.value = item.value || 'SUM'; - - this.api.asc_insertFormula(this.api.asc_getFormulaLocaleName(item.value), Asc.c_oAscPopUpSelectorType.Func, true); + this.toolbar.fireEvent('function:apply', [{name: this.api.asc_getFormulaLocaleName(item.value), origin: item.value}, true]); Common.NotificationCenter.trigger('edit:complete', this.toolbar); Common.component.Analytics.trackEvent('ToolBar', 'Insert formula'); @@ -1703,7 +1701,7 @@ define([ toolbar.lockToolbar(SSE.enumLock.editFormula, is_formula, { array: [toolbar.cmbFontName, toolbar.cmbFontSize, toolbar.btnIncFontSize, toolbar.btnDecFontSize, toolbar.btnBold, toolbar.btnItalic, toolbar.btnUnderline, toolbar.btnStrikeout, toolbar.btnSubscript, toolbar.btnTextColor]}); - toolbar.lockToolbar(SSE.enumLock.editText, is_text, {array:[toolbar.btnInsertFormula]}); + toolbar.lockToolbar(SSE.enumLock.editText, is_text, {array: [toolbar.btnInsertFormula].concat(toolbar.btnsFormula)}); } this._state.coauthdisable = undefined; this._state.selection_type = undefined; @@ -3108,6 +3106,7 @@ define([ var formulatab = me.getApplication().getController('FormulaDialog'); formulatab.setConfig({toolbar: me}); formulatab = formulatab.getView('FormulaTab'); + me.toolbar.btnsFormula = formulatab.getButtons('formula'); Array.prototype.push.apply(me.toolbar.lockControls, formulatab.getButtons()); if ( !config.isOffline ) { diff --git a/apps/spreadsheeteditor/main/app/template/Toolbar.template b/apps/spreadsheeteditor/main/app/template/Toolbar.template index 181036137b..fae46d2d51 100644 --- a/apps/spreadsheeteditor/main/app/template/Toolbar.template +++ b/apps/spreadsheeteditor/main/app/template/Toolbar.template @@ -157,9 +157,10 @@
- - - +
+ +
+
diff --git a/apps/spreadsheeteditor/main/app/view/FormulaTab.js b/apps/spreadsheeteditor/main/app/view/FormulaTab.js index 095b92527b..aca7758960 100644 --- a/apps/spreadsheeteditor/main/app/view/FormulaTab.js +++ b/apps/spreadsheeteditor/main/app/view/FormulaTab.js @@ -48,29 +48,23 @@ define([ SSE.Views.FormulaTab = Common.UI.BaseView.extend(_.extend((function(){ function setEvents() { var me = this; - var _setevent = function(btn){ - (typeof btn.menu == 'object') && btn.menu.on('item:click', function (menu, item, e) { - me.fireEvent('function:apply', [{name: item.caption, origin: item.value}]); - }); - }; - // me.btnFinancial.menu.on('item:click', function (menu, item, e) { - // me.fireEvent('function:apply', [{name: item.caption, origin: item.value}]); - // }); - _setevent(this.btnFinancial); - _setevent(this.btnLogical); - _setevent(this.btnTextData); - _setevent(this.btnDateTime); - _setevent(this.btnReference); - _setevent(this.btnMath); + me.btnAutosum.on('click', function(){ + me.fireEvent('function:apply', [{name: me.api.asc_getFormulaLocaleName('SUM'), origin: 'SUM'}, true]); + }); + me.btnAutosum.menu.on('item:click', function (menu, item, e) { + me.fireEvent('function:apply', [{name: item.caption, origin: item.value}, true]); + }); + me.btnFormula.on('click', function(){ + me.fireEvent('function:apply', [{name: 'more', origin: 'more'}]); + }); } - return { options: {}, initialize: function (options) { Common.UI.BaseView.prototype.initialize.call(this); this.toolbar = options.toolbar; - this.formulasGroups = options.formulasGroups; + this.formulasGroups = options.formulasGroups; this.lockedControls = []; @@ -88,7 +82,7 @@ define([ menu: true, split: false, disabled: true, - lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth] + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth] }); Common.Utils.injectComponent($host.find('#slot-btn-financial'), this.btnFinancial); this.lockedControls.push(this.btnFinancial); @@ -101,7 +95,7 @@ define([ menu: true, split: false, disabled: true, - lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth] + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth] }); Common.Utils.injectComponent($host.find('#slot-btn-logical'), this.btnLogical); this.lockedControls.push(this.btnLogical); @@ -114,7 +108,7 @@ define([ menu: true, split: false, disabled: true, - lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth] + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth] }); Common.Utils.injectComponent($host.find('#slot-btn-text'), this.btnTextData); this.lockedControls.push(this.btnTextData); @@ -127,7 +121,7 @@ define([ menu: true, split: false, disabled: true, - lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth] + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth] }); Common.Utils.injectComponent($host.find('#slot-btn-datetime'), this.btnDateTime); this.lockedControls.push(this.btnDateTime); @@ -140,7 +134,7 @@ define([ menu: true, split: false, disabled: true, - lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth] + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth] }); Common.Utils.injectComponent($host.find('#slot-btn-lookup'), this.btnReference); this.lockedControls.push(this.btnReference); @@ -153,11 +147,60 @@ define([ menu: true, split: false, disabled: true, - lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth] + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth] }); Common.Utils.injectComponent($host.find('#slot-btn-math'), this.btnMath); this.lockedControls.push(this.btnMath); + this.btnRecent = new Common.UI.Button({ + cls: 'btn-toolbar x-huge icon-top', + iconCls: 'btn-cell-group', + caption: this.txtRecent, + hint: this.txtRecent, + menu: true, + split: false, + disabled: true, + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth] + }); + Common.Utils.injectComponent($host.find('#slot-btn-recent'), this.btnRecent); + this.lockedControls.push(this.btnRecent); + + this.btnAutosum = new Common.UI.Button({ + cls: 'btn-toolbar x-huge icon-top', + iconCls: 'btn-cell-group', + caption: this.txtAutosum, + hint: this.txtAutosumTip, + split: true, + disabled: true, + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth], + menu: new Common.UI.Menu({ + items : [ + {caption: 'SUM', value: 'SUM'}, + {caption: 'MIN', value: 'MIN'}, + {caption: 'MAX', value: 'MAX'}, + {caption: 'COUNT', value: 'COUNT'}, + {caption: '--'}, + { + caption: me.txtAdditional, + value: 'more' + } + ] + }) + }); + Common.Utils.injectComponent($host.find('#slot-btn-autosum'), this.btnAutosum); + this.lockedControls.push(this.btnAutosum); + + this.btnFormula = new Common.UI.Button({ + cls: 'btn-toolbar x-huge icon-top', + iconCls: 'btn-cell-group', + caption: this.txtFormula, + hint: this.txtFormulaTip, + disabled: true, + lock: [_set.editText, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selRangeEdit, _set.lostConnect, _set.coAuth] + }); + Common.Utils.injectComponent($host.find('#slot-btn-additional-formula'), this.btnFormula); + this.lockedControls.push(this.btnFormula); + Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); }, @@ -170,7 +213,7 @@ define([ (new Promise(function (accept, reject) { accept(); })).then(function(){ - // setEvents.call(me); + setEvents.call(me); }); }, @@ -191,64 +234,78 @@ define([ }, this); }, + setButtonMenu: function(btn, name) { + var me = this, + arr = [], + group = me.formulasGroups.findWhere({name : name}); + + if (group) { + var functions = group.get('functions'); + functions && functions.forEach(function(item) { + arr.push(new Common.UI.MenuItem({ + caption: item.get('name'), + value: item.get('origin') + })); + }); + arr.push(new Common.UI.MenuItem({ + caption: '--' + })); + arr.push(new Common.UI.MenuItem({ + caption: me.txtAdditional, + value: 'more' + })); + + } + if (arr.length) { + if (btn.menu && btn.menu.rendered) { + btn.menu.removeAll(); + arr.forEach(function(item){ + btn.menu.addItem(item); + }); + } else { + btn.setMenu(new Common.UI.Menu({ + restoreHeight: 415, + items: arr + })); + btn.menu.on('item:click', function (menu, item, e) { + me.fireEvent('function:apply', [{name: item.caption, origin: item.value}]); + }); + } + } + btn.setDisabled(arr.length<1); + }, + fillFunctions: function () { if (this.formulasGroups) { - var me = this; - var setMenu = function(btn, name) { - var i = 0, - length = 0, - functions = null, - arr = [], - group = me.formulasGroups.findWhere({name : name}); + this.setButtonMenu(this.btnFinancial, 'Financial'); + this.setButtonMenu(this.btnLogical, 'Logical'); + this.setButtonMenu(this.btnTextData, 'TextAndData'); + this.setButtonMenu(this.btnDateTime, 'DateAndTime'); + this.setButtonMenu(this.btnReference, 'LookupAndReference'); + this.setButtonMenu(this.btnMath, 'Mathematic'); + this.setButtonMenu(this.btnRecent, 'Last10'); - if (group) { - functions = group.get('functions'); - functions && functions.forEach(function(item) { - arr.push(new Common.UI.MenuItem({ - caption: item.get('name'), - value: item.get('origin') - })); - }); - } - if (arr.length) { - if (btn.menu && btn.menu.rendered) { - btn.menu.removeAll(); - arr.forEach(function(item){ - btn.menu.addItem(item); - }); - } else { - btn.setMenu(new Common.UI.Menu({ - restoreHeight: 415, - items: arr - })); - btn.menu.on('item:click', function (menu, item, e) { - me.fireEvent('function:apply', [{name: item.caption, origin: item.value}]); - }); - } - } - btn.setDisabled(arr.length<1); - }; - - setMenu(this.btnFinancial, 'Financial'); - setMenu(this.btnLogical, 'Logical'); - setMenu(this.btnTextData, 'TextAndData'); - setMenu(this.btnDateTime, 'DateAndTime'); - setMenu(this.btnReference, 'LookupAndReference'); - setMenu(this.btnMath, 'Mathematic'); + var formulas = this.btnAutosum.menu.items; + for (var i=0; i