From c6c0bfffc2e1d519f6a706383b182127ca6e4644 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 13 Aug 2019 13:28:06 +0300 Subject: [PATCH] [SSE] Formula tab: fix position for menu item 'Additional' in More button --- apps/common/main/lib/extend/Bootstrap.js | 9 +- .../main/app/view/FormulaTab.js | 117 ++++++++++++------ 2 files changed, 87 insertions(+), 39 deletions(-) diff --git a/apps/common/main/lib/extend/Bootstrap.js b/apps/common/main/lib/extend/Bootstrap.js index ab8468c29..b7d4a582f 100755 --- a/apps/common/main/lib/extend/Bootstrap.js +++ b/apps/common/main/lib/extend/Bootstrap.js @@ -41,8 +41,8 @@ function onDropDownKeyDown(e) { var $this = $(this), $parent = $this.parent(), - beforeEvent = jQuery.Event('keydown.before.bs.dropdown'), - afterEvent = jQuery.Event('keydown.after.bs.dropdown'); + beforeEvent = jQuery.Event('keydown.before.bs.dropdown', {keyCode: e.keyCode}), + afterEvent = jQuery.Event('keydown.after.bs.dropdown', {keyCode: e.keyCode}); $parent.trigger(beforeEvent); @@ -110,8 +110,9 @@ function patchDropDownKeyDown(e) { _.delay(function() { var mnu = $('> [role=menu]', li), $subitems = mnu.find('> li:not(.divider):not(.disabled):visible > a'), - $dataviews = mnu.find('> li:not(.divider):not(.disabled):visible .dataview'); - if ($subitems.length>0 && $dataviews.length<1) + $dataviews = mnu.find('> li:not(.divider):not(.disabled):visible .dataview'), + $internal_menu = mnu.find('> li:not(.divider):not(.disabled):visible ul.internal-menu'); + if ($subitems.length>0 && $dataviews.length<1 && $internal_menu.length<1) ($subitems.index($subitems.filter(':focus'))<0) && $subitems.eq(0).focus(); }, 250); } diff --git a/apps/spreadsheeteditor/main/app/view/FormulaTab.js b/apps/spreadsheeteditor/main/app/view/FormulaTab.js index 098ba5deb..3ee7e83cc 100644 --- a/apps/spreadsheeteditor/main/app/view/FormulaTab.js +++ b/apps/spreadsheeteditor/main/app/view/FormulaTab.js @@ -320,6 +320,72 @@ define([ btn.setDisabled(arr.length<1); }, + setMenuItemMenu: function(name) { + var me = this, + arr = [], + formulaDialog = SSE.getController('FormulaDialog'), + 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') + })); + }); + if (arr.length) { + var mnu = new Common.UI.MenuItem({ + caption : formulaDialog['sCategory' + name] || name, + menu: new Common.UI.Menu({ + menuAlign: 'tl-tr', + items: [ + {template: _.template('
')}, + { caption: '--' }, + { + caption: me.txtAdditional, + value: 'more' + } + ] + }) + }); + mnu.menu.items[2].on('click', function (item, e) { + me.fireEvent('function:apply', [{name: item.caption, origin: item.value}, false, name]); + }); + mnu.menu.on('show:after', function (menu, e) { + var internalMenu = menu.items[0]._internalMenu; + internalMenu.scroller.update({alwaysVisibleY: true}); + _.delay(function() { + menu.items[0]._internalMenu && menu.items[0]._internalMenu.cmpEl.focus(); + }, 10); + }).on('keydown:before', function(menu, e) { + if (e.keyCode == Common.UI.Keys.RETURN) { + e.preventDefault(); + e.stopPropagation(); + } else if (e.keyCode == Common.UI.Keys.LEFT || e.keyCode == Common.UI.Keys.ESC) { + var $parent = menu.cmpEl.parent(); + if ($parent.hasClass('dropdown-submenu') && $parent.hasClass('over')) { // close submenu + $parent.removeClass('over'); + $parent.find('> a').focus(); + } + } + } ); + + // internal menu + var menu = new Common.UI.Menu({ + maxHeight: 300, + cls: 'internal-menu', + items: arr + }); + menu.on('item:click', function (menu, item, e) { + me.fireEvent('function:apply', [{name: item.caption, origin: item.value}, false, name]); + }); + mnu.menu.items[0]._internalMenu = menu; + return mnu; + } + } + }, + fillFunctions: function () { if (this.formulasGroups) { this.setButtonMenu(this.btnFinancial, 'Financial'); @@ -337,41 +403,11 @@ define([ // more button var me = this, - morearr = [], - formulaDialog = SSE.getController('FormulaDialog'); + morearr = []; ['Cube', 'Database', 'Engineering', 'Information', 'Statistical'].forEach(function(name) { - var group = me.formulasGroups.findWhere({name : name}); - if (group) { - var functions = group.get('functions'), - arr = []; - functions && functions.forEach(function(item) { - arr.push(new Common.UI.MenuItem({ - caption: item.get('name'), - value: item.get('origin') - })); - }); - if (arr.length) { - arr.push(new Common.UI.MenuItem({ - caption: '--' - })); - arr.push(new Common.UI.MenuItem({ - caption: me.txtAdditional, - value: 'more' - })); - var mnu = new Common.UI.MenuItem({ - caption : formulaDialog['sCategory' + name] || name, - menu : new Common.UI.Menu({ - restoreHeight: 415, - menuAlign: 'tl-tr', - items: arr - }) - }); - mnu.menu.on('item:click', function (menu, item, e) { - me.fireEvent('function:apply', [{name: item.caption, origin: item.value}, false, name]); - }); - morearr.push(mnu); - } - } + var mnu = me.setMenuItemMenu(name); + mnu && morearr.push(mnu); + }); var btn = this.btnMore; if (morearr.length) { @@ -382,10 +418,21 @@ define([ }); } else { btn.setMenu(new Common.UI.Menu({ - restoreHeight: 415, items: morearr })); } + btn.menu.items.forEach(function(mnu){ + var menuContainer = mnu.menu.items[0].cmpEl.children(':first'), + menu = mnu.menu.items[0]._internalMenu; + menu.render(menuContainer); + menu.cmpEl.css({ + display : 'block', + position : 'relative', + left : 0, + top : 0 + }); + menu.cmpEl.attr({tabindex: "-1"}); + }); } btn.setDisabled(morearr.length<1); }