[MERGE] trunk-trigger-on_loaded.

bzr revid: vta@openerp.com-20121018121022-h7y6qccvky7qg45d
This commit is contained in:
vta vta@openerp.com 2012-10-18 14:10:22 +02:00
commit 70f41ea726
11 changed files with 61 additions and 41 deletions

View File

@ -701,9 +701,12 @@ instance.web.Menu = instance.web.Widget.extend({
return this.do_reload();
},
do_reload: function() {
return this.rpc("/web/menu/load", {}).then(this.on_loaded);
var self = this;
return this.rpc("/web/menu/load", {}).then(function(r) {
self.menu_loaded(r);
});
},
on_loaded: function(data) {
menu_loaded: function(data) {
var self = this;
this.data = data;
this.renderElement();
@ -720,6 +723,7 @@ instance.web.Menu = instance.web.Widget.extend({
if (self.current_menu) {
self.open_menu(self.current_menu);
}
this.trigger('menu_loaded', data);
this.has_been_loaded.resolve();
},
limit_entries: function() {

View File

@ -324,8 +324,9 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
context: this.dataset.get_context() });
$.when(load_view)
.pipe(this.on_loaded)
.fail(function () {
.pipe(function(r) {
self.search_view_loaded(r)
}).fail(function () {
self.ready.reject.apply(null, arguments);
});
}
@ -645,7 +646,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
(new instance.web.search.Advanced(this));
},
on_loaded: function(data) {
search_view_loaded: function(data) {
var self = this;
this.fields_view = data.fields_view;
if (data.fields_view.type !== 'search' ||
@ -654,7 +655,6 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
"Got non-search view after asking for a search view: type %s, arch root %s",
data.fields_view.type, data.fields_view.arch.tag));
}
this.make_widgets(
data.fields_view['arch'].children,
data.fields_view.fields);
@ -671,9 +671,12 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
'facet_for_defaults', this.defaults)).then(function () {
self.query.reset(_(arguments).compact(), {preventSearch: true});
});
return $.when(drawer_started, defaults_fetched)
.then(function () { self.ready.resolve(); })
.then(function () {
self.trigger("search_view_loaded", data);
self.ready.resolve();
});
},
/**
* Handle event when the user make a selection in the filters management select box.

View File

@ -127,6 +127,7 @@ 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();
@ -143,13 +144,13 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
}
this._super();
},
on_loaded: function(data) {
load_form: function(data) {
var self = this;
if (!data) {
throw new Error("No data provided.");
}
if (this.arch) {
throw "Form view does not support multiple calls to on_loaded";
throw "Form view does not support multiple calls to load_form";
}
this.fields_order = [];
this.fields_view = data;
@ -213,7 +214,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
e.stopPropagation();
}
});
this.trigger('form_view_loaded', data);
return $.when();
},
widgetFocused: function() {
@ -3802,7 +3803,7 @@ instance.web.form.One2ManyList = instance.web.ListView.List.extend({
instance.web.form.One2ManyFormView = instance.web.FormView.extend({
form_template: 'One2Many.formview',
on_loaded: function(data) {
load_form: function(data) {
this._super(data);
var self = this;
this.$buttons.find('button.oe_form_button_create').click(function() {
@ -4012,7 +4013,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({
}
this.list_view.m2m_field = this;
var loaded = $.Deferred();
this.list_view.on_loaded.add_last(function() {
this.list_view.on("list_view_loaded", self, function() {
self.initial_is_loaded.resolve();
loaded.resolve();
});
@ -4132,7 +4133,7 @@ instance.web.form.FieldMany2ManyKanban = instance.web.form.AbstractField.extend(
}
this.kanban_view.m2m = this;
var loaded = $.Deferred();
this.kanban_view.on_loaded.add_last(function() {
this.kanban_view.on("kanban_view_loaded",self,function() {
self.initial_is_loaded.resolve();
loaded.resolve();
});
@ -4356,7 +4357,7 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({
this.view_form.set_embedded_view(this.options.alternative_form_view);
}
this.view_form.appendTo(this.$el.find(".oe_popup_form"));
this.view_form.on_loaded.add_last(function() {
this.view_form.on("form_view_loaded", self, function() {
var multi_select = self.row_id === null && ! self.options.disable_multiple_selection;
self.$buttonpane.html(QWeb.render("AbstractFormPopup.buttons", {
multi_select: multi_select,
@ -4476,7 +4477,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
self.do_search(domains.concat([self.domain]), contexts.concat(self.context), groupbys);
}
});
this.searchview.on_loaded.add_last(function () {
this.searchview.on("search_view_loaded", self, function() {
self.view_list = new instance.web.form.SelectCreateListView(self,
self.dataset, false,
_.extend({'deletable': false,
@ -4493,7 +4494,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
}).pipe(function() {
self.searchview.do_search();
});
self.view_list.on_loaded.add_last(function() {
self.view_list.on("list_view_loaded", self, function() {
self.$buttonpane.html(QWeb.render("SelectCreatePopup.search.buttons", {widget:self}));
var $cbutton = self.$buttonpane.find(".oe_selectcreatepopup-search-close");
$cbutton.click(function() {

View File

@ -83,6 +83,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
});
this.no_leaf = false;
this.on('view_load', self, self.load_list);
},
set_default_options: function (options) {
this._super(options);
@ -218,7 +219,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
* @param {Object} data.fields_view.arch current list view descriptor
* @param {Boolean} grouped Is the list view grouped
*/
on_loaded: function(data, grouped) {
load_list: function(data, grouped) {
var self = this;
this.fields_view = data;
this.name = "" + this.fields_view.arch.attrs.string;
@ -358,6 +359,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
this.sidebar.add_toolbar(this.fields_view.toolbar);
this.sidebar.$el.hide();
}
this.trigger('list_view_loaded', data, grouped);
},
/**
* Configures the ListView pager based on the provided dataset's information
@ -468,7 +470,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
reload_view: function (grouped, context, initial) {
var self = this;
var callback = function (field_view_get) {
self.on_loaded(field_view_get, grouped);
self.load_list(field_view_get, grouped);
};
if (this.embedded_view) {
return $.Deferred().then(callback).resolve(this.embedded_view);

View File

@ -100,7 +100,7 @@ openerp.web.list_editable = function (instance) {
this._super();
}
},
on_loaded: function (data, grouped) {
load_list: function (data, grouped) {
var self = this;
// tree/@editable takes priority on everything else if present.
var result = this._super(data, grouped);

View File

@ -1135,11 +1135,13 @@ instance.web.View = instance.web.Widget.extend({
return this.load_view();
},
load_view: function() {
var self = this;
if (this.embedded_view) {
var def = $.Deferred();
var self = this;
$.async_when().then(function() {def.resolve(self.embedded_view);});
return def.pipe(this.on_loaded);
return def.pipe(function(r) {
self.trigger('view_loaded', r);
});
} else {
var context = new instance.web.CompoundContext(this.dataset.get_context());
if (! this.view_type)
@ -1150,15 +1152,11 @@ instance.web.View = instance.web.Widget.extend({
"view_type": this.view_type,
toolbar: !!this.options.$sidebar,
context: context
}).pipe(this.on_loaded);
}).pipe(function(r) {
self.trigger('view_loaded', r);
});
}
},
/**
* Called after a successful call to fields_view_get.
* Must return a promise.
*/
on_loaded: function(fields_view_get) {
},
set_default_options: function(options) {
this.options = options || {};
_.defaults(this.options, {

View File

@ -12,6 +12,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
display_name: _lt('Calendar'),
// Dhtmlx scheduler ?
init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
this.ready = $.Deferred();
this.set_default_options(options);
@ -38,6 +39,7 @@ 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);
},
start: function() {
this._super();
@ -47,7 +49,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
scheduler.clearAll();
this._super();
},
on_loaded: function(data) {
load_calendar: function(data) {
this.fields_view = data;
this.$el.addClass(this.fields_view.arch.attrs['class']);
this.calendar_fields = {};
@ -106,7 +108,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
this.sidebar = new instance.web_calendar.Sidebar(this);
this.has_been_loaded.pipe(this.sidebar.appendTo(this.$el.find('.oe_calendar_sidebar_container')));
}
this.trigger('calendar_view_loaded', data);
return this.has_been_loaded.resolve();
},
init_scheduler: function() {

View File

@ -11,6 +11,7 @@ instance.web.DiagramView = instance.web.View.extend({
display_name: _lt('Diagram'),
searchable: false,
init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
this.set_default_options(options);
this.view_manager = parent;
@ -20,17 +21,20 @@ 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);
},
start: function() {
return this.rpc("/web_diagram/diagram/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded);
var self = this;
return this.rpc("/web_diagram/diagram/load", {"model": this.model, "view_id": this.view_id}).then(function(r) {
self.load_diagram(r);
});
},
toTitleCase: function(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
},
on_loaded: function(result) {
load_diagram: function(result) {
var self = this;
if(this.ids && this.ids.length) {
this.id = this.ids[self.dataset.index || 0];
@ -47,7 +51,7 @@ instance.web.DiagramView = instance.web.View.extend({
return label.tag == "label";
});
this.$el.html(QWeb.render("DiagramView", {'widget': this}));
this.$el.html(QWeb.render("DiagramView", {'widget': self}));
this.$el.addClass(this.fields_view.arch.attrs['class']);
_.each(self.labels,function(label){
@ -68,7 +72,7 @@ instance.web.DiagramView = instance.web.View.extend({
if(this.id) {
self.get_diagram_info();
}
this.trigger('diagram_view_loaded', result);
},
get_diagram_info: function() {

View File

@ -12,11 +12,13 @@ instance.web_gantt.GanttView = instance.web.View.extend({
template: "GanttView",
view_type: "gantt",
init: function() {
var self = this;
this._super.apply(this, arguments);
this.has_been_loaded = $.Deferred();
this.chart_id = _.uniqueId();
this.on('view_loaded', self, self.load_gantt);
},
on_loaded: function(fields_view_get, fields_get) {
load_gantt: function(fields_view_get, fields_get) {
var self = this;
this.fields_view = fields_view_get;
this.$el.addClass(this.fields_view.arch.attrs['class']);

View File

@ -23,6 +23,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
view_type: "graph",
init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
this.set_default_options(options);
this.dataset = dataset;
@ -41,6 +42,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
this.group_by = [];
this.graph = null;
this.on('view_loaded', self, self.load_graph);
},
destroy: function () {
if (this.graph) {
@ -49,7 +51,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
this._super();
},
on_loaded: function(fields_view_get) {
load_graph: function(fields_view_get) {
// TODO: move to load_view and document
var self = this;
this.fields_view = fields_view_get;
@ -98,7 +100,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
self.forcehtml = false;
});
});
return this._super();
this.trigger('graph_view_loaded', fields_view_get);
},
get_format: function (options) {

View File

@ -14,6 +14,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
number_of_color_schemes: 10,
init: function (parent, dataset, view_id, options) {
this._super(parent, dataset, view_id, options);
var self = this;
_.defaults(this.options, {
"quick_creatable": true,
"creatable": true,
@ -41,6 +42,7 @@ 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);
},
start: function() {
var self = this;
@ -55,7 +57,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
this._super.apply(this, arguments);
$('html').off('click.kanban');
},
on_loaded: function(data) {
load_kanban: function(data) {
this.fields_view = data;
this.$el.addClass(this.fields_view.arch.attrs['class']);
this.$buttons = $(QWeb.render("KanbanView.buttons", {'widget': this}));
@ -71,7 +73,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
this.fields_keys = _.keys(this.fields_view.fields);
this.add_qweb_template();
this.has_been_loaded.resolve();
this._super.apply(this, arguments);
this.trigger('kanban_view_loaded', data);
return $.when();
},
_is_quick_create_enabled: function() {