[FIX] fixes many issues with the various views

the views don't always return a proper promise, or were
somewhat fragile and broke with the changes in the view
manager.
This commit is contained in:
Géry Debongnie
2014-10-21 09:33:49 +02:00
parent 582ccb5ab9
commit ffb8bf31af
6 changed files with 46 additions and 29 deletions
+1
View File
@@ -1278,6 +1278,7 @@ openerp.mail = function (session) {
start: function () {
this._super.apply(this, arguments);
this.bind_events();
return $.when();
},
/* instantiate the compose message object and insert this on the DOM.
+5 -12
View File
@@ -4143,14 +4143,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
/**
* Returns the current active view if any.
*/
if (this.viewmanager && this.viewmanager.views && this.viewmanager.active_view &&
this.viewmanager.views[this.viewmanager.active_view] &&
this.viewmanager.views[this.viewmanager.active_view].controller) {
return {
type: this.viewmanager.active_view,
controller: this.viewmanager.views[this.viewmanager.active_view].controller
};
}
return (this.viewmanager && this.viewmanager.active_view);
},
set_value: function(value_) {
value_ = value_ || [];
@@ -4242,12 +4235,12 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
save_any_view: function() {
var view = this.get_active_view();
if (view) {
if (this.viewmanager.active_view === "form") {
if (this.viewmanager.active_view.type === "form") {
if (view.controller.is_initialized.state() !== 'resolved') {
return $.when(false);
}
return $.when(view.controller.save());
} else if (this.viewmanager.active_view === "list") {
} else if (this.viewmanager.active_view.type === "list") {
return $.when(view.controller.ensure_saved());
}
}
@@ -4258,7 +4251,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
if (!view){
return true;
}
switch (this.viewmanager.active_view) {
switch (this.viewmanager.active_view.type) {
case 'form':
return _(view.controller.fields).chain()
.invoke('is_valid')
@@ -4275,7 +4268,7 @@ instance.web.form.One2ManyViewManager = instance.web.ViewManager.extend({
template: 'One2Many.viewmanager',
init: function(parent, dataset, views, flags) {
this._super(parent, dataset, views, _.extend({}, flags, {$sidebar: false}));
this.registry = this.registry.extend({
this.registry = instance.web.views.extend({
list: 'instance.web.form.One2ManyListView',
form: 'instance.web.form.One2ManyFormView',
kanban: 'instance.web.form.One2ManyKanbanView',
@@ -88,6 +88,8 @@ openerp.web_calendar = function(instance) {
this.range_start = null;
this.range_stop = null;
this.selected_filters = [];
this.shown = $.Deferred();
},
set_default_options: function(options) {
@@ -229,6 +231,7 @@ openerp.web_calendar = function(instance) {
this.info_fields.push(fv.arch.children[fld].attrs.name);
}
self.shown.done(this._do_show_init.bind(this));
var edit_check = new instance.web.Model(this.dataset.model)
.call("check_access_rights", ["write", false])
.then(function (write_right) {
@@ -238,15 +241,18 @@ openerp.web_calendar = function(instance) {
.call("check_access_rights", ["create", false])
.then(function (create_right) {
self.create_right = create_right;
self.init_calendar().then(function() {
$(window).trigger('resize');
self.trigger('calendar_view_loaded', fv);
self.ready.resolve();
});
self.ready.resolve();
self.trigger('calendar_view_loaded', fv);
});
return $.when(edit_check, init);
},
_do_show_init: function () {
var self = this;
this.init_calendar().then(function() {
$(window).trigger('resize');
self.trigger('calendar_view_loaded', self.fields_view);
});
},
get_fc_init_options: function () {
//Documentation here : http://arshaw.com/fullcalendar/docs/
var self = this;
@@ -647,7 +653,13 @@ openerp.web_calendar = function(instance) {
return data;
},
do_search: function(domain, context, _group_by) {
do_search: function (domain, context, _group_by) {
var self = this;
this.shown.done(function () {
self._do_search(domain, context, _group_by);
});
},
_do_search: function(domain, context, _group_by) {
var self = this;
if (! self.all_filters) {
self.all_filters = {}
@@ -854,11 +866,12 @@ openerp.web_calendar = function(instance) {
return false;
},
do_show: function() {
do_show: function() {
if (this.$buttons) {
this.$buttons.show();
}
this.do_push_state({});
this.shown.resolve();
return this._super();
},
do_hide: function () {
@@ -31,6 +31,8 @@ instance.web_graph.GraphView = instance.web.View.extend({
get_domain: function () {},
get_groupby: function () {},
};
this.view_loaded = $.Deferred();
},
view_loading: function (fields_view_get) {
@@ -72,9 +74,17 @@ instance.web_graph.GraphView = instance.web.View.extend({
if (self.widget_config.measures.length === 0) {
self.widget_config.measures.push('__count');
}
this.view_loaded.resolve();
},
do_search: function (domain, context, group_by) {
var self = this;
this.view_loaded.done(function () {
self._do_search(domain, context, group_by);
});
},
_do_search: function (domain, context, group_by) {
if (this.ignore_do_search) {
this.ignore_do_search = false;
return;
+7 -7
View File
@@ -252,12 +252,12 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
self.fields_keys = _.unique(self.fields_keys.concat(grouping_fields));
}
var grouping = new instance.web.Model(self.dataset.model, context, domain).query(self.fields_keys).group_by(grouping_fields);
return self.alive($.when(grouping)).done(function(groups) {
return self.alive($.when(grouping)).then(function(groups) {
self.remove_no_result();
if (groups) {
self.do_process_groups(groups);
return self.do_process_groups(groups);
} else {
self.do_process_dataset();
return self.do_process_dataset();
}
});
});
@@ -266,12 +266,12 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
var self = this;
this.$el.find('table:first').show();
this.$el.removeClass('oe_kanban_ungrouped').addClass('oe_kanban_grouped');
this.add_group_mutex.exec(function() {
return this.add_group_mutex.exec(function() {
self.do_clear_groups();
self.dataset.ids = [];
if (!groups.length) {
self.no_result();
return false;
return $.when();
}
self.nb_records = 0;
var remaining = groups.length - 1,
@@ -306,8 +306,8 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
var self = this;
this.$el.find('table:first').show();
this.$el.removeClass('oe_kanban_grouped').addClass('oe_kanban_ungrouped');
var def = $.Deferred();
this.add_group_mutex.exec(function() {
var def = $.Deferred();
self.do_clear_groups();
self.dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit }).done(function(records) {
var kgroup = new instance.web_kanban.KanbanGroup(self, records, null, self.dataset);
@@ -326,8 +326,8 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
}).done(null, function() {
def.reject();
});
return def;
});
return def;
},
do_reload: function() {
this.do_search(this.search_domain, this.search_context, this.search_group_by);
@@ -15,13 +15,13 @@
<div t-name="KanbanView.buttons" class="oe_kanban_buttons">
<t t-if="widget.options.action_buttons !== false">
<t t-if="widget.is_action_enabled('create')">
<button type="button" class="oe_kanban_button_new oe_highlight">
<button type="button" class="oe_kanban_button_new btn btn-primary">
<t t-esc="widget.options.create_text || _t('Create')"/>
</button>
<span t-if="widget.is_action_enabled('group_create')" class="oe_alternative" style="display: none">
<span class="oe_fade">or</span>
<div class="oe_bounce_container">
<a href="#" class="oe_bold oe_kanban_add_column">Add a new column</a>
<a href="#" class="oe_kanban_add_column text-info">Add a new column</a>
</div>
</span>
</t>