[FIX] [FIX] Fix needaction counters, now updated dynamically.

Needaction counters are now updated :
- when loading the menus (as before),
- when performing an action in a form view (update the current menu),
- when cliking on a top-level menu item (update all childs menus)

bzr revid: tde@openerp.com-20130426093653-gwdciylu26nfntzp
This commit is contained in:
Thibault Delavallée 2013-04-26 11:36:53 +02:00
commit dd09b3185b
3 changed files with 43 additions and 6 deletions

View File

@ -863,9 +863,7 @@ instance.web.Menu = instance.web.Widget.extend({
self.reflow();
// launch the fetch of needaction counters, asynchronous
if (!_.isEmpty(menu_data.all_menu_ids)) {
this.rpc("/web/menu/load_needaction", {menu_ids: menu_data.all_menu_ids}).done(function(r) {
self.on_needaction_loaded(r);
});
this.do_load_needaction(menu_data.all_menu_ids);
}
});
var lazyreflow = _.debounce(this.reflow.bind(this), 200);
@ -891,7 +889,7 @@ instance.web.Menu = instance.web.Widget.extend({
this.data = {data: data};
this.renderElement();
this.$secondary_menus.html(QWeb.render("Menu.secondary", { widget : this }));
this.$el.on('click', 'a[data-menu]', this.on_menu_click);
this.$el.on('click', 'a[data-menu]', this.on_top_menu_click);
// Hide second level submenus
this.$secondary_menus.find('.oe_menu_toggler').siblings('.oe_secondary_submenu').hide();
if (self.current_menu) {
@ -900,6 +898,12 @@ instance.web.Menu = instance.web.Widget.extend({
this.trigger('menu_loaded', data);
this.has_been_loaded.resolve();
},
do_load_needaction: function (menu_ids) {
var self = this;
return this.rpc("/web/menu/load_needaction", {'menu_ids': menu_ids}).done(function(r) {
self.on_needaction_loaded(r);
});
},
on_needaction_loaded: function(data) {
var self = this;
this.needaction_data = data;
@ -1031,11 +1035,36 @@ instance.web.Menu = instance.web.Widget.extend({
}
this.open_menu(id);
},
do_reload_needaction: function () {
var self = this;
self.do_load_needaction([self.current_menu]).then(function () {
self.trigger("need_action_reloaded");
});
},
/**
* Jquery event handler for menu click
*
* @param {Event} ev the jquery event
*/
on_top_menu_click: function(ev) {
var self = this;
var id = $(ev.currentTarget).data('menu');
var menu_ids = [id];
var menu = _.filter(this.data.data.children, function (menu) {return menu.id == id;})[0];
function add_menu_ids (menu) {
if (menu.children) {
_.each(menu.children, function (menu) {
menu_ids.push(menu.id);
add_menu_ids(menu);
});
}
};
add_menu_ids(menu);
self.do_load_needaction(menu_ids).then(function () {
self.trigger("need_action_reloaded");
});
this.on_menu_click(ev);
},
on_menu_click: function(ev) {
ev.preventDefault();
var needaction = $(ev.target).is('div.oe_menu_counter');

View File

@ -91,6 +91,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
this.ViewManager = parent;
this.set_default_options(options);
this.dataset = dataset;
this.model = dataset.model;
@ -720,6 +721,8 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
return this.save().done(function(result) {
self.trigger("save", result);
self.to_view_mode();
}).then(function(result) {
self.ViewManager.ActionManager.__parentedParent.menu.do_reload_needaction();
});
},
on_button_cancel: function(event) {

View File

@ -521,6 +521,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
return x;
}
});
this.ActionManager = parent;
this.views = {};
this.flags = flags || {};
this.registry = instance.web.views;
@ -1259,6 +1260,7 @@ instance.web.View = instance.web.Widget.extend({
view_type: undefined,
init: function(parent, dataset, view_id, options) {
this._super(parent);
this.ViewManager = parent;
this.dataset = dataset;
this.view_id = view_id;
this.set_default_options(options);
@ -1330,7 +1332,6 @@ instance.web.View = instance.web.Widget.extend({
}
};
var context = new instance.web.CompoundContext(dataset.get_context(), action_data.context || {});
var handler = function (action) {
if (action && action.constructor == Object) {
var ncontext = new instance.web.CompoundContext(context);
@ -1367,7 +1368,11 @@ instance.web.View = instance.web.Widget.extend({
}
}
args.push(context);
return dataset.call_button(action_data.name, args).then(handler);
return dataset.call_button(action_data.name, args).then(handler).then(function () {
if (self.ViewManager.ActionManager) {
self.ViewManager.ActionManager.__parentedParent.menu.do_reload_needaction();
}
});
} else if (action_data.type=="action") {
return this.rpc('/web/action/load', {
action_id: action_data.name,