From 906ceba9488fafa9e7999526c90e7e6c61e69180 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 13 Dec 2012 15:09:14 +0100 Subject: [PATCH] [IMP] lot of small improvements to better detect when a view has finished loading bzr revid: nicolas.vanhoren@openerp.com-20121213140914-8d1u01h17r2x4fpu --- addons/web/static/src/js/chrome.js | 26 +++++++++++-------- addons/web/static/src/js/search.js | 2 +- addons/web/static/src/js/view_form.js | 4 ++- addons/web/static/src/js/view_list.js | 4 ++- addons/web/static/src/js/view_tree.js | 5 +++- addons/web/static/src/js/views.js | 16 +++++++----- addons/web_calendar/static/src/js/calendar.js | 4 ++- addons/web_diagram/static/src/js/diagram.js | 5 +++- addons/web_gantt/static/src/js/gantt.js | 4 ++- addons/web_graph/static/src/js/graph.js | 4 ++- addons/web_kanban/static/src/js/kanban.js | 4 ++- 11 files changed, 52 insertions(+), 26 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 56af4c9d564..fbe7fbde795 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1122,6 +1122,8 @@ instance.web.WebClient = instance.web.Client.extend({ init: function(parent) { this._super(parent); this._current_state = null; + this.menu_dm = new instance.web.DropMisordered(); + this.action_mutex = new $.Mutex(); }, start: function() { var self = this; @@ -1287,18 +1289,20 @@ instance.web.WebClient = instance.web.Client.extend({ }, on_menu_action: function(options) { var self = this; - return this.rpc("/web/action/load", { action_id: options.action_id }) + return this.menu_dm.add(this.rpc("/web/action/load", { action_id: options.action_id })) .then(function (result) { - if (options.needaction) { - result.context = new instance.web.CompoundContext( - result.context, - {search_default_message_unread: true}); - } - return $.when(self.action_manager.do_action(result, { - clear_breadcrumbs: true, - action_menu_id: self.menu.current_menu, - })).fail(function() { - self.menu.open_menu(options.previous_menu_id); + return self.action_mutex.exec(function() { + if (options.needaction) { + result.context = new instance.web.CompoundContext( + result.context, + {search_default_message_unread: true}); + } + return $.when(self.action_manager.do_action(result, { + clear_breadcrumbs: true, + action_menu_id: self.menu.current_menu, + })).fail(function() { + self.menu.open_menu(options.previous_menu_id); + }); }); }); }, diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index eea8bba726d..34ab101fea7 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -640,7 +640,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea .then(this.proxy('setup_default_query')); return $.when(drawer_started, defaults_fetched) - .done(function () { + .then(function () { self.trigger("search_view_loaded", data); self.ready.resolve(); }); diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 3f6952e5da4..f422ec01ed3 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -128,13 +128,15 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM self.init_pager(); }); self.on("load_record", self, self.load_record); - this.on('view_loaded', self, self.load_form); instance.web.bus.on('clear_uncommitted_changes', this, function(e) { if (!this.can_be_discarded()) { e.preventDefault(); } }); }, + view_loading: function(r) { + return this.load_form(r); + }, destroy: function() { _.each(this.get_widgets(), function(w) { w.off('focused blurred'); diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 04ff8b48923..f6794bd435c 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -90,7 +90,9 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi this.no_leaf = false; this.grouped = false; - this.on('view_loaded', self, self.load_list); + }, + view_loading: function(r) { + return this.load_list(r); }, set_default_options: function (options) { this._super(options); diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js index acac93f1842..2f9efad9171 100644 --- a/addons/web/static/src/js/view_tree.js +++ b/addons/web/static/src/js/view_tree.js @@ -37,7 +37,10 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie this.options = _.extend({}, this.defaults, options || {}); _.bindAll(this, 'color_for'); - this.on('view_loaded', this, this.load_tree); + }, + + view_loading: function(r) { + return this.load_tree(r); }, /** diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index c949762a5f6..2fe51bcf7e4 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -1186,32 +1186,36 @@ instance.web.View = instance.web.Widget.extend({ }, load_view: function(context) { var self = this; - var view_loaded; + var view_loaded_def; if (this.embedded_view) { - view_loaded = $.Deferred(); + view_loaded_def = $.Deferred(); $.async_when().done(function() { - view_loaded.resolve(self.embedded_view); + view_loaded_def.resolve(self.embedded_view); }); } else { if (! this.view_type) console.warn("view_type is not defined", this); - view_loaded = instance.web.fields_view_get({ + view_loaded_def = instance.web.fields_view_get({ "model": this.dataset._model, "view_id": this.view_id, "view_type": this.view_type, "toolbar": !!this.options.$sidebar, }); } - return view_loaded.then(function(r) { + return view_loaded_def.then(function(r) { self.fields_view = r; - self.trigger('view_loaded', r); // add css classes that reflect the (absence of) access rights self.$el.addClass('oe_view') .toggleClass('oe_cannot_create', !self.is_action_enabled('create')) .toggleClass('oe_cannot_edit', !self.is_action_enabled('edit')) .toggleClass('oe_cannot_delete', !self.is_action_enabled('delete')); + return $.when(self.view_loading(r)).then(function() { + self.trigger('view_loaded', r); + }); }); }, + view_loading: function(r) { + }, set_default_options: function(options) { this.options = options || {}; _.defaults(this.options, { diff --git a/addons/web_calendar/static/src/js/calendar.js b/addons/web_calendar/static/src/js/calendar.js index 46d25e749a2..81e7712ff1f 100644 --- a/addons/web_calendar/static/src/js/calendar.js +++ b/addons/web_calendar/static/src/js/calendar.js @@ -49,7 +49,9 @@ instance.web_calendar.CalendarView = instance.web.View.extend({ this.range_stop = null; this.update_range_dates(Date.today()); this.selected_filters = []; - this.on('view_loaded', self, self.load_calendar); + }, + view_loading: function(r) { + return this.load_calendar(r); }, destroy: function() { scheduler.clearAll(); diff --git a/addons/web_diagram/static/src/js/diagram.js b/addons/web_diagram/static/src/js/diagram.js index 00b2cdfe0ae..2d3e3cc6b45 100644 --- a/addons/web_diagram/static/src/js/diagram.js +++ b/addons/web_diagram/static/src/js/diagram.js @@ -22,10 +22,13 @@ instance.web.DiagramView = instance.web.View.extend({ this.domain = this.dataset._domain || []; this.context = {}; this.ids = this.dataset.ids; - this.on('view_loaded', self, self.load_diagram); this.on('pager_action_executed', self, self.pager_action_trigger); }, + view_loading: function(r) { + return this.load_diagram(r); + }, + toTitleCase: function(str) { return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); }, diff --git a/addons/web_gantt/static/src/js/gantt.js b/addons/web_gantt/static/src/js/gantt.js index ebbf04926ed..dbe5a33fcca 100644 --- a/addons/web_gantt/static/src/js/gantt.js +++ b/addons/web_gantt/static/src/js/gantt.js @@ -16,7 +16,9 @@ instance.web_gantt.GanttView = instance.web.View.extend({ this._super.apply(this, arguments); this.has_been_loaded = $.Deferred(); this.chart_id = _.uniqueId(); - this.on('view_loaded', self, self.load_gantt); + }, + view_loading: function(r) { + return this.load_gantt(r); }, load_gantt: function(fields_view_get, fields_get) { var self = this; diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 282822d6cba..35ad0aaaea8 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -42,7 +42,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.group_by = []; this.graph = null; - this.on('view_loaded', self, self.load_graph); + }, + view_loading: function(r) { + return this.load_graph(r); }, destroy: function () { if (this.graph) { diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index 982c27c03fc..88ff146aee9 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.js @@ -43,7 +43,9 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ this.currently_dragging = {}; this.limit = options.limit || 40; this.add_group_mutex = new $.Mutex(); - this.on('view_loaded', self, self.load_kanban); + }, + view_loading: function(r) { + return this.load_kanban(r); }, start: function() { var self = this;