Merge pull request #227 from ONLYOFFICE/feature/sse-formula-tab-additional

Feature/sse formula tab additional
This commit is contained in:
Julia Radzhabova 2019-08-14 15:47:07 +03:00 committed by GitHub
commit 2e38661ebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 175 additions and 54 deletions

View file

@ -409,6 +409,10 @@ define([
},
onAfterKeydownMenu: function(e) {
this.trigger('keydown:before', this, e);
if (e.isDefaultPrevented())
return;
if (e.keyCode == Common.UI.Keys.RETURN) {
var li = $(e.target).closest('li');
if (li.length<=0) li = $(e.target).parent().find('li .dataview');

View file

@ -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);
}

View file

@ -16,6 +16,15 @@
}
}
&.internal-menu {
border: none;
border-radius: 0;
.box-shadow(none);
margin: 0;
padding: 0;
overflow: hidden;
}
li {
& > a {
padding: 5px 20px;

View file

@ -247,6 +247,40 @@ define([
}, this);
},
focusInner: function(menu, e) {
if (e.keyCode == Common.UI.Keys.UP)
menu.items[menu.items.length-1].cmpEl.find('> a').focus();
else
menu.items[0].cmpEl.find('> a').focus();
},
focusOuter: function(menu, e) {
menu.items[2].cmpEl.find('> a').focus();
},
onBeforeKeyDown: function(menu, e) {
if (e.keyCode == Common.UI.Keys.RETURN) {
e.preventDefault();
e.stopPropagation();
var li = $(e.target).closest('li');
(li.length>0) && li.click();
Common.UI.Menu.Manager.hideAll();
} else if (e.namespace!=="after.bs.dropdown" && (e.keyCode == Common.UI.Keys.DOWN || e.keyCode == Common.UI.Keys.UP)) {
var $items = $('> [role=menu] > li:not(.divider):not(.disabled):visible', menu.$el).find('> a');
if (!$items.length) return;
var index = $items.index($items.filter(':focus')),
me = this;
if (menu._outerMenu && (e.keyCode == Common.UI.Keys.UP && index==0 || e.keyCode == Common.UI.Keys.DOWN && index==$items.length - 1) ||
menu._innerMenu && (e.keyCode == Common.UI.Keys.UP || e.keyCode == Common.UI.Keys.DOWN) && index!==-1) {
e.preventDefault();
e.stopPropagation();
_.delay(function() {
menu._outerMenu ? me.focusOuter(menu._outerMenu, e) : me.focusInner(menu._innerMenu, e);
}, 10);
}
}
},
setButtonMenu: function(btn, name) {
var me = this,
arr = [],
@ -262,32 +296,124 @@ define([
});
}
if (arr.length) {
arr.push(new Common.UI.MenuItem({
caption: '--'
}));
arr.push(new Common.UI.MenuItem({
caption: me.txtAdditional,
value: 'more'
}));
if (btn.menu && btn.menu.rendered) {
btn.menu.removeAll();
arr.forEach(function(item){
btn.menu.addItem(item);
});
var menu = btn.menu._innerMenu;
if (menu) {
menu.removeAll();
arr.forEach(function(item){
menu.addItem(item);
});
}
} else {
btn.setMenu(new Common.UI.Menu({
restoreHeight: 415,
items: arr
items: [
{template: _.template('<div id="id-toolbar-formula-menu-'+ name +'" style="display: flex;" class="open"></div>')},
{ caption: '--' },
{
caption: me.txtAdditional,
value: 'more'
}
]
}));
btn.menu.on('item:click', function (menu, item, e) {
btn.menu.items[2].on('click', function (item, e) {
me.fireEvent('function:apply', [{name: item.caption, origin: item.value}, false, name]);
});
btn.menu.on('show:after', function (menu, e) {
var internalMenu = menu._innerMenu;
internalMenu.scroller.update({alwaysVisibleY: true});
_.delay(function() {
menu._innerMenu && menu._innerMenu.cmpEl.focus();
}, 10);
}).on('keydown:before', _.bind(me.onBeforeKeyDown, this));
var menu = new Common.UI.Menu({
maxHeight: 300,
cls: 'internal-menu',
items: arr
});
menu.render(btn.menu.items[0].cmpEl.children(':first'));
menu.cmpEl.css({
display : 'block',
position : 'relative',
left : 0,
top : 0
});
menu.cmpEl.attr({tabindex: "-1"});
menu.on('item:click', function (menu, item, e) {
me.fireEvent('function:apply', [{name: item.caption, origin: item.value}, false, name]);
}).on('keydown:before', _.bind(me.onBeforeKeyDown, this));
btn.menu._innerMenu = menu;
menu._outerMenu = btn.menu;
}
}
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('<div id="id-toolbar-formula-menu-'+ name +'" style="display: flex;" class="open"></div>')},
{ 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._innerMenu;
internalMenu.scroller.update({alwaysVisibleY: true});
_.delay(function() {
menu._innerMenu && menu._innerMenu.items[0].cmpEl.find('> a').focus();
}, 10);
}).on('keydown:before', _.bind(me.onBeforeKeyDown, this))
.on('keydown:before', function(menu, e) {
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]);
}).on('keydown:before', _.bind(me.onBeforeKeyDown, this));
mnu.menu._innerMenu = menu;
menu._outerMenu = mnu.menu;
return mnu;
}
}
},
fillFunctions: function () {
if (this.formulasGroups) {
this.setButtonMenu(this.btnFinancial, 'Financial');
@ -305,41 +431,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) {
@ -350,10 +446,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._innerMenu;
menu.render(menuContainer);
menu.cmpEl.css({
display : 'block',
position : 'relative',
left : 0,
top : 0
});
menu.cmpEl.attr({tabindex: "-1"});
});
}
btn.setDisabled(morearr.length<1);
}