[FIX] web: various bugs with pivot view and no data
The pivot view had various small issues causing a crash when transitioning from and to a 'no data' state.
This commit is contained in:
committed by
Aaron Bohy
parent
21324ded09
commit
7056ec1ac6
@@ -171,11 +171,13 @@ var PivotController = AbstractController.extend({
|
||||
*/
|
||||
_update: function (state) {
|
||||
this._updateButtons();
|
||||
var hasNoContent = !state.measures.length || !state.has_data;
|
||||
var hasNoContent = !state.has_data || !state.measures.length;
|
||||
|
||||
if (hasNoContent) {
|
||||
this.renderer.$el.detach();
|
||||
this.$el.append(QWeb.render('PivotView.nodata'));
|
||||
if (!this.$('.oe_view_nocontent').length) {
|
||||
this.renderer.$el.detach();
|
||||
this.$el.append(QWeb.render('PivotView.nodata'));
|
||||
}
|
||||
} else {
|
||||
if (!document.contains(this.renderer.el)) {
|
||||
this.$('div.oe_view_nocontent').remove();
|
||||
|
||||
@@ -186,11 +186,14 @@ var PivotModel = AbstractModel.extend({
|
||||
*/
|
||||
get: function (options) {
|
||||
var isRaw = options && options.raw;
|
||||
if (!this.data.has_data) {
|
||||
return {has_data: false};
|
||||
}
|
||||
return {
|
||||
colGroupBys: this.data.main_col.groupbys,
|
||||
fields: this.fields,
|
||||
has_data: this.data.has_data,
|
||||
headers: !isRaw && this._computeHeaders(),
|
||||
has_data: true,
|
||||
mainColWidth: this.data.main_col.width,
|
||||
measures: this.data.measures,
|
||||
rows: !isRaw && this._computeRows(),
|
||||
@@ -243,8 +246,6 @@ var PivotModel = AbstractModel.extend({
|
||||
*/
|
||||
reload: function (handle, params) {
|
||||
var self = this;
|
||||
var old_row_root = this.data.main_row.root;
|
||||
var old_col_root = this.data.main_col.root;
|
||||
if ('domain' in params) {
|
||||
this.data.domain = params.domain;
|
||||
} else {
|
||||
@@ -253,7 +254,12 @@ var PivotModel = AbstractModel.extend({
|
||||
if ('groupBy' in params) {
|
||||
this.data.groupedBy = params.groupBy;
|
||||
}
|
||||
if (!this.data.has_data) {
|
||||
return this._loadData(params);
|
||||
}
|
||||
|
||||
var old_row_root = this.data.main_row.root;
|
||||
var old_col_root = this.data.main_col.root;
|
||||
return this._loadData(params).then(function () {
|
||||
var new_groupby_length;
|
||||
if (!('groupBy' in params)) {
|
||||
|
||||
@@ -18,6 +18,9 @@ var PivotRenderer = AbstractRenderer.extend({
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_render: function () {
|
||||
if (!this.state.has_data) {
|
||||
return this._super.apply(this, arguments);
|
||||
}
|
||||
var $fragment = $(document.createDocumentFragment());
|
||||
var $table = $('<table>').appendTo($fragment);
|
||||
var $thead = $('<thead>').appendTo($table);
|
||||
|
||||
@@ -389,6 +389,53 @@ QUnit.module('Views', {
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('no content helper when no data, part 2', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
this.data.partner.records = [];
|
||||
|
||||
var pivot = createView({
|
||||
View: PivotView,
|
||||
model: "partner",
|
||||
data: this.data,
|
||||
arch: '<pivot string="Partners"></pivot>',
|
||||
});
|
||||
|
||||
assert.strictEqual(pivot.$('.oe_view_nocontent').length, 1,
|
||||
"should have a no_content_helper");
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('no content helper when no data, part 3', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var pivot = createView({
|
||||
View: PivotView,
|
||||
model: "partner",
|
||||
data: this.data,
|
||||
arch: '<pivot string="Partners"></pivot>',
|
||||
viewOptions: {
|
||||
domain: [['foo', '=', 12345]]
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(pivot.$('.oe_view_nocontent').length, 1,
|
||||
"should have a no_content_helper");
|
||||
pivot.update({domain: [['foo', '=', 12345]]});
|
||||
assert.strictEqual(pivot.$('.oe_view_nocontent').length, 1,
|
||||
"should still have a no_content_helper");
|
||||
pivot.update({domain: []});
|
||||
assert.strictEqual(pivot.$('.oe_view_nocontent').length, 0,
|
||||
"should not have a no_content_helper");
|
||||
|
||||
// tries to open a field selection menu, to make sure it was not
|
||||
// removed from the dom.
|
||||
pivot.$('.o_pivot_header_cell_closed').first().click();
|
||||
assert.strictEqual(pivot.$('ul.o_pivot_field_menu').length, 1,
|
||||
"the field selector menu exists");
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('tries to restore previous state after domain change', function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user