[IMP] lot of small improvements to better detect when a view has finished loading

bzr revid: nicolas.vanhoren@openerp.com-20121213140914-8d1u01h17r2x4fpu
This commit is contained in:
niv-openerp 2012-12-13 15:09:14 +01:00
parent 5bc1a17026
commit 906ceba948
11 changed files with 52 additions and 26 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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, {

View File

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

View File

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

View File

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

View File

@ -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) {

View File

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