From 9bd63dd24ae7c8f8eb9eefd0078b9e19b55cf0cb Mon Sep 17 00:00:00 2001 From: KKamaa Date: Mon, 28 Mar 2022 03:43:11 +0300 Subject: [PATCH] [FIX] isort, prettier, black: JS lint in all affect modules --- .../src/tests/support_branding_tests.js | 66 +++++++++++-------- .../static/src/js/relational.js | 1 - .../static/src/js/calendar.js | 4 ++ .../static/src/js/calendar_model.js | 2 +- .../static/src/js/web_drop_target.js | 9 ++- web_m2x_options/static/src/js/form.js | 12 ++-- web_pwa_oca/static/src/js/pwa_manager.js | 3 +- .../static/src/js/kanban_renderer_mobile.js | 31 +++++---- .../static/src/js/web_responsive.js | 1 - .../src/js/control_panel_model_extension.js | 32 ++++----- .../static/src/js/search_bar.js | 9 ++- .../src/js/switch_context_warning_worker.js | 14 ++-- .../static/src/js/numeric_step.js | 10 +-- .../static/src/js/widget_x2many_2d_matrix.js | 3 + 14 files changed, 116 insertions(+), 81 deletions(-) diff --git a/support_branding/static/src/tests/support_branding_tests.js b/support_branding/static/src/tests/support_branding_tests.js index e20fbcd43..bc97daf26 100644 --- a/support_branding/static/src/tests/support_branding_tests.js +++ b/support_branding/static/src/tests/support_branding_tests.js @@ -1,11 +1,13 @@ -odoo.define('support_branding.crash_manager_tests', function (require) { +odoo.define("support_branding.crash_manager_tests", function (require) { "use strict"; - const CrashManager = require('web.CrashManager').CrashManager; - const testUtils = require('web.test_utils'); + /* global QUnit*/ + + const CrashManager = require("web.CrashManager").CrashManager; + const testUtils = require("web.test_utils"); const createActionManager = testUtils.createActionManager; - QUnit.module('support_branding', {}, function() { + QUnit.module("support_branding", {}, function () { QUnit.test("Error Dialog is created", async function (assert) { // No of assertion expected. assert.expect(5); @@ -14,53 +16,63 @@ odoo.define('support_branding.crash_manager_tests', function (require) { var actionManager = await createActionManager({ services: { crash_manager: CrashManager, - } + }, }); // Check if action with crash manager service was created. - assert.notOk(_.isEmpty(actionManager), "Action manager with " + - "crash manager service should be created and not empty"); + assert.notOk( + _.isEmpty(actionManager), + "Action manager with " + + "crash manager service should be created and not empty" + ); // Test custom error - let error = { - type: 'Support Branding Odoo Client Error', - message: 'Message', + const error = { + type: "Support Branding Odoo Client Error", + message: "Message", data: { - debug: 'Traceback', + debug: "Traceback", }, }; // NB: This will use the saved res.config settings of support // branding containing the support mail. It is fetched in crash // manager init function as saved in res.config settings. // attached is a default data xml with sample data. - actionManager.call('crash_manager', 'show_error', error); + actionManager.call("crash_manager", "show_error", error); await testUtils.nextTick(); - var $mail_dialog = 'form.support-branding-submit-form'; + var $mail_dialog = "form.support-branding-submit-form"; // Confirm if we have a form and its required elements. - assert.containsOnce($, $mail_dialog, "Error dialog should be " + - "opened and showing mail section on footer"); - assert.containsOnce($, '.support-desc', 'We should have a ' + - 'textarea to add our issues'); - assert.containsOnce($, 'button.support-btn', 'We should have a ' + - 'send mail button to send support mail'); + assert.containsOnce( + $, + $mail_dialog, + "Error dialog should be opened and showing mail section on footer" + ); + assert.containsOnce( + $, + ".support-desc", + "We should have a textarea to add our issues" + ); + assert.containsOnce( + $, + "button.support-btn", + "We should have a send mail button to send support mail" + ); // Add a test text mail. - $(".support-desc").val("Send this as a test mail to " + - "configured support mail"); + $(".support-desc").val( + "Send this as a test mail to configured support mail" + ); // Try to send mail, by default a popup will be triggered // defaulting to form call of 'mailto'. - await testUtils.dom.click($('button.support-btn'), - {allowInvisible: true}); + await testUtils.dom.click($("button.support-btn"), {allowInvisible: true}); // Close error dialog - await testUtils.dom.click($('button.close'), - {allowInvisible: true}); + await testUtils.dom.click($("button.close"), {allowInvisible: true}); // Confirm dialog was closed - assert.containsNone($, $mail_dialog, - "Error Dialog should be closed"); + assert.containsNone($, $mail_dialog, "Error Dialog should be closed"); actionManager.destroy(); }); diff --git a/web_advanced_search/static/src/js/relational.js b/web_advanced_search/static/src/js/relational.js index 18c276f7b..934aa9172 100644 --- a/web_advanced_search/static/src/js/relational.js +++ b/web_advanced_search/static/src/js/relational.js @@ -8,7 +8,6 @@ odoo.define("web_advanced_search.RelationalOwl", function (require) { const FieldMany2One = relationalFields.FieldMany2One; const FieldManagerMixin = require("web.FieldManagerMixin"); const {useListener} = require("web.custom_hooks"); - /* global owl */ const {Component} = owl; const {xml} = owl.tags; diff --git a/web_calendar_color_field/static/src/js/calendar.js b/web_calendar_color_field/static/src/js/calendar.js index b96d01031..4677ced4d 100644 --- a/web_calendar_color_field/static/src/js/calendar.js +++ b/web_calendar_color_field/static/src/js/calendar.js @@ -15,6 +15,10 @@ odoo.define("web_calendar_color_field.CalendarModel", function (require) { * * If the field is also added to filters, and a color field is defined, * we use that color field as colorIndex. + * + * @param {Object} element: '' + * @param {Array} events: '' + * @returns {Promise} */ _loadColors: function (element, events) { var self = this; diff --git a/web_calendar_slot_duration/static/src/js/calendar_model.js b/web_calendar_slot_duration/static/src/js/calendar_model.js index e4fd434a3..04358b6ba 100644 --- a/web_calendar_slot_duration/static/src/js/calendar_model.js +++ b/web_calendar_slot_duration/static/src/js/calendar_model.js @@ -11,7 +11,7 @@ odoo.define("web_calendar_slot_duration.CalendarModel", function (require) { * @override */ _getFullCalendarOptions: function () { - var result = this._super.call(this, arguments); + var result = this._super.apply(this, arguments); result.slotDuration = this.data.context.calendar_slot_duration || result.slotDuration || diff --git a/web_drop_target/static/src/js/web_drop_target.js b/web_drop_target/static/src/js/web_drop_target.js index b00d12cc4..2b5df2075 100644 --- a/web_drop_target/static/src/js/web_drop_target.js +++ b/web_drop_target/static/src/js/web_drop_target.js @@ -1,4 +1,4 @@ -/* global Uint8Array, base64js */ +/* global base64js */ // Copyright 2018 Therp BV // Copyright 2021 Tecnativa - Alexandre D. Díaz // License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). @@ -24,7 +24,8 @@ odoo.define("web_drop_target", function (require) { */ start: function () { const $body = $("body"); - this._dropZoneNS = _.uniqueId("o_dz_"); // For event namespace used when multiple chat window is open + // For event namespace used when multiple chat window is open + this._dropZoneNS = _.uniqueId("o_dz_"); $body.on( "dragleave." + this._dropZoneNS, this._onBodyFileDragLeave.bind(this) @@ -159,7 +160,7 @@ odoo.define("web_drop_target", function (require) { if ( _.isEmpty(this._get_drop_items(ev)) && this._checkDragOver() && - (controller == undefined || controller.jsID === this.controllerID) + (controller === undefined || controller.jsID === this.controllerID) ) { const drop_zone_offset = this.$drop_zone.offset(); const overlay_css = { @@ -212,6 +213,7 @@ odoo.define("web_drop_target", function (require) { * * @private * @param {MouseEvent} ev + * @returns {Object} drop items */ _get_drop_items: function (ev) { let drop_items = []; @@ -250,6 +252,7 @@ odoo.define("web_drop_target", function (require) { * @param {String} res_model * @param {Number} res_id * @param {Object} extra_data + * @returns {Void} */ _create_attachment: function (file, reader, res_model, res_id, extra_data) { // Helper to upload an attachment and update the sidebar diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index 85facf0fc..b18dc89c3 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -134,7 +134,7 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) { if (blacklisted_ids.length > 0) { domain.push(["id", "not in", blacklisted_ids]); } - + /* eslint-disable complexity */ self._rpc({ model: self.field.relation, method: "name_search", @@ -201,16 +201,15 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) { // 3- if not set locally, check if it's set globally via ir.config_parameter // 4- if set globally, apply its value // 5- if not set globally either, check if returned values are more than node's limit + var search_more = values.length > self.limit; if (!_.isUndefined(self.nodeOptions.search_more)) { - var search_more = is_option_set(self.nodeOptions.search_more); + search_more = is_option_set(self.nodeOptions.search_more); } else if ( !_.isUndefined(ir_options["web_m2x_options.search_more"]) ) { - var search_more = is_option_set( + search_more = is_option_set( ir_options["web_m2x_options.search_more"] ); - } else { - var search_more = values.length > self.limit; } if (search_more) { @@ -349,6 +348,7 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) { resolve(values); } }); + /* eslint-enable complexity */ }); this.orderer.add(def); @@ -483,7 +483,7 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) { this._super(attrs); var limit = ir_options["web_m2x_options.field_limit_entries"]; if (!_.isUndefined(limit)) { - attrs.limit = parseInt(limit); + attrs.limit = parseInt(limit, 10); } }, }); diff --git a/web_pwa_oca/static/src/js/pwa_manager.js b/web_pwa_oca/static/src/js/pwa_manager.js index ffabc14cf..c4bd9de4b 100644 --- a/web_pwa_oca/static/src/js/pwa_manager.js +++ b/web_pwa_oca/static/src/js/pwa_manager.js @@ -21,7 +21,8 @@ odoo.define("web_pwa_oca.PWAManager", function (require) { "Service workers are not supported! Maybe you are not using HTTPS or you work in private mode." ) ); - } else { + } + if ("serviceWorker" in navigator) { this._service_worker = navigator.serviceWorker; this.registerServiceWorker("/service-worker.js"); } diff --git a/web_responsive/static/src/js/kanban_renderer_mobile.js b/web_responsive/static/src/js/kanban_renderer_mobile.js index c5f43649e..4810d8675 100644 --- a/web_responsive/static/src/js/kanban_renderer_mobile.js +++ b/web_responsive/static/src/js/kanban_renderer_mobile.js @@ -61,13 +61,15 @@ "click .o_kanban_mobile_tab": "_onMobileTabClicked", "click .o_kanban_mobile_add_column": "_onMobileQuickCreateClicked", }), - ANIMATE: true, // Allows to disable animations for the tests + // Allows to disable animations for the tests + ANIMATE: true, /** * @override */ init: function () { this._super.apply(this, arguments); - this.activeColumnIndex = 0; // Index of the currently displayed column + // Index of the currently displayed column + this.activeColumnIndex = 0; this._scrollPosition = null; }, /** @@ -377,7 +379,8 @@ db_id: column.db_id, onSuccess: () => self._layoutUpdate(animate), }); - } else { + } + if (column.data.isOpen) { this._layoutUpdate(animate); } return Promise.resolve(); @@ -396,16 +399,19 @@ _renderGrouped: function (fragment) { var self = this; var newFragment = document.createDocumentFragment(); - this._super.apply(this, [newFragment]); + var fragment_change = [newFragment]; + this._super.apply(this, fragment_change); this.defs.push( Promise.all(this.defs).then(function () { var data = []; _.each(self.state.data, function (group) { - if (!group.value) { - group = _.extend({}, group, {value: _t("Undefined")}); - data.unshift(group); - } else { - data.push(group); + var grp = group; + if (!grp.value) { + grp = _.extend({}, grp, {value: _t("Undefined")}); + data.unshift(grp); + } + if (grp.value) { + data.push(grp); } }); @@ -445,7 +451,7 @@ * Retrieve the Jquery node (.o_kanban_group) for a list of a given widgets * * @private - * @param widgets + * @param {Object} widgets: '' * @returns {jQuery} the matching .o_kanban_group widgets */ _toNode: function (widgets) { @@ -462,8 +468,8 @@ * Update the given column to the updated positions * * @private - * @param $column The jquery column - * @param cssProperties Use to update column + * @param {Object} $column The jquery column + * @param {Object} cssProperties Use to update column * @param {Boolean} [animate=false] set to true to animate * @returns {Promise} */ @@ -493,6 +499,7 @@ /** * @private + * @param {MouseEvent} event */ _onMobileQuickCreateClicked: function (event) { if (event) { diff --git a/web_responsive/static/src/js/web_responsive.js b/web_responsive/static/src/js/web_responsive.js index 9dbfc6282..d8da1795b 100644 --- a/web_responsive/static/src/js/web_responsive.js +++ b/web_responsive/static/src/js/web_responsive.js @@ -21,7 +21,6 @@ odoo.define("web_responsive", function (require) { const PatchableAttachmentViewer = patchMixin(AttachmentViewer); const ControlPanel = require("web.ControlPanel"); const SearchPanel = require("web/static/src/js/views/search_panel.js"); - /* global owl */ const {QWeb, Context} = owl; const {useState, useContext} = owl.hooks; diff --git a/web_search_with_and/static/src/js/control_panel_model_extension.js b/web_search_with_and/static/src/js/control_panel_model_extension.js index 67f2d7db5..70cb547c4 100644 --- a/web_search_with_and/static/src/js/control_panel_model_extension.js +++ b/web_search_with_and/static/src/js/control_panel_model_extension.js @@ -20,32 +20,32 @@ odoo.define( isShiftKey, }) { const queryElem = this.state.query.find( - (queryElem) => - queryElem.filterId === filterId && - queryElem.value === value && - queryElem.operator === operator + (queryElem_val) => + queryElem_val.filterId === filterId && + queryElem_val.value === value && + queryElem_val.operator === operator ); if (!queryElem) { + const {groupId} = this.state.filters[filterId]; + this.state.query.push({ + filterId, + groupId, + label, + value, + operator, + }); if (isShiftKey) { - const groupId = Math.random(); + const group_id = Math.random(); this.state.query.push({ filterId, - groupId, - label, - value, - operator, - }); - } else { - const {groupId} = this.state.filters[filterId]; - this.state.query.push({ - filterId, - groupId, + group_id, label, value, operator, }); } - } else { + } + if (queryElem) { queryElem.label = label; } }, diff --git a/web_search_with_and/static/src/js/search_bar.js b/web_search_with_and/static/src/js/search_bar.js index a12912057..5cd1a0adb 100644 --- a/web_search_with_and/static/src/js/search_bar.js +++ b/web_search_with_and/static/src/js/search_bar.js @@ -36,6 +36,8 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require this._closeAutoComplete(); }, + /* eslint-disable complexity */ + /** * @private * @param {KeyboardEvent} ev @@ -100,7 +102,7 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require } } break; - case "ArrowUp": + case "ArrowUp": { ev.preventDefault(); let previousIndex = this.state.focusedItem - 1; if (previousIndex < 0) { @@ -108,6 +110,7 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require } this.state.focusedItem = previousIndex; break; + } case "Backspace": if (!this.state.inputValue.length) { const facets = this.model.get("facets"); @@ -124,7 +127,8 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require /* Falls through */ case "Tab": if (this.state.inputValue.length) { - ev.preventDefault(); // Keep the focus inside the search bar + // Keep the focus inside the search bar + ev.preventDefault(); this._selectSource(currentItem); } break; @@ -135,5 +139,6 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require break; } }, + /* eslint-enable complexity */ }); }); diff --git a/web_switch_context_warning/static/src/js/switch_context_warning_worker.js b/web_switch_context_warning/static/src/js/switch_context_warning_worker.js index 7c9d1446f..4e3c30e31 100644 --- a/web_switch_context_warning/static/src/js/switch_context_warning_worker.js +++ b/web_switch_context_warning/static/src/js/switch_context_warning_worker.js @@ -1,8 +1,8 @@ // Show a big banner in the top of the page if the context has been // Changed in another tab or window (in the same browser) -var con = []; -var lastCtx = null; +window.con = []; +window.lastCtx = null; addEventListener( "connect", @@ -10,21 +10,21 @@ addEventListener( "use strict"; var port = ee.ports[0]; - con.push(port); + window.con.push(port); port.onmessage = function (e) { var newCtx = e.data; - if (lastCtx && newCtx !== lastCtx) { - con.forEach(function (eport) { + if (window.lastCtx && newCtx !== window.lastCtx) { + window.con.forEach(function (eport) { eport.postMessage({ type: "newCtx", newCtx: newCtx, - lastCtx: lastCtx, + lastCtx: window.lastCtx, }); }); } - lastCtx = newCtx; + window.lastCtx = newCtx; }; }, false diff --git a/web_widget_numeric_step/static/src/js/numeric_step.js b/web_widget_numeric_step/static/src/js/numeric_step.js index 8c166fe7a..75700d260 100644 --- a/web_widget_numeric_step/static/src/js/numeric_step.js +++ b/web_widget_numeric_step/static/src/js/numeric_step.js @@ -159,21 +159,23 @@ odoo.define("web_widget_numeric_step.field", function (require) { * @param {String} mode can be "plus" or "minus" */ _doStep: function (mode) { + let mode_val = mode; let cval = 0; try { const field = this.record.fields[this.name]; cval = field_utils.parse[field.type](this.$input.val()); } catch (e) { cval = this.value; - mode = false; // Only set the value in this case + // Only set the value in this case + mode_val = false; } - if (mode === "plus") { + if (mode_val === "plus") { cval += this._config.step; - } else if (mode === "minus") { + } else if (mode_val === "minus") { cval -= this._config.step; } const nval = this._sanitizeNumberValue(cval); - if (nval !== this.lastSetValue || !mode) { + if (nval !== this.lastSetValue || !mode_val) { this.$input.val(nval); // Every time that user update the value we must trigger an // onchange method. diff --git a/web_widget_x2many_2d_matrix/static/src/js/widget_x2many_2d_matrix.js b/web_widget_x2many_2d_matrix/static/src/js/widget_x2many_2d_matrix.js index 118206925..f89db2d48 100644 --- a/web_widget_x2many_2d_matrix/static/src/js/widget_x2many_2d_matrix.js +++ b/web_widget_x2many_2d_matrix/static/src/js/widget_x2many_2d_matrix.js @@ -176,6 +176,9 @@ odoo.define("web_widget_x2many_2d_matrix.widget", function (require) { /** * Determine if a field represented by field_def can be aggregated + * + * @param {Object} field_def: field def + * @returns {Boolean} if field def is aggregatable */ is_aggregatable: function (field_def) { return field_def.type in {float: 1, monetary: 1, integer: 1};