[IMP] web_menu_navbar_needaction: reflow, new features (#265)

[IMP] web_menu_navbar_needaction: Several improvements:

* Make the menu reflow after updating needactions
* Allow to disable needaction completely or to set a custom domain
* Support for clicking the number to end up on the first action
* No need to block the UI for our request
* Don't crash on corner cases, filter out search defaults from context, disable custom filters
* Allow to define needaction domains for any menu
* Support server actions
* Support models implementing the function, but not the interface
* Show a main menu's child needaction counters
This commit is contained in:
Holger Brunn
2016-09-20 21:34:55 +02:00
committed by Pedro M. Baeza
parent 6e35172b30
commit 82088b11e1
6 changed files with 177 additions and 12 deletions

View File

@@ -2,3 +2,7 @@
{
margin-left: .3em;
}
#oe_main_menu_navbar .badge:hover
{
transform: scale(1.1);
}

View File

@@ -50,29 +50,72 @@ openerp.web_menu_navbar_needaction = function(instance)
.map(function() { return parseInt(jQuery(this).attr('data-menu')); })
.get();
return new instance.web.Model('ir.ui.menu')
.call('get_navbar_needaction_data', [this.navbar_menu_ids])
.call('get_navbar_needaction_data', [this.navbar_menu_ids],
{}, {shadow: true})
.then(this.proxy(this.process_navbar_needaction));
},
process_navbar_needaction: function(data)
{
var self = this;
_.each(data, function (needaction_count, menu_id)
_.each(data, function (needaction_data, menu_id)
{
var $item = self.$el.parents('body').find(
_.str.sprintf('#oe_main_menu_navbar a[data-menu="%s"]',
menu_id));
if(!$item.length)
if(!$item.length || _.isEmpty(needaction_data))
{
return;
}
$item.find('.badge').remove();
if(needaction_count)
if(needaction_data.count)
{
$item.append(
instance.web.qweb.render("Menu.needaction_counter",
{widget : {needaction_counter: needaction_count}}));
var $counter = jQuery(
instance.web.qweb.render("Menu.needaction_counter",
{
widget: {
needaction_counter: needaction_data.count,
}
}))
.appendTo($item);
if(needaction_data.action_id)
{
$counter.click(function(ev)
{
var parent = self.getParent();
ev.stopPropagation();
ev.preventDefault();
return parent.menu_dm.add(
self.rpc('/web/action/load', {
action_id: needaction_data.action_id,
}))
.then(function(action)
{
return parent.action_mutex.exec(function()
{
action.domain = needaction_data.action_domain;
action.context = new instance.web.CompoundContext(
action.context || {}
);
action.context = instance.web.pyeval.eval(
'context', action.context
);
_.each(_.keys(action.context), function(key)
{
if(key.startsWith('search_default'))
{
delete action.context[key];
}
});
return parent.action_manager.do_action(
action, {disable_custom_filters: true}
);
});
});
});
}
}
});
instance.web.bus.trigger('resize');
},
})