From 41391c5a5f49437018ce338e877d2a4c09d2e78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 10 Apr 2022 19:28:21 +0200 Subject: [PATCH] Use for...of loop issue8183 review403221002 --- src/action.js | 12 +-- src/board.js | 25 +++-- src/common.js | 66 ++++++------- src/model.js | 219 +++++++++++++++++++---------------------- src/pyson.js | 6 +- src/sao.js | 43 ++++----- src/screen.js | 220 +++++++++++++++++++----------------------- src/session.js | 4 +- src/tab.js | 109 ++++++++++----------- src/view.js | 42 ++++---- src/view/calendar.js | 13 ++- src/view/form.js | 113 +++++++++++----------- src/view/graph.js | 24 ++--- src/view/list_form.js | 19 ++-- src/view/tree.js | 152 ++++++++++++++--------------- src/window.js | 61 ++++++------ src/wizard.js | 14 ++- 17 files changed, 530 insertions(+), 612 deletions(-) diff --git a/src/action.js b/src/action.js index 817f814911..1b388ef1ec 100644 --- a/src/action.js +++ b/src/action.js @@ -63,10 +63,10 @@ if (!jQuery.isEmptyObject(action.views)) { params.view_ids = []; params.mode = []; - action.views.forEach(function(x) { - params.view_ids.push(x[0]); - params.mode.push(x[1]); - }); + for (const view of action.views) { + params.view_ids.push(view[0]); + params.mode.push(view[1]); + } } else if (!jQuery.isEmptyObject(action.view_id)) { params.view_ids = [action.view_id[0]]; } @@ -94,10 +94,10 @@ params.search_value = decoder.decode( action.pyson_search_value || '[]'); params.tab_domain = []; - action.domains.forEach(function(element, index) { + for (const element of action.domains) { params.tab_domain.push( [element[0], decoder.decode(element[1]), element[2]]); - }); + } name_prm = jQuery.when(action.name); params.model = action.res_model || data.res_model; params.res_id = action.res_id || data.res_id; diff --git a/src/board.js b/src/board.js index 391cf74b9d..0b6d06baaf 100644 --- a/src/board.js +++ b/src/board.js @@ -42,8 +42,8 @@ new this.xml_parser(this, null, {}).parse(xml.children()[0]); actions_prms = []; - for (var i = 0, len = this.actions.length; i < len; i++) { - actions_prms.push(this.actions[i].action_prm); + for (const action of this.actions) { + actions_prms.push(action.action_prm); } this.actions_prms = jQuery.when.apply(jQuery, actions_prms); }, @@ -57,12 +57,11 @@ } }, active_changed: function(event_action) { - this.actions.forEach(function(action) { - if (action === event_action) { - return; + for (const action of this.actions) { + if (action !== event_action) { + action.update_domain(this.actions); } - action.update_domain(this.actions); - }); + } }, }); @@ -94,10 +93,10 @@ if (!jQuery.isEmptyObject(action.views)) { params.view_ids = []; params.mode = []; - action.views.forEach(function(x) { - params.view_ids.push(x[0]); - params.mode.push(x[1]); - }); + for (const view of action.views) { + params.view_ids.push(view[0]); + params.mode.push(view[1]); + } } else if (!jQuery.isEmptyObject(action.view_id)) { params.view_ids = [action.view_id[0]]; } @@ -120,10 +119,10 @@ params.search_value = decoder.decode( action.pyson_search_value || '[]'); params.tab_domain = []; - action.domains.forEach(function(element, index) { + for (const element of action.domains) { params.tab_domain.push( [element[0], decoder.decode(element[1]), element[2]]); - }); + } params.context_model = action.context_model; params.context_domain = action.context_domain; if (action.limit !== null) { diff --git a/src/common.js b/src/common.js index 19d4faad66..caffb2fd5d 100644 --- a/src/common.js +++ b/src/common.js @@ -109,15 +109,15 @@ i++; } var result = [[]]; - pools.forEach(function(pool) { + for (const pool of pools) { var tmp = []; - result.forEach(function(x) { - pool.forEach(function(y) { + for (const x of result) { + for (const y of pool) { tmp.push(x.concat([y])); - }); - }); + } + } result = tmp; - }); + } return result; }; @@ -667,9 +667,9 @@ Sao.common.selection_mixin.init_selection = function(value, callback) { if (!value) { value = {}; - (this.attributes.selection_change_with || []).forEach(function(e) { + for (const e of (this.attributes.selection_change_with || [])) { value[e] = null; - }); + } } var key = JSON.stringify(value); var selection = this.attributes.selection || []; @@ -758,17 +758,17 @@ }, record.model.session); prm.done(function(result) { var selection = []; - result.forEach(function(x) { + for (const x of result) { selection.push([x.id, x.rec_name]); - }); + } if (this.nullable_widget) { selection.push([null, '']); } var help = {}; if (help_field){ - result.forEach(function(x) { + for (const x of result) { help[x.id] = x[help_field]; - }); + } } this._last_domain = [domain, context]; this._domain_cache[jdomain] = selection; @@ -1554,7 +1554,7 @@ var cur = tokens[0]; var nex = null; var result = []; - tokens.slice(1).forEach(function(nex) { + for (const nex of tokens.slice(1)) { if ((nex == '=') && cur && ~this.OPERATORS.indexOf(cur + nex)) { result.push(cur + nex); @@ -1565,7 +1565,7 @@ } cur = nex; } - }.bind(this)); + } if (cur !== null) { result.push(cur); } @@ -1575,9 +1575,9 @@ var result = []; var current = result; var parent = []; - tokens.forEach(function(token, i) { + for (const token of tokens) { if (current === undefined) { - return; + continue; } if (token == '(') { parent.push(current); @@ -1587,7 +1587,7 @@ } else { current.push(token); } - }); + } return result; }, group: function(tokens) { @@ -1676,24 +1676,24 @@ _group = _group.bind(this); var parts = []; - tokens.forEach(function(token) { + for (const token of tokens) { if (this.is_generator(token)) { - _group(parts).forEach(function(group) { + for (const group of _group(parts)) { if (!Sao.common.compare(group, [null])) { result.push(group); } - }); + } parts = []; result.push(this.group(token)); } else { parts.push(token); } - }.bind(this)); - _group(parts).forEach(function(group) { + } + for (const group of _group(parts)) { if (!Sao.common.compare(group, [null])) { result.push(group); } - }); + } return result; }, is_generator: function(value) { @@ -2653,11 +2653,11 @@ if (domoperator) { result.push(domoperator); } - domains.forEach(function append(domain) { + for (const domain of domains) { if (!jQuery.isEmptyObject(domain)) { result.push(domain); } - }); + } return this.simplify(this.merge(result)); }, unique_value: function(domain) { @@ -3066,20 +3066,20 @@ from = (from < 0) ? 0 : from; var to = Math.round(idx + this.batchnum / 2); var ids = []; - this.tryton_icons.slice(from, to).forEach(function(e) { + for (const e of this.tryton_icons.slice(from, to)) { ids.push(e[0]); - }); + } var read_prm = icon_model.execute('read', [ids, ['name', 'icon']], {}); return read_prm.then(function(icons) { - icons.forEach(function(icon) { + for (const icon of icons) { var img_url = this._convert(icon.icon); this.loaded_icons[icon.name] = img_url; delete this.name2id[icon.name]; this.tryton_icons.splice( find_array([icon.id, icon.name]), 1); - }.bind(this)); + } }.bind(this)); }.bind(this)); return this.register_prm; @@ -4096,9 +4096,8 @@ 'class': 'btn-group', 'role': 'group' }).appendTo(toolbar); - for (var i in buttons) { - var properties = buttons[i]; - var button = jQuery('