[FIX] web_kanban_gauge: correctly render gauge widget
Before this rev., nothing was rendered when the 'gauge' widget was set on a field (e.g. Sales > Leads Management > Team Assignation), because the API of the fields in web evolved a lot recently, and the rendering should now be done in a private function called '_render', not 'render'.
This commit is contained in:
@@ -6,7 +6,7 @@ var field_registry = require('web.field_registry');
|
||||
var utils = require('web.utils');
|
||||
|
||||
/**
|
||||
* Kanban widgets: GaugeWidget
|
||||
* Field widget: GaugeWidget
|
||||
* options
|
||||
* - max_value: maximum value of the gauge [default: 100]
|
||||
* - max_field: get the max_value from the field that must be present in the
|
||||
@@ -26,7 +26,15 @@ var utils = require('web.utils');
|
||||
var GaugeWidget = AbstractField.extend({
|
||||
className: "oe_gauge",
|
||||
|
||||
render: function() {
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_render: function () {
|
||||
// parameters
|
||||
var max_value = this.nodeOptions.max_value || 100;
|
||||
if (this.nodeOptions.max_field) {
|
||||
@@ -124,4 +132,6 @@ var GaugeWidget = AbstractField.extend({
|
||||
|
||||
field_registry.add("gauge", GaugeWidget);
|
||||
|
||||
return GaugeWidget;
|
||||
|
||||
});
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
odoo.define('web_kanban_gauge.gauge_tests', function (require) {
|
||||
"use strict";
|
||||
|
||||
var KanbanView = require('web.KanbanView');
|
||||
var testUtils = require('web.test_utils');
|
||||
|
||||
var createView = testUtils.createView;
|
||||
|
||||
QUnit.module('fields', {}, function () {
|
||||
|
||||
QUnit.module('basic_fields', {
|
||||
beforeEach: function () {
|
||||
this.data = {
|
||||
partner: {
|
||||
fields: {
|
||||
int_field: {string: "int_field", type: "integer", sortable: true},
|
||||
},
|
||||
records: [
|
||||
{id: 1, int_field: 10},
|
||||
{id: 2, int_field: 4},
|
||||
]
|
||||
},
|
||||
};
|
||||
}
|
||||
}, function () {
|
||||
|
||||
QUnit.module('gauge widget');
|
||||
|
||||
QUnit.test('basic rendering', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var kanban = createView({
|
||||
View: KanbanView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<kanban><templates><t t-name="kanban-box">' +
|
||||
'<div><field name="int_field" widget="gauge"/></div>' +
|
||||
'</t></templates></kanban>',
|
||||
});
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_record:first .oe_gauge svg').length, 1,
|
||||
"should render the gauge widget");
|
||||
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -5,4 +5,10 @@
|
||||
<script type="text/javascript" src="/web_kanban_gauge/static/src/js/kanban_gauge.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="qunit_suite" name="gauge_tests" inherit_id="web.qunit_suite">
|
||||
<xpath expr="//t[@t-set='head']" position="inside">
|
||||
<script type="text/javascript" src="/web_kanban_gauge/static/tests/gauge_tests.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user