[IMP] web_widget_dropdown_dynamic: black, isort, prettier

This commit is contained in:
Alexey Pelykh
2020-04-12 08:55:00 +02:00
committed by Thanakrit Pintana
parent 5f03f1b541
commit b31c4382a0
5 changed files with 165 additions and 150 deletions

View File

@@ -1,11 +1,11 @@
/*
/*
* 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.basic_model', function (require) {
odoo.define("web_widget_dropdown_dynamic.basic_model", function(require) {
"use strict";
var BasicModel = require('web.BasicModel');
var BasicModel = require("web.BasicModel");
BasicModel.include({
/**
@@ -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) {
@@ -29,7 +29,7 @@ odoo.define('web_widget_dropdown_dynamic.basic_model', function (require) {
var context = record.getContext({fieldName: fieldName});
// avoid rpc if not necessary
// Avoid rpc if not necessary
var hasChanged = this._saveSpecialDataCache(record, fieldName, {
context: context,
});

View File

@@ -1,47 +1,47 @@
/*
/*
* 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');
var AbstractField = require('web.AbstractField');
var field_registry = require('web.field_registry');
var core = require("web.core");
var AbstractField = require("web.AbstractField");
var field_registry = require("web.field_registry");
var _lt = core._lt;
var FieldDynamicDropdown = AbstractField.extend({
description: _lt('Dynamic Dropdown'),
template: 'FieldSelection',
specialData: '_fetchDynamicDropdownValues',
supportedFieldTypes: ['selection', 'char', 'integer'],
description: _lt("Dynamic Dropdown"),
template: "FieldSelection",
specialData: "_fetchDynamicDropdownValues",
supportedFieldTypes: ["selection", "char", "integer"],
events: _.extend({}, AbstractField.prototype.events, {
'change': '_onChange',
change: "_onChange",
}),
/**
* @override
*/
init: function () {
init: function() {
this._super.apply(this, arguments);
this._setValues();
},
//--------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
// --------------------------------------------------------------------------
/**
* @override
* @returns {jQuery}
*/
getFocusableElement: function () {
return this.$el.is('select') ? this.$el : $();
getFocusableElement: function() {
return this.$el.is("select") ? this.$el : $();
},
/**
* @override
*/
isSet: function () {
isSet: function() {
return this.value !== false;
},
/**
@@ -50,25 +50,30 @@ odoo.define('web_widget_dropdown_dynamic.field_dynamic_dropdown', function (requ
*
* @override
*/
updateModifiersValue: function () {
updateModifiersValue: function() {
this._super.apply(this, arguments);
if (!this.attrs.modifiersValue.invisible && this.mode !== 'readonly') {
if (!this.attrs.modifiersValue.invisible && this.mode !== "readonly") {
this._setValues();
this._renderEdit();
}
},
//--------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
// --------------------------------------------------------------------------
/**
* @override
* @private
*/
_formatValue: function (value) {
var options = _.extend({}, this.nodeOptions, { data: this.recordData }, this.formatOptions);
var formattedValue = _.find(this.values, function (option) {
_formatValue: function(value) {
var options = _.extend(
{},
this.nodeOptions,
{data: this.recordData},
this.formatOptions
);
var formattedValue = _.find(this.values, function(option) {
return option[0] === value;
});
if (!formattedValue) {
@@ -84,13 +89,15 @@ odoo.define('web_widget_dropdown_dynamic.field_dynamic_dropdown', function (requ
* @override
* @private
*/
_renderEdit: function () {
_renderEdit: function() {
this.$el.empty();
for (var i = 0 ; i < this.values.length ; i++) {
this.$el.append($('<option/>', {
value: JSON.stringify(this.values[i][0]),
text: this.values[i][1]
}));
for (var i = 0; i < this.values.length; i++) {
this.$el.append(
$("<option/>", {
value: JSON.stringify(this.values[i][0]),
text: this.values[i][1],
})
);
}
this.$el.val(JSON.stringify(this.value));
},
@@ -98,13 +105,13 @@ odoo.define('web_widget_dropdown_dynamic.field_dynamic_dropdown', function (requ
* @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();
},
@@ -113,28 +120,30 @@ odoo.define('web_widget_dropdown_dynamic.field_dynamic_dropdown', function (requ
*
* @private
*/
_setValues: function () {
this.values = _.reject(this.record.specialData[this.name], function (v) {
return v[0] === false && v[1] === '';
_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) {
this.values = [[false, this.attrs.placeholder || '']].concat(this.values);
this.values = [[false, this.attrs.placeholder || ""]].concat(
this.values
);
}
},
//--------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
// --------------------------------------------------------------------------
/**
* @private
*/
_onChange: function () {
_onChange: function() {
var value = JSON.parse(this.$el.val());
this._setValue(value.toString());
},
});
field_registry.add('dynamic_dropdown', FieldDynamicDropdown);
field_registry.add("dynamic_dropdown", FieldDynamicDropdown);
return FieldDynamicDropdown;
});