summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-03-31 23:28:58 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit7056ec1ac6e6c23231d9044bb60efc2a0bdb7ae2 (patch)
treea7aa305521e8ce8eb080b66fe826cd600d83b82f
parent21324ded09883d08ec951b0e3cc80ff5ed270aed (diff)
[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.
-rw-r--r--addons/web/static/src/js/views/pivot/pivot_controller.js8
-rw-r--r--addons/web/static/src/js/views/pivot/pivot_model.js12
-rw-r--r--addons/web/static/src/js/views/pivot/pivot_renderer.js3
-rw-r--r--addons/web/static/test/views/pivot_tests.js47
4 files changed, 64 insertions, 6 deletions
diff --git a/addons/web/static/src/js/views/pivot/pivot_controller.js b/addons/web/static/src/js/views/pivot/pivot_controller.js
index 2aa4cd93797..f53e0f9db7c 100644
--- a/addons/web/static/src/js/views/pivot/pivot_controller.js
+++ b/addons/web/static/src/js/views/pivot/pivot_controller.js
@@ -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();
diff --git a/addons/web/static/src/js/views/pivot/pivot_model.js b/addons/web/static/src/js/views/pivot/pivot_model.js
index d2bf632053c..d5b226b27da 100644
--- a/addons/web/static/src/js/views/pivot/pivot_model.js
+++ b/addons/web/static/src/js/views/pivot/pivot_model.js
@@ -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)) {
diff --git a/addons/web/static/src/js/views/pivot/pivot_renderer.js b/addons/web/static/src/js/views/pivot/pivot_renderer.js
index c6ab6b3125a..c38f8b6b768 100644
--- a/addons/web/static/src/js/views/pivot/pivot_renderer.js
+++ b/addons/web/static/src/js/views/pivot/pivot_renderer.js
@@ -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);
diff --git a/addons/web/static/test/views/pivot_tests.js b/addons/web/static/test/views/pivot_tests.js
index def0896abce..fc4c4fc4874 100644
--- a/addons/web/static/test/views/pivot_tests.js
+++ b/addons/web/static/test/views/pivot_tests.js
@@ -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);