mirror of https://github.com/OCA/web.git
[IMP] web_widget_dropdown_dynamic: black, isort, prettier
parent
ec5084302a
commit
db803eb8c8
|
@ -8,7 +8,7 @@
|
|||
"version": "13.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "CorporateHub, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/web/",
|
||||
"website": "https://github.com/OCA/web",
|
||||
"depends": ["web"],
|
||||
"data": ["templates/assets.xml"],
|
||||
"installable": True,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
*/
|
||||
odoo.define("web_widget_dropdown_dynamic.basic_model", function(require) {
|
||||
odoo.define("web_widget_dropdown_dynamic.basic_model", function (require) {
|
||||
"use strict";
|
||||
|
||||
var BasicModel = require("web.BasicModel");
|
||||
|
@ -20,7 +20,7 @@ odoo.define("web_widget_dropdown_dynamic.basic_model", function(require) {
|
|||
* (for the given parameters), no RPC is done and the promise
|
||||
* is resolved with the undefined value.
|
||||
*/
|
||||
_fetchDynamicDropdownValues: function(record, fieldName, fieldInfo) {
|
||||
_fetchDynamicDropdownValues: function (record, fieldName, fieldInfo) {
|
||||
var model = fieldInfo.options.model || record.model;
|
||||
var method = fieldInfo.values || fieldInfo.options.values;
|
||||
if (!method) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
*/
|
||||
odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(require) {
|
||||
odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require("web.core");
|
||||
|
@ -22,7 +22,7 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
|||
/**
|
||||
* @override
|
||||
*/
|
||||
init: function() {
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this._setValues();
|
||||
},
|
||||
|
@ -35,13 +35,13 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
|||
* @override
|
||||
* @returns {jQuery}
|
||||
*/
|
||||
getFocusableElement: function() {
|
||||
getFocusableElement: function () {
|
||||
return this.$el.is("select") ? this.$el : $();
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
isSet: function() {
|
||||
isSet: function () {
|
||||
return this.value !== false;
|
||||
},
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
|||
*
|
||||
* @override
|
||||
*/
|
||||
updateModifiersValue: function() {
|
||||
updateModifiersValue: function () {
|
||||
this._super.apply(this, arguments);
|
||||
if (!this.attrs.modifiersValue.invisible && this.mode !== "readonly") {
|
||||
this._setValues();
|
||||
|
@ -66,14 +66,14 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
|||
* @override
|
||||
* @private
|
||||
*/
|
||||
_formatValue: function(value) {
|
||||
_formatValue: function (value) {
|
||||
var options = _.extend(
|
||||
{},
|
||||
this.nodeOptions,
|
||||
{data: this.recordData},
|
||||
this.formatOptions
|
||||
);
|
||||
var formattedValue = _.find(this.values, function(option) {
|
||||
var formattedValue = _.find(this.values, function (option) {
|
||||
return option[0] === value;
|
||||
});
|
||||
if (!formattedValue) {
|
||||
|
@ -89,7 +89,7 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
|||
* @override
|
||||
* @private
|
||||
*/
|
||||
_renderEdit: function() {
|
||||
_renderEdit: function () {
|
||||
this.$el.empty();
|
||||
for (var i = 0; i < this.values.length; i++) {
|
||||
this.$el.append(
|
||||
|
@ -105,13 +105,13 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
|||
* @override
|
||||
* @private
|
||||
*/
|
||||
_renderReadonly: function() {
|
||||
_renderReadonly: function () {
|
||||
this.$el.empty().text(this._formatValue(this.value));
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_reset: function() {
|
||||
_reset: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this._setValues();
|
||||
},
|
||||
|
@ -120,8 +120,8 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
|||
*
|
||||
* @private
|
||||
*/
|
||||
_setValues: function() {
|
||||
this.values = _.reject(this.record.specialData[this.name], function(v) {
|
||||
_setValues: function () {
|
||||
this.values = _.reject(this.record.specialData[this.name], function (v) {
|
||||
return v[0] === false && v[1] === "";
|
||||
});
|
||||
if (!this.attrs.modifiersValue || !this.attrs.modifiersValue.required) {
|
||||
|
@ -138,7 +138,7 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
|||
/**
|
||||
* @private
|
||||
*/
|
||||
_onChange: function() {
|
||||
_onChange: function () {
|
||||
var value = JSON.parse(this.$el.val());
|
||||
this._setValue(value.toString());
|
||||
},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", function(
|
||||
odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", function (
|
||||
require
|
||||
) {
|
||||
"use strict";
|
||||
|
@ -8,8 +8,8 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
|||
var FormView = require("web.FormView");
|
||||
var testUtils = require("web.test_utils");
|
||||
|
||||
QUnit.module("web_widget_dropdown_dynamic", {}, function() {
|
||||
QUnit.test("values are fetched w/o context (char)", async function(assert) {
|
||||
QUnit.module("web_widget_dropdown_dynamic", {}, function () {
|
||||
QUnit.test("values are fetched w/o context (char)", async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var form = await testUtils.createView({
|
||||
|
@ -27,7 +27,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
|||
"<form>" +
|
||||
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
||||
"</form>",
|
||||
mockRPC: function(route, args) {
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "_get_test_field_values") {
|
||||
return Promise.resolve([["value", "Title"]]);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
|||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test("values are fetched w/o context (integer)", async function(assert) {
|
||||
QUnit.test("values are fetched w/o context (integer)", async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var form = await testUtils.createView({
|
||||
|
@ -59,7 +59,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
|||
"<form>" +
|
||||
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
||||
"</form>",
|
||||
mockRPC: function(route, args) {
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "_get_test_field_values") {
|
||||
return Promise.resolve([[0, "Title"]]);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
|||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test("values are fetched w/o context (selection)", async function(
|
||||
QUnit.test("values are fetched w/o context (selection)", async function (
|
||||
assert
|
||||
) {
|
||||
assert.expect(2);
|
||||
|
@ -93,7 +93,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
|||
"<form>" +
|
||||
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
||||
"</form>",
|
||||
mockRPC: function(route, args) {
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "_get_test_field_values") {
|
||||
return Promise.resolve([["value", "Title"]]);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
|||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test("values are fetched with changing context", async function(assert) {
|
||||
QUnit.test("values are fetched with changing context", async function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
var form = await testUtils.createView({
|
||||
|
@ -127,7 +127,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
|||
'<field name="other_field" />' +
|
||||
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values" context="{\'step\': other_field}"/>' +
|
||||
"</form>",
|
||||
mockRPC: function(route, args) {
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "_get_test_field_values") {
|
||||
if (args.kwargs.context.step === "step-1") {
|
||||
return Promise.resolve([["value", "Title"]]);
|
||||
|
|
Loading…
Reference in New Issue