summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2013-04-26 11:36:53 +0200
committerThibault Delavallée <tde@openerp.com>2013-04-26 11:36:53 +0200
commitdd09b3185bb15c4f360f91bf683feff28e33dc5b (patch)
treeac60881d4b3ac4262fc60c5e1cd10c428499ff64
parent2397513664cc85c56696bb34f2e2da98f2d25f97 (diff)
parent1088554b40640ba3e81d25e19bfe49607a92c28a (diff)
[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
-rw-r--r--addons/web/static/src/js/chrome.js37
-rw-r--r--addons/web/static/src/js/view_form.js3
-rw-r--r--addons/web/static/src/js/views.js9
3 files changed, 43 insertions, 6 deletions
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js
index 02228a96b06..e6870b82629 100644
--- a/addons/web/static/src/js/chrome.js
+++ b/addons/web/static/src/js/chrome.js
@@ -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');
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 7a853a579cb..b9dfa8e284a 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -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) {
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index 0a7250397f7..eb4d4bb0b11 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -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,